-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathMakefile
More file actions
374 lines (296 loc) · 17 KB
/
Copy pathMakefile
File metadata and controls
374 lines (296 loc) · 17 KB
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
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
.DEFAULT_GOAL := help
# The directory where the git repo is mounted in the docker container
docker_container_repo_dir=/app
# Common docker options
#
# Pinned Rust toolchain version. Keep in lockstep with `rust-toolchain.toml` and
# `wp_rs_web/Dockerfile` so local `cargo`, the CI Docker image, and the pinned
# toolchain never drift. See https://github.com/Automattic/wordpress-rs/issues/1436.
rust_stable_toolchain := 1.97.1
rust_docker_container := public.ecr.aws/docker/library/rust:$(rust_stable_toolchain)
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)
certificate_name_release = Apple Distribution: Automattic, Inc. (PZYM8XX95Q)
# Required for supporting tvOS and watchOS. We can update the nightly toolchain version if needed.
rust_nightly_toolchain := nightly-2026-07-16
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
swift-docs: xcframework swift-docs-only
@# Help: Generate Xcode documentation.
swift-docs-only:
mkdir -p docs/Swift
swift package --allow-writing-to-directory docs generate-documentation --target WordPressAPI --output-path docs/Swift/WordPressAPI.doccarchive --disable-indexing
swift package --allow-writing-to-directory docs generate-documentation --target WordPressAPIInternal --output-path docs/Swift/WordPressAPIInternal.doccarchive --disable-indexing
tar -czf swift-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 $* --features export-uncancellable-endpoints --package wp_mobile --profile $(CARGO_PROFILE) --no-default-features
./scripts/swift-bindings.sh target/$*/$(CARGO_PROFILE_DIRNAME)/libwp_mobile.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))
# Build all targets for a specific platform (without creating xcframework).
build-apple-macOS: $(build-apple-platform-macos)
build-apple-iOS: $(build-apple-platform-ios)
build-apple-tvOS: $(build-apple-platform-tvos)
build-apple-watchOS: $(build-apple-platform-watchos)
# Creating xcframework for one single platform, including real device and simulator.
# NOTE: these REPLACE the xcframework rather than adding a slice to it. Use
# `xcframework-only-macos` for local `swift build`, which links the macOS slice.
#
# Each rule builds its platform's targets (prerequisites), then assembles them
# into the xcframework (recipe). The assemble command is inlined per rule on
# purpose: these rules previously shared a single `xcframework-only-%` pattern
# rule for the assemble recipe, but adding a `@# Help:` comment to the
# otherwise-recipe-less explicit rules silently shadowed that pattern recipe,
# so the assemble step stopped running (#1490). Keep each rule's recipe
# self-contained so `make help` and the actual build never drift again.
xcframework-only-macos: $(build-apple-platform-macos)
@# Help: Build an xcframework containing only macOS (~18GB). Use this to verify UniFFI changes locally.
cargo run --quiet --bin xcframework -- --profile $(CARGO_PROFILE) --targets $(apple-platform-targets-macos)
xcframework-only-ios: $(build-apple-platform-ios)
@# Help: Build an xcframework containing only iOS (~24GB). Replaces any existing xcframework.
cargo run --quiet --bin xcframework -- --profile $(CARGO_PROFILE) --targets $(apple-platform-targets-ios)
xcframework-only-tvos: $(build-apple-platform-tvos)
@# Help: Build an xcframework containing only tvOS. Replaces any existing xcframework.
cargo run --quiet --bin xcframework -- --profile $(CARGO_PROFILE) --targets $(apple-platform-targets-tvos)
xcframework-only-watchos: $(build-apple-platform-watchos)
@# Help: Build an xcframework containing only watchOS. Replaces any existing xcframework.
cargo run --quiet --bin xcframework -- --profile $(CARGO_PROFILE) --targets $(apple-platform-targets-watchos)
# Assemble pre-built targets into an xcframework (without building targets).
xcframework-assemble:
@# Help: Assemble already-built targets into an xcframework, without building anything.
cargo run --quiet --bin xcframework -- --profile $(CARGO_PROFILE) --targets $(apple-platform-targets)
# Creating xcframework for all platforms.
#
# This builds all 11 Apple targets and consumes ~100GB in `target/`. For local
# verification of a UniFFI change, prefer `xcframework-only-macos` — see
# Documentation/local-development.md.
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 target/libwordpressFFI.xcframework.zip
ditto -c -k --sequesterRsrc --keepParent target/libwordpressFFI.xcframework/ target/libwordpressFFI.xcframework.zip
xcframework-package-sign: xcframework-all xcframework-sign xcframework-package
xcframework-package-checksum:
swift package compute-checksum target/libwordpressFFI.xcframework.zip | tee target/libwordpressFFI.xcframework.zip.checksum.txt
xcframework-sign:
codesign --timestamp -v --sign "${certificate_name_release}" target/libwordpressFFI.xcframework
codesign -dvv target/libwordpressFFI.xcframework
docker-image-web:
docker build -t wordpress-rs-web -f wp_rs_web/Dockerfile . --progress=plain
swift-linux-library:
cargo build --release --features export-uncancellable-endpoints --package wp_mobile
./scripts/swift-bindings.sh target/release/libwp_mobile.a
mkdir -p target/release/libwordpressFFI-linux
cp target/release/swift-bindings/Headers/* target/release/libwordpressFFI-linux/
cp target/release/libwp_mobile.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:
xcrun simctl create "iPhone 17 Pro Test Device" "com.apple.CoreSimulator.SimDeviceType.iPhone-17-Pro"
bundle exec fastlane run run_tests project:native/swift/Example/Example.xcodeproj scheme:Example build_for_testing:true ensure_devices_found:true device:"iPhone 17 Pro Test Device (26.5)" xcargs:"-skipPackagePluginValidation"
test-swift:
$(MAKE) test-swift-$(uname)
test-swift-linux:
docker exec -w /app -it wordpress make test-swift-linux-in-docker
test-swift-linux-in-docker: swift-linux-library
swift test -Xlinker -Ltarget/release/libwordpressFFI-linux -Xlinker -lwp_mobile --no-parallel
test-swift-darwin: xcframework
swift test
test-swift-macOS: test-swift-darwin
test-swift-iOS: xcframework
scripts/xcodebuild-test.sh iOS-26-5
test-swift-tvOS: xcframework
scripts/xcodebuild-test.sh tvOS-26-5
test-swift-watchOS: xcframework
scripts/xcodebuild-test.sh watchOS-26-5
# Line tables preserve file/line backtraces without full debug info's CI memory cost.
test-rust-lib:
$(rust_docker_run) env CARGO_PROFILE_TEST_DEBUG=line-tables-only cargo test --lib -- --nocapture
test-rust-doc:
$(rust_docker_run) env CARGO_PROFILE_TEST_DEBUG=line-tables-only 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-rust-integration-remote-login:
@# Help: Run the flaky external login-discovery tests (ignored in the main suite; hit real *.wpmt.co sites).
$(rust_docker_run) cargo test --package wp_api_integration_tests --test test_login_remote -- --ignored --nocapture
report-remote-login-integration-test-suite-health:
@# Help: Post the remote login integration-test-suite health digest to Slack (needs BUILDKITE_TOKEN + SLACK_WEBHOOK).
bundle exec fastlane report_remote_login_integration_test_suite_health
test-kotlin-integration:
@# Help: Run Kotlin integration tests in test server.
docker exec -i -e REPOSILITE_MIRROR_ENABLED -e REPOSILITE_MIRROR_URL wordpress /bin/bash < ./scripts/run-kotlin-integration-tests.sh
runComposeDesktopApp:
@# Help: Run the Compose Multiplatform desktop application.
cd native/kotlin && ./gradlew :example:composeApp:run
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.
# `--jobs 1` on the --tests pass caps clippy's peak RAM. Each crate in the wp_api
# family (wp_api, wp_mobile, the integration-test crates, the CLIs) costs ~4.5GB
# to lint because of the wp_contextual/UniFFI macro-generated code. The first
# pass's heavy libs form a dependency chain and can't overlap (peak ~4.7GB even
# at the default -j), so it stays parallel. But the --tests pass builds their
# independent test targets all at once, spiking to ~9GB — serializing just that
# pass caps it back at one crate (~4.7GB) without paying serial-dep time twice.
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 --jobs 1 -- -D warnings"
lint-swift:
@# Help: Run the linter for Swift.
xcrun swift format lint --strict --recursive --parallel --ignore-unparsable-files \
native/swift/Sources/wordpress-api \
native/swift/Sources/wordpress-api-cache \
native/swift/Tests \
native/swift/Example \
native/swift/Tools
lintfix-swift: fmt-swift
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"
check-rust-toolchain:
@# Help: Check whether the pinned Rust toolchain has fallen behind the latest stable release.
./.buildkite/commands/check-rust-toolchain-current.sh
setup-rust:
@# Help: Install the necessary Rust toolchains on your development computer (for macOS).
RUST_TOOLCHAIN=$(rust_stable_toolchain) $(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
# Platform-specific Rust setup (only installs what each platform needs in CI)
setup-rust-macOS:
rustup toolchain install $(rust_stable_toolchain)
rustup target add --toolchain $(rust_stable_toolchain) x86_64-apple-darwin aarch64-apple-darwin
setup-rust-iOS:
rustup toolchain install $(rust_stable_toolchain)
rustup target add --toolchain $(rust_stable_toolchain) aarch64-apple-ios x86_64-apple-ios aarch64-apple-ios-sim
setup-rust-tvOS setup-rust-watchOS:
rustup toolchain install $(rust_stable_toolchain)
rustup toolchain install $(rust_nightly_toolchain)
rustup component add rust-src --toolchain $(rust_nightly_toolchain)
setup-rust-android-targets:
rustup target add \
x86_64-linux-android \
i686-linux-android \
armv7-linux-androideabi \
aarch64-linux-android
cargo install cargo-ndk --locked
run-wp-cli-command:
@docker exec wordpress /bin/bash -c "wp --allow-root $(ARGS)"
validate-localizations:
@# Help: Validate localization files using `wp_localization_validation` crate
$(rust_docker_run) /bin/bash -c "cargo run --bin wp_localization_validation -- --localization-folder ./wp_localization/localization/"
fmt-swift:
@# Help: Format Swift code.
xcrun swift format --in-place --recursive --parallel --ignore-unparsable-files native/swift
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"'