-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
270 lines (208 loc) · 10.8 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
.DEFAULT_GOAL := help
# The directory where the git repo is mounted in the docker container
docker_container_repo_dir=/app
# Common docker options
rust_docker_container := public.ecr.aws/docker/library/rust:1.84.0
docker_opts_shared := --rm -v "$(PWD)":$(docker_container_repo_dir) -w $(docker_container_repo_dir)
rust_docker_run := docker run -v $(PWD):/$(docker_container_repo_dir) -w $(docker_container_repo_dir) -it -e TEST_ALL_PLUGINS -e CARGO_HOME=/app/.cargo $(rust_docker_container)
docker_build_and_run := docker build -t foo . && docker run $(docker_opts_shared) -it foo
swift_package_platform_version = $(shell swift package dump-package | jq -r '.platforms[] | select(.platformName=="$1") | .version')
swift_package_platform_macos = $(call swift_package_platform_version,macos)
swift_package_platform_ios = $(call swift_package_platform_version,ios)
swift_package_platform_watchos = $(call swift_package_platform_version,watchos)
swift_package_platform_tvos = $(call swift_package_platform_version,tvos)
# Required for supporting tvOS and watchOS. We can update the nightly toolchain version if needed.
rust_nightly_toolchain := nightly-2024-12-08
clean:
@# Help: Remove untracked files from the project via Git.
git clean -ffXd
.PHONY: docs # Rebuild docs each time we run this command
docs:
@# Help: Generate project documentation.
rm -rf docs
mkdir -p docs
$(rust_docker_run) /bin/bash -c 'cargo doc'
cp -r target/doc/static.files docs/static.files
cp -r target/doc/wp_api docs/wp_api
cp -r target/doc/wp_contextual docs/wp_contextual
docs-archive: docs
@# Help: Archive the generated project documentation.
tar -czvf docs.tar.gz docs
release-on-ci:
@[ -n "$(BUILDKITE_API_TOKEN)" ] || (echo "BUILDKITE_API_TOKEN is not set" && exit 1)
@[ -n "$(WORDPRESS_RS_NEW_VERSION)" ] || (echo "WORDPRESS_RS_NEW_VERSION is not set" && exit 1)
@echo "Triggering a release job on Buildkite. New version: $(WORDPRESS_RS_NEW_VERSION)"
@mkdir -p .build
@echo '{ \
"commit": "HEAD", \
"branch": "trunk", \
"message": "Publishing a new release", \
"env": {"NEW_VERSION":"${WORDPRESS_RS_NEW_VERSION}"} \
}' | jq > .build/buildkite_release_job_request.json
@curl -s "https://api.buildkite.com/v2/organizations/automattic/pipelines/wordpress-rs/builds" \
-H "Authorization: Bearer $(BUILDKITE_API_TOKEN)" \
--json @.build/buildkite_release_job_request.json \
--output .build/buildkite_release_job_response.json
@echo "Buildkite job triggerd. See .build/buildkite_release_job_response.json for the buildkite job details."
@echo ""
@echo "Swift package will be released by https://buildkite.com/automattic/wordpress-rs/builds/$$(jq -r '.number' .build/buildkite_release_job_response.json)"
@echo "Once that job finishes, Android libraries will be release by https://buildkite.com/automattic/wordpress-rs/builds?branch=$(WORDPRESS_RS_NEW_VERSION)"
apple-platform-targets-macos := x86_64-apple-darwin aarch64-apple-darwin
apple-platform-targets-ios := aarch64-apple-ios x86_64-apple-ios aarch64-apple-ios-sim
apple-platform-targets-tvos := aarch64-apple-tvos aarch64-apple-tvos-sim
apple-platform-targets-watchos := arm64_32-apple-watchos x86_64-apple-watchos-sim aarch64-apple-watchos-sim
apple-platform-targets := \
$(apple-platform-targets-macos) \
$(apple-platform-targets-ios) \
$(apple-platform-targets-tvos) \
$(apple-platform-targets-watchos)
ifeq ($(BUILDKITE), true)
CARGO_PROFILE ?= release
CARGO_PROFILE_DIRNAME := release
else
CARGO_PROFILE ?= dev
CARGO_PROFILE_DIRNAME := debug
endif
cargo_config_library = --config profile.$(CARGO_PROFILE).debug=true --config 'profile.$(CARGO_PROFILE).panic="abort"'
# Set deployment targets for each platform
_build-apple-%-darwin: export MACOSX_DEPLOYMENT_TARGET=$(swift_package_platform_macos)
_build-apple-%-ios _build-apple-%-ios-sim: export IPHONEOS_DEPLOYMENT_TARGET=$(swift_package_platform_ios)
_build-apple-%-tvos _build-apple-%-tvos-sim: export TVOS_DEPLOYMENT_TARGET=$(swift_package_platform_tvos)
_build-apple-%-watchos _build-apple-%-watchos-sim: export WATCHOS_DEPLOYMENT_TARGET=$(swift_package_platform_watchos)
# Use nightly toolchain for tvOS and watchOS
_build-apple-%-tvos _build-apple-%-tvos-sim _build-apple-%-watchos _build-apple-%-watchos-sim: \
CARGO_OPTS = +$(rust_nightly_toolchain) -Z build-std=panic_abort,std
# Build the library for a specific target
_build-apple-%:
cargo $(CARGO_OPTS) $(cargo_config_library) build --target $* --package wp_api --profile $(CARGO_PROFILE)
./scripts/swift-bindings.sh target/$*/$(CARGO_PROFILE_DIRNAME)/libwp_api.a
# Build the library for one single platform, including real device and simulator.
build-apple-platform-macos := $(addprefix _build-apple-,$(apple-platform-targets-macos))
build-apple-platform-ios := $(addprefix _build-apple-,$(apple-platform-targets-ios))
build-apple-platform-tvos := $(addprefix _build-apple-,$(apple-platform-targets-tvos))
build-apple-platform-watchos := $(addprefix _build-apple-,$(apple-platform-targets-watchos))
# Creating xcframework for one single platform, including real device and simulator.
xcframework-only-macos: $(build-apple-platform-macos)
xcframework-only-ios: $(build-apple-platform-ios)
xcframework-only-tvos: $(build-apple-platform-tvos)
xcframework-only-watchos: $(build-apple-platform-watchos)
xcframework-only-%:
cargo run --quiet --bin xcframework -- --profile $(CARGO_PROFILE) --targets $(apple-platform-targets-$*)
# Creating xcframework for all platforms.
xcframework-all: $(build-apple-platform-macos) $(build-apple-platform-ios) $(build-apple-platform-tvos) $(build-apple-platform-watchos)
cargo run --quiet --bin xcframework -- --profile $(CARGO_PROFILE) --targets $(apple-platform-targets)
ifeq ($(SKIP_PACKAGE_WP_API),true)
xcframework:
@echo "Skip building libwordpressFFI.xcframework"
else
xcframework: xcframework-all
endif
xcframework-package: xcframework-all
rm -rf libwordpressFFI.xcframework.zip
ditto -c -k --sequesterRsrc --keepParent target/libwordpressFFI.xcframework/ libwordpressFFI.xcframework.zip
xcframework-package-checksum:
swift package compute-checksum libwordpressFFI.xcframework.zip | tee libwordpressFFI.xcframework.zip.checksum.txt
docker-image-swift:
docker build -t wordpress-rs-swift -f Dockerfile.swift .
swift-linux-library:
cargo build --release --package wp_api
./scripts/swift-bindings.sh target/release/libwp_api.a
mkdir -p target/release/libwordpressFFI-linux
cp target/release/swift-bindings/Headers/* target/release/libwordpressFFI-linux/
cp target/release/libwp_api.a target/release/libwordpressFFI-linux/
swift-example-app: swift-example-app-mac swift-example-app-ios
swift-example-app-mac:
xcodebuild -project native/swift/Example/Example.xcodeproj -scheme Example -destination 'platform=macOS,arch=arm64' -skipPackagePluginValidation build
swift-example-app-ios:
bundle exec fastlane run run_tests project:native/swift/Example/Example.xcodeproj scheme:Example build_for_testing:true ensure_devices_found:true device:"iPhone 16 (18.0)" xcargs:"-skipPackagePluginValidation"
test-swift:
$(MAKE) test-swift-$(uname)
test-swift-linux: docker-image-swift
docker run $(docker_opts_shared) -it wordpress-rs-swift make test-swift-linux-in-docker
test-swift-linux-in-docker: swift-linux-library
swift test -Xlinker -Ltarget/release/libwordpressFFI-linux -Xlinker -lwp_api
test-swift-darwin: xcframework
swift test
test-swift-macOS: test-swift-darwin
test-swift-iOS: xcframework
scripts/xcodebuild-test.sh iOS-18-0
test-swift-tvOS: xcframework
scripts/xcodebuild-test.sh tvOS-18-0
test-swift-watchOS: xcframework
scripts/xcodebuild-test.sh watchOS-11-0
test-rust-lib:
$(rust_docker_run) cargo test --lib -- --nocapture
test-rust-doc:
$(rust_docker_run) cargo test --doc -- --nocapture
test-rust-wp-derived-request-parser:
$(rust_docker_run) cargo test --package wp_derive_request_builder
test-rust-integration:
@# Help: Run Rust integration tests in test server.
docker exec -i wordpress /bin/bash < ./scripts/run-rust-integration-tests.sh
test-rust-integration-wordpress-org-api:
$(rust_docker_run) cargo test --package wp_api_integration_tests --test test_plugin_directory -- --nocapture
test-kotlin-integration:
@# Help: Run Kotlin integration tests in test server.
docker exec -i wordpress /bin/bash < ./scripts/run-kotlin-integration-tests.sh
restore-test-server:
@# Help: Restore the test server from backup.
curl "http://localhost:4000/restore?db=true&plugins=true"
start-test-server: stop-server
@# Help: Start the test server.
docker-compose up -d --build
docker exec -i wordpress /bin/bash < ./scripts/setup-test-site.sh
integration-test-backend:
@# Help: Start the integration test helper server.
docker exec -i wordpress /bin/bash -c " if pgrep wp_api_integ; then pkill wp_api_integ; fi" # Kill the previous server
docker exec -i wordpress /bin/bash < ./scripts/start-wp-api-integration-tests-backend.sh
test-server: start-test-server integration-test-backend
print-log-integration-test-server:
@# Help: Print the logs of integration test helper server.
docker exec -i wordpress /bin/bash -c "cat /app/target/release/wp_api_integration_tests_backend.log"
stop-server:
@# Help: Stop the running server.
docker-compose down
lint: lint-rust lint-swift
@# Help: Run the linter for all languages.
lint-rust:
@# Help: Run the linter for Rust.
$(rust_docker_run) /bin/bash -c "rustup component add clippy && cargo clippy --all -- -D warnings && cargo clippy --tests --all -- -D warnings"
lint-swift:
@# Help: Run the linter for Swift.
swift package plugin swiftlint
lintfix-swift:
@# Help: Run the linter for Swift and correct fixable issues.
swift package plugin swiftlint --autocorrect
fmt-rust:
$(rust_docker_run) /bin/bash -c "rustup component add rustfmt && cargo fmt"
fmt-check-rust:
$(rust_docker_run) /bin/bash -c "rustup component add rustfmt && cargo fmt --all -- --check"
setup-rust:
@# Help: Install the necessary Rust toolchains on your development computer (for macOS).
RUST_TOOLCHAIN=stable $(MAKE) setup-rust-toolchain
RUST_TOOLCHAIN=$(rust_nightly_toolchain) $(MAKE) setup-rust-toolchain
setup-rust-toolchain:
rustup toolchain install $(RUST_TOOLCHAIN)
rustup component add rust-src --toolchain $(RUST_TOOLCHAIN)
rustup target add --toolchain $(RUST_TOOLCHAIN) \
x86_64-apple-ios \
aarch64-apple-ios \
aarch64-apple-darwin \
x86_64-apple-darwin \
aarch64-apple-ios-sim
setup-rust-android-targets:
rustup target add \
x86_64-linux-android \
i686-linux-android \
armv7-linux-androideabi \
aarch64-linux-android
run-wp-cli-command:
@docker exec wordpress /bin/bash -c "wp --allow-root $(ARGS)"
help:
@printf "%-40s %s\n" "Target" "Description"
@printf "%-40s %s\n" "------" "-----------"
@make -pqR : 2>/dev/null \
| awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' \
| sort \
| egrep -v -e '^[^[:alnum:]]' -e '^$@$$' \
| xargs -I _ sh -c 'printf "%-40s " _; make _ -nB | (grep -i "^# Help:" || echo "") | tail -1 | sed "s/^# Help: //g"'