diff --git a/.bazelrc b/.bazelrc index d17159936..429405bc0 100644 --- a/.bazelrc +++ b/.bazelrc @@ -25,6 +25,12 @@ build --features=swift.use_global_module_cache # Gate the references to androidndk behind a flag to support building on arm linux. build:android --android_crosstool_top=@androidndk//:toolchain +# TODO(snowp): Remove this once the below issues are resolved. +# https://github.com/bazelbuild/rules_rust/issues/3564 +# https://github.com/bazelbuild/rules_rust/issues/3627 +build:ios --config=fake-nightly +build:ios --@rules_rust//rust/settings:experimental_use_allocator_libraries_with_mangled_symbols + build --@rules_rust//rust/settings:rustfmt.toml=//:rustfmt.toml build --@rules_rust//rust/settings:clippy.toml=//:.clippy.toml @@ -70,24 +76,23 @@ build:release-common --config=abort-panic # Size optimizations, codegen-units=1 go along side LTO, which accounts for # about 10% reduction; -z has a non-zero smaller impact (a few pp). build:release-common --@rules_rust//rust/settings:extra_rustc_flag='-Ccodegen-units=1' -build:release-common --@rules_rust//rust/settings:extra_rustc_flag='-Copt-level=s' -build:release-common --@rules_rust//rust/settings:extra_rustc_flag='-Clto=fat' -# Without the next line, rules_rust will add -Clinker-plugin-lto which would be amazing -# but the ndk's lld won't support the output -build:release-common --@rules_rust//rust/settings:lto='manual' +build:release-common --@rules_rust//rust/settings:extra_rustc_flag='-Copt-level=z' build:release-android --define android_strip_symbols=true build:release-android --android_platforms=@rules_android//:armeabi-v7a,@rules_android//:arm64-v8a,@rules_android//:x86,@rules_android//:x86_64 build:release-android --config=release-common -build:release-android --copt=-flto=thin --linkopt=-flto=thin build:release-android --config=android +build:release-android --@rules_rust//rust/settings:lto='fat' build:release-android --linkopt=-Wl,--pack-dyn-relocs=android +# TODO(snowp): This should do better but requires a certain version of Android. +# Investigate what this is and track when we can use it. # build:release-android --linkopt=-Wl,--use-android-relr-tags # Custom iOS release configuration build:force-xcode-version --ios_simulator_device="iPhone 15" build:force-xcode-version --ios_simulator_version=18.2 build:force-xcode-version --xcode_version=16.2 +build:release-ios --config=ios build:release-ios --config=release-common --config=force-xcode-version build:release-ios --features=swift.enable_library_evolution build:release-ios --features=swift.emit_swiftinterface diff --git a/.github/workflows/ios.yaml b/.github/workflows/ios.yaml index 8b3f27d5c..ddcc467de 100644 --- a/.github/workflows/ios.yaml +++ b/.github/workflows/ios.yaml @@ -29,7 +29,7 @@ jobs: - name: Check for workflow file changes id: workflow_check run: | - ./ci/files_changed.sh .github/workflows/ios.yaml + ./ci/files_changed.sh .github/workflows/ios.yaml MODULE.bazel MODULE.bazel.lock continue-on-error: true - name: Determine if tests should run id: check_changes_separate @@ -92,7 +92,7 @@ jobs: - name: "Install dependencies" run: ./ci/mac_ci_setup.sh - name: Run iOS tests (tsan) - run: env -u ANDROID_NDK_HOME ./bazelw test $(./bazelw query 'kind(ios_unit_test, //test/platform/swift/unit_integration/core/...)') --test_tag_filters=macos_only --test_output=errors --config ci + run: env -u ANDROID_NDK_HOME ./bazelw test $(./bazelw query 'kind(ios_unit_test, //test/platform/swift/unit_integration/core/...)') --test_tag_filters=macos_only --test_output=errors --config ci --config ios verify_ios: runs-on: ubuntu-latest needs: ["macos_tsan", "swift_hello_world"] diff --git a/BUILD b/BUILD index 58ba565f3..9b523ffc3 100644 --- a/BUILD +++ b/BUILD @@ -88,7 +88,7 @@ android_artifacts( native_deps = select({ # When targeting an optimized build, use the stripped binary. The symbols are collected prior to stripping and exposed via capture_symbols below. "//bazel/android:strip_symbols": [":capture.debug_info"], - "//conditions:default": ["//platform/jvm:capture"], + "//conditions:default": ["//platform/jvm:capture_shared"], }), proguard_rules = "//platform/jvm:proguard", visibility = ["//visibility:public"], @@ -96,7 +96,7 @@ android_artifacts( android_debug_info( name = "capture.debug_info", - dep = "//platform/jvm:capture", + dep = "//platform/jvm:capture_shared", tags = ["manual"], ) diff --git a/Cargo.Bazel.lock b/Cargo.Bazel.lock index 50927e6af..30e264c26 100644 --- a/Cargo.Bazel.lock +++ b/Cargo.Bazel.lock @@ -1,5 +1,5 @@ { - "checksum": "f82c53dbe0d8bcfb4edf75508e8596220b4ff1dc97dd37f49f86e8a61af24c73", + "checksum": "5813aca78603335fbe761a3d1be543901f95bc22e839ec959c3d7202e907c8a9", "crates": { "addr2line 0.25.1": { "name": "addr2line", @@ -6608,21 +6608,8 @@ "version": "1.0.0", "package_url": null, "repository": null, - "targets": [ - { - "Library": { - "crate_name": "capture", - "crate_root": "src/lib.rs", - "srcs": { - "allow_empty": true, - "include": [ - "**/*.rs" - ] - } - } - } - ], - "library_target_name": "capture", + "targets": [], + "library_target_name": null, "common_attrs": { "compile_data_glob": [ "**" diff --git a/MODULE.bazel b/MODULE.bazel index af4dd0ed1..50581805a 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -4,7 +4,7 @@ module(name = "capture-sdk") # Constants #################### -RUST_VERSION = "1.88.0" +RUST_VERSION = "1.90.0" OKHTTP_VERSION = "4.12.0" @@ -53,7 +53,7 @@ bazel_dep(name = "platforms", version = "0.0.11") bazel_dep(name = "rules_kotlin", version = "2.1.9") bazel_dep(name = "rules_proto", version = "7.1.0") bazel_dep(name = "protobuf", version = "29.3") -bazel_dep(name = "rules_rust", version = "0.62.0") +bazel_dep(name = "rules_rust", version = "0.65.0") bazel_dep(name = "rules_shell", version = "0.4.0") # Required by android_artifacts for pom_file, it's not in bazel central registry @@ -288,18 +288,18 @@ rust.toolchain( # # tl;dr; run e.g. $ ./tools/rust_std_checksum.sh 1.82.0 sha256s = { - "rust-std-" + RUST_VERSION + "-aarch64-apple-ios-sim.tar.gz": "e9505b25f37f49d90f2edd31ea8d4d20362e8dfe48c036f49dc4e638abf90dc9", - "rust-std-" + RUST_VERSION + "-aarch64-apple-ios.tar.gz": "0072ccac226551ae06865d963c74e872b8d425f4afe6465036034656880b3f5a", - "rust-std-" + RUST_VERSION + "-x86_64-apple-ios.tar.gz": "98678a0c84760458dd971c548de495ed155d9f0b0fd59bb21df7d9e733fd97f7", - "rust-std-" + RUST_VERSION + "-aarch64-linux-android.tar.gz": "9d1408d9e5ec0fb02904f18b5543318c092488069eae79e1c3af60a1ae27124d", - "rust-std-" + RUST_VERSION + "-armv7-linux-androideabi.tar.gz": "48132028374a7ac64b07dc4f8c12c5ea6bdbf9cd400a3e622470d32c10500ced", - "rust-std-" + RUST_VERSION + "-i686-linux-android.tar.gz": "b22d731679d0ae2567d2a3bf1c2d519e5c237ef4466c1d475aed7313f0304549", - "rustc-" + RUST_VERSION + "-aarch64-apple-darwin.tar.gz": "539d09b27becd0c52e15f6551e3756aa5ce0fc14484a922731abd0341967eea8", - "cargo-" + RUST_VERSION + "-aarch64-apple-darwin.tar.gz": "b4c5c9ba40b62f3486f05133ae2a739d99d1ad05566d73ad6bc6370636e2de7a", - "llvm-tools-" + RUST_VERSION + "-aarch64-apple-darwin.tar.gz": "9c0487e42dce9b039dadfd855e7b6d690d669298250b7910ad58655fa8466a61", - "rust-std-" + RUST_VERSION + "-aarch64-apple-darwin.tar.gz": "f852990a4bb1a84cef74fb92d0c9715b453379c32af43a8b3b357cadcc78f542", - "clippy-" + RUST_VERSION + "-aarch64-apple-darwin.tar.gz": "ffbf7fabb4271b5dfbaf9e8de7001837cd67a46f89d9217dcbc8df91b9ff8794", - "rustfmt-" + RUST_VERSION + "-aarch64-apple-darwin.tar.gz": "b9658e85e2adfaa68c4b9610d14a6194d66aea3547e5af09d40616adc6c6427a", + "rust-std-" + RUST_VERSION + "-aarch64-apple-ios-sim.tar.gz": "7cfa5f18307d198da5e28fa9c7dc129cb8856131cf1121fed91a756c2a7b3580", + "rust-std-" + RUST_VERSION + "-aarch64-apple-ios.tar.gz": "596585ba45607c0487cec70ba1b9b3215ef6826de1bd59a44273b4f3f442f3b2", + "rust-std-" + RUST_VERSION + "-x86_64-apple-ios.tar.gz": "e0e42c0139ccd113f7b8c671071aa6c9999208a932847eefdcdc2b3ea8099524", + "rust-std-" + RUST_VERSION + "-aarch64-linux-android.tar.gz": "0094d52b27d0c3091000f9c439b683a205c15cbd713acafd1a8febee42ed448a", + "rust-std-" + RUST_VERSION + "-armv7-linux-androideabi.tar.gz": "1ce1491fd05ddd65436a130d0a84dc4230f542bef838c16c61375f94dcf1b727", + "rust-std-" + RUST_VERSION + "-i686-linux-android.tar.gz": "40c03f9fd057fdcb28223166ae22ebf667ae76727773fd3c33eeb1088ded9509", + "rustc-" + RUST_VERSION + "-aarch64-apple-darwin.tar.gz": "77e8d4c354aab89b2abcd4608d2cb7612a99000d8064491aeafbc325c757943a", + "cargo-" + RUST_VERSION + "-aarch64-apple-darwin.tar.gz": "a242bb8d88d4d1b621f33742d0c718ebb5a551b07d21240e8b8c31152dc29737", + "llvm-tools-" + RUST_VERSION + "-aarch64-apple-darwin.tar.gz": "d89589963e941955aeb65ce4e71f88322686f7e4d65f66a87a05c8b893a6cf78", + "rust-std-" + RUST_VERSION + "-aarch64-apple-darwin.tar.gz": "30d6e3008a288f779c90c92d867dcd4f05fd5107d7f3e69d4d37a5945878110a", + "clippy-" + RUST_VERSION + "-aarch64-apple-darwin.tar.gz": "323a3ebca03d5aa7dc8d8d54ac05963e08a1c4fb22066ef6b05ee5398e397b12", + "rustfmt-" + RUST_VERSION + "-aarch64-apple-darwin.tar.gz": "0fff92769fbe393468584232a30ae8e0ea01eb2242201122eea56593b30861ac", }, urls = [ # NOTE: `urls` are technically mirrors so we want to make sure we always try our own first then the official ones. @@ -313,6 +313,7 @@ rust.toolchain( ], versions = [ RUST_VERSION, + "nightly/2025-10-02", ], ) use_repo(rust, "rust_toolchains") diff --git a/MODULE.bazel.lock b/MODULE.bazel.lock index 59987561c..4b03a258e 100644 --- a/MODULE.bazel.lock +++ b/MODULE.bazel.lock @@ -24,7 +24,8 @@ "https://bcr.bazel.build/modules/apple_support/1.17.1/MODULE.bazel": "655c922ab1209978a94ef6ca7d9d43e940cd97d9c172fb55f94d91ac53f8610b", "https://bcr.bazel.build/modules/apple_support/1.21.1/MODULE.bazel": "5809fa3efab15d1f3c3c635af6974044bac8a4919c62238cce06acee8a8c11f1", "https://bcr.bazel.build/modules/apple_support/1.22.1/MODULE.bazel": "90bd1a660590f3ceffbdf524e37483094b29352d85317060b2327fff8f3f4458", - "https://bcr.bazel.build/modules/apple_support/1.22.1/source.json": "2bc34da8d0ebc4c4132c8b26db766ca1b86bbcf26dea94b94aa1cd73e2623aeb", + "https://bcr.bazel.build/modules/apple_support/1.23.0/MODULE.bazel": "317d47e3f65b580e7fb4221c160797fda48e32f07d2dfff63d754ef2316dcd25", + "https://bcr.bazel.build/modules/apple_support/1.23.0/source.json": "cb90a670c368cd37b5a7021486fd3f9a3fb0fcb8f45af43399137938d32ced76", "https://bcr.bazel.build/modules/aspect_bazel_lib/2.11.0/MODULE.bazel": "cb1ba9f9999ed0bc08600c221f532c1ddd8d217686b32ba7d45b0713b5131452", "https://bcr.bazel.build/modules/aspect_bazel_lib/2.11.0/source.json": "92494d5aa43b96665397dd13ee16023097470fa85e276b93674d62a244de47ee", "https://bcr.bazel.build/modules/aspect_bazel_lib/2.7.7/MODULE.bazel": "491f8681205e31bb57892d67442ce448cda4f472a8e6b3dc062865e29a64f89c", @@ -52,7 +53,8 @@ "https://bcr.bazel.build/modules/bazel_features/1.28.0/MODULE.bazel": "4b4200e6cbf8fa335b2c3f43e1d6ef3e240319c33d43d60cc0fbd4b87ece299d", "https://bcr.bazel.build/modules/bazel_features/1.3.0/MODULE.bazel": "cdcafe83ec318cda34e02948e81d790aab8df7a929cec6f6969f13a489ccecd9", "https://bcr.bazel.build/modules/bazel_features/1.30.0/MODULE.bazel": "a14b62d05969a293b80257e72e597c2da7f717e1e69fa8b339703ed6731bec87", - "https://bcr.bazel.build/modules/bazel_features/1.30.0/source.json": "b07e17f067fe4f69f90b03b36ef1e08fe0d1f3cac254c1241a1818773e3423bc", + "https://bcr.bazel.build/modules/bazel_features/1.32.0/MODULE.bazel": "095d67022a58cb20f7e20e1aefecfa65257a222c18a938e2914fd257b5f1ccdc", + "https://bcr.bazel.build/modules/bazel_features/1.32.0/source.json": "2546c766986a6541f0bacd3e8542a1f621e2b14a80ea9e88c6f89f7eedf64ae1", "https://bcr.bazel.build/modules/bazel_features/1.4.1/MODULE.bazel": "e45b6bb2350aff3e442ae1111c555e27eac1d915e77775f6fdc4b351b758b5d7", "https://bcr.bazel.build/modules/bazel_features/1.9.0/MODULE.bazel": "885151d58d90d8d9c811eb75e3288c11f850e1d6b481a8c9f766adee4712358b", "https://bcr.bazel.build/modules/bazel_features/1.9.1/MODULE.bazel": "8f679097876a9b609ad1f60249c49d68bfab783dd9be012faf9d82547b14815a", @@ -67,7 +69,8 @@ "https://bcr.bazel.build/modules/bazel_skylib/1.6.1/MODULE.bazel": "8fdee2dbaace6c252131c00e1de4b165dc65af02ea278476187765e1a617b917", "https://bcr.bazel.build/modules/bazel_skylib/1.7.0/MODULE.bazel": "0db596f4563de7938de764cc8deeabec291f55e8ec15299718b93c4423e9796d", "https://bcr.bazel.build/modules/bazel_skylib/1.7.1/MODULE.bazel": "3120d80c5861aa616222ec015332e5f8d3171e062e3e804a2a0253e1be26e59b", - "https://bcr.bazel.build/modules/bazel_skylib/1.7.1/source.json": "f121b43eeefc7c29efbd51b83d08631e2347297c95aac9764a701f2a6a2bb953", + "https://bcr.bazel.build/modules/bazel_skylib/1.8.1/MODULE.bazel": "88ade7293becda963e0e3ea33e7d54d3425127e0a326e0d17da085a5f1f03ff6", + "https://bcr.bazel.build/modules/bazel_skylib/1.8.1/source.json": "7ebaefba0b03efe59cac88ed5bbc67bcf59a3eff33af937345ede2a38b2d368a", "https://bcr.bazel.build/modules/bazel_worker_api/0.0.1/MODULE.bazel": "02a13b77321773b2042e70ee5e4c5e099c8ddee4cf2da9cd420442c36938d4bd", "https://bcr.bazel.build/modules/bazel_worker_api/0.0.4/MODULE.bazel": "460aa12d01231a80cce03c548287b433b321d205b0028ae596728c35e5ee442e", "https://bcr.bazel.build/modules/bazel_worker_api/0.0.4/source.json": "d353c410d47a8b65d09fa98e83d57ebec257a2c2b9c6e42d6fda1cb25e5464a5", @@ -153,13 +156,14 @@ "https://bcr.bazel.build/modules/pathkit/1.0.1/source.json": "3215e6b4b08f96f34024eaf186d247744ca255925d7ee3f50cf94f7cf885696b", "https://bcr.bazel.build/modules/platforms/0.0.10/MODULE.bazel": "8cb8efaf200bdeb2150d93e162c40f388529a25852b332cec879373771e48ed5", "https://bcr.bazel.build/modules/platforms/0.0.11/MODULE.bazel": "0daefc49732e227caa8bfa834d65dc52e8cc18a2faf80df25e8caea151a9413f", - "https://bcr.bazel.build/modules/platforms/0.0.11/source.json": "f7e188b79ebedebfe75e9e1d098b8845226c7992b307e28e1496f23112e8fc29", "https://bcr.bazel.build/modules/platforms/0.0.4/MODULE.bazel": "9b328e31ee156f53f3c416a64f8491f7eb731742655a47c9eec4703a71644aee", "https://bcr.bazel.build/modules/platforms/0.0.5/MODULE.bazel": "5733b54ea419d5eaf7997054bb55f6a1d0b5ff8aedf0176fef9eea44f3acda37", "https://bcr.bazel.build/modules/platforms/0.0.6/MODULE.bazel": "ad6eeef431dc52aefd2d77ed20a4b353f8ebf0f4ecdd26a807d2da5aa8cd0615", "https://bcr.bazel.build/modules/platforms/0.0.7/MODULE.bazel": "72fd4a0ede9ee5c021f6a8dd92b503e089f46c227ba2813ff183b71616034814", "https://bcr.bazel.build/modules/platforms/0.0.8/MODULE.bazel": "9f142c03e348f6d263719f5074b21ef3adf0b139ee4c5133e2aa35664da9eb2d", "https://bcr.bazel.build/modules/platforms/0.0.9/MODULE.bazel": "4a87a60c927b56ddd67db50c89acaa62f4ce2a1d2149ccb63ffd871d5ce29ebc", + "https://bcr.bazel.build/modules/platforms/1.0.0/MODULE.bazel": "f05feb42b48f1b3c225e4ccf351f367be0371411a803198ec34a389fb22aa580", + "https://bcr.bazel.build/modules/platforms/1.0.0/source.json": "f4ff1fd412e0246fd38c82328eb209130ead81d62dcd5a9e40910f867f733d96", "https://bcr.bazel.build/modules/prometheus-cpp/1.2.4/MODULE.bazel": "0fbe5dcff66311947a3f6b86ebc6a6d9328e31a28413ca864debc4a043f371e5", "https://bcr.bazel.build/modules/prometheus-cpp/1.3.0/MODULE.bazel": "ce82e086bbc0b60267e970f6a54b2ca6d0f22d3eb6633e00e2cc2899c700f3d8", "https://bcr.bazel.build/modules/prometheus-cpp/1.3.0/source.json": "8cb66b4e535afc718e9d104a3db96ccb71a42ee816a100e50fd0d5ac843c0606", @@ -219,7 +223,8 @@ "https://bcr.bazel.build/modules/rules_cc/0.0.9/MODULE.bazel": "836e76439f354b89afe6a911a7adf59a6b2518fafb174483ad78a2a2fde7b1c5", "https://bcr.bazel.build/modules/rules_cc/0.1.1/MODULE.bazel": "2f0222a6f229f0bf44cd711dc13c858dad98c62d52bd51d8fc3a764a83125513", "https://bcr.bazel.build/modules/rules_cc/0.1.2/MODULE.bazel": "557ddc3a96858ec0d465a87c0a931054d7dcfd6583af2c7ed3baf494407fd8d0", - "https://bcr.bazel.build/modules/rules_cc/0.1.2/source.json": "53fcb09b5816c83ca60d9d7493faf3bfaf410dfc2f15deb52d6ddd146b8d43f0", + "https://bcr.bazel.build/modules/rules_cc/0.2.4/MODULE.bazel": "1ff1223dfd24f3ecf8f028446d4a27608aa43c3f41e346d22838a4223980b8cc", + "https://bcr.bazel.build/modules/rules_cc/0.2.4/source.json": "2bd87ef9b41d4753eadf65175745737135cba0e70b479bdc204ef0c67404d0c4", "https://bcr.bazel.build/modules/rules_detekt/0.8.1.2/MODULE.bazel": "d84df200a766e9f783aa576b6b71f6f20d68c72f9be9e3ae728e1a069806cf55", "https://bcr.bazel.build/modules/rules_detekt/0.8.1.2/source.json": "f067f68422c2267442c84d0055fa74312a083c8a79437072812a5528a01180d2", "https://bcr.bazel.build/modules/rules_foreign_cc/0.10.1/MODULE.bazel": "b9527010e5fef060af92b6724edb3691970a5b1f76f74b21d39f7d433641be60", @@ -317,8 +322,8 @@ "https://bcr.bazel.build/modules/rules_python/1.3.0/source.json": "25932f917cd279c7baefa6cb1d3fa8750a7a29de522024449b19af6eab51f4a0", "https://bcr.bazel.build/modules/rules_robolectric/4.14.1.2/MODULE.bazel": "d44fec647d0aeb67b9f3b980cf68ba634976f3ae7ccd6c07d790b59b87a4f251", "https://bcr.bazel.build/modules/rules_robolectric/4.14.1.2/source.json": "37c10335f2361c337c5c1f34ed36d2da70534c23088062b33a8bdaab68aa9dea", - "https://bcr.bazel.build/modules/rules_rust/0.62.0/MODULE.bazel": "6a15b57982e278793c684f426e19166e62e73f1bd45fe3b6bcedd0b901177b37", - "https://bcr.bazel.build/modules/rules_rust/0.62.0/source.json": "1b3a6551a585ee47cafa21550c5eb87c6f3a56bb9761f9e3421ff1102f220437", + "https://bcr.bazel.build/modules/rules_rust/0.65.0/MODULE.bazel": "1b53caef82fd1c89a2fb15cfa3a15a8e98fe12f4904806b409f5a0183e73f547", + "https://bcr.bazel.build/modules/rules_rust/0.65.0/source.json": "3ea929f53bab109fb903d54f08bd86095c323cc3969c025f69e795b564ac5e5f", "https://bcr.bazel.build/modules/rules_shell/0.1.2/MODULE.bazel": "66e4ca3ce084b04af0b9ff05ff14cab4e5df7503973818bb91cbc6cda08d32fc", "https://bcr.bazel.build/modules/rules_shell/0.2.0/MODULE.bazel": "fda8a652ab3c7d8fee214de05e7a9916d8b28082234e8d2c0094505c5268ed3c", "https://bcr.bazel.build/modules/rules_shell/0.3.0/MODULE.bazel": "de4402cd12f4cc8fda2354fce179fdb068c0b9ca1ec2d2b17b3e21b24c1a937b", @@ -364,37 +369,6 @@ }, "selectedYankedVersions": {}, "moduleExtensions": { - "@@apple_support+//crosstool:setup.bzl%apple_cc_configure_extension": { - "general": { - "bzlTransitiveDigest": "gv4nokEMGNye4Jvoh7Tw0Lzs63zfklj+n4t0UegI7Ms=", - "usagesDigest": "KQVWrmzxrdWZHmzACGxrsuaS4FscNQUmdUjwazd4jHE=", - "recordedFileInputs": {}, - "recordedDirentsInputs": {}, - "envVariables": {}, - "generatedRepoSpecs": { - "local_config_apple_cc_toolchains": { - "repoRuleId": "@@apple_support+//crosstool:setup.bzl%_apple_cc_autoconf_toolchains", - "attributes": {} - }, - "local_config_apple_cc": { - "repoRuleId": "@@apple_support+//crosstool:setup.bzl%_apple_cc_autoconf", - "attributes": {} - } - }, - "recordedRepoMappingEntries": [ - [ - "apple_support+", - "bazel_tools", - "bazel_tools" - ], - [ - "bazel_tools", - "rules_cc", - "rules_cc+" - ] - ] - } - }, "@@aspect_rules_esbuild+//esbuild:extensions.bzl%esbuild": { "general": { "bzlTransitiveDigest": "sCHEKLUzL/knUyFXUmzsIORGC5fGP2nV5lyg0zV6nhY=", diff --git a/bazel/bitdrift_build_system.bzl b/bazel/bitdrift_build_system.bzl index 3b63388e1..b6abd075e 100644 --- a/bazel/bitdrift_build_system.bzl +++ b/bazel/bitdrift_build_system.bzl @@ -1,5 +1,5 @@ load("@crates//:defs.bzl", "aliases", "all_crate_deps") -load("@rules_rust//rust:defs.bzl", "rust_binary", "rust_clippy", "rust_library", "rust_test") +load("@rules_rust//rust:defs.bzl", "rust_binary", "rust_clippy", "rust_library", "rust_shared_library", "rust_test") def bitdrift_rust_binary(name, srcs = None, deps = [], proc_macro_deps = [], **args): rust_binary( @@ -24,6 +24,29 @@ def bitdrift_rust_binary(name, srcs = None, deps = [], proc_macro_deps = [], **a ], ) +def bitdrift_rust_shared_library(name, srcs = None, deps = [], proc_macro_deps = [], rustc_flags = [], **args): + rust_shared_library( + name = name, + srcs = srcs if srcs else native.glob(["src/**/*.rs"]), + deps = all_crate_deps(normal = True) + deps, + proc_macro_deps = all_crate_deps(proc_macro = True) + proc_macro_deps, + aliases = aliases(), + edition = "2021", + rustc_flags = rustc_flags + _rustc_flags(), + **args + ) + + rust_clippy( + name = "_{}_rust_clippy".format(name), + testonly = True, + deps = [ + name, + ], + tags = [ + "manual", + ], + ) + def bitdrift_rust_test(name, deps = [], proc_macro_deps = [], **args): rust_test( name = name, diff --git a/platform/jvm/BUILD.bazel b/platform/jvm/BUILD.bazel index 8ce08493c..537d5ad7b 100644 --- a/platform/jvm/BUILD.bazel +++ b/platform/jvm/BUILD.bazel @@ -1,5 +1,4 @@ -load("@rules_cc//cc:defs.bzl", "cc_binary") -load("//bazel:bitdrift_build_system.bzl", "bitdrift_rust_library") +load("//bazel:bitdrift_build_system.bzl", "bitdrift_rust_library", "bitdrift_rust_shared_library") exports_files(["AndroidManifest.xml"]) @@ -9,44 +8,47 @@ exports_files(["AndroidManifest.xml"]) # at src/platform/jvm named either libcapture.so or libcapture.dylib depending on the platform. # This allows the JniLibrary to load this with the name "capture" when the library path is set # to src/platform/jvm. -cc_binary( - name = "capture", - linkopts = [ - "-lm", # Required to avoid dlopen runtime failures unrelated to rust - "-lz", # Link against system zlib library +bitdrift_rust_shared_library( + name = "capture_shared", + compile_data = [ + "jni_symbols.lds", + ], + crate_name = "capture", + crate_root = "src/lib.rs", + rustc_flags = [ + "-Clink-args=-lm", # Required to avoid dlopen runtime failures unrelated to rust + "-Clink-args=-lz", # Link against system zlib library ] + select({ "@platforms//os:android": [ - "-Wl,-z,max-page-size=16384", # enable 16 KB ELF alignment on Android to support API 35+ - "-Wl,--retain-symbols-file=$(location :jni_symbols.lds)", - "-Wl,--build-id", # Include build id in the binary + "-Clink-args=-Wl,-z,max-page-size=16384", # enable 16 KB ELF alignment on Android to support API 35+ + "-Clink-args=-Wl,--retain-symbols-file=$(location :jni_symbols.lds)", + "-Clink-args=-Wl,--build-id", # Include build id in the binary ], "@platforms//os:linux": ["-Wl,--retain-symbols-file=$(location :jni_symbols.lds)"], # The linker on macos doesn't support the same options or file formats as linux, so use a pattern match here (not availabile on linux). # We could use another file which prefixes all the symbols with _, but this seems easier. "@platforms//os:macos": [ - "-Wl,-exported_symbol,_Java_io_bitdrift_capture_network*", - "-Wl,-exported_symbol,_Java_io_bitdrift_capture_CaptureJni*", - "-Wl,-exported_symbol,_Java_io_bitdrift_capture_Jni*", - "-Wl,-exported_symbol,_JNI_OnLoad", - "-Wl,-framework,Security", + "-Clink-args=-Wl,-exported_symbol,_Java_io_bitdrift_capture_network*", + "-Clink-args=-Wl,-exported_symbol,_Java_io_bitdrift_capture_CaptureJni*", + "-Clink-args=-Wl,-exported_symbol,_Java_io_bitdrift_capture_Jni*", + "-Clink-args=-Wl,-exported_symbol,_JNI_OnLoad", + "-Clink-args=-Wl,-framework,Security", ], "//conditions:default": ["@platforms//:incompatible"], }), - linkshared = True, tags = [ "no-cache", "no-remote", ], visibility = ["//visibility:public"], deps = [ - "jni_symbols.lds", - ":capture_jni", + "//platform/shared:platform-shared", ], ) # This is Rust JNI implementation. Most of the logic lives here. bitdrift_rust_library( - name = "capture_jni", + name = "capture", visibility = ["//visibility:public"], deps = [ "//platform/shared:platform-shared", diff --git a/platform/jvm/Cargo.toml b/platform/jvm/Cargo.toml index 8f59465af..cd95f3cc8 100644 --- a/platform/jvm/Cargo.toml +++ b/platform/jvm/Cargo.toml @@ -34,5 +34,5 @@ tracing-subscriber.workspace = true uuid.workspace = true [lib] -crate-type = ["lib", "cdylib"] +crate-type = ["cdylib"] name = "capture" diff --git a/platform/jvm/capture/build.gradle.kts b/platform/jvm/capture/build.gradle.kts index ed6321854..cc31d8fd1 100644 --- a/platform/jvm/capture/build.gradle.kts +++ b/platform/jvm/capture/build.gradle.kts @@ -113,7 +113,7 @@ cargoNdk { targets = arrayListOf("arm64") // enable 16 KB ELF alignment on Android to support API 35+ extraCargoEnv = mapOf( - "RUSTFLAGS" to "-C link-args=-Wl,-z,max-page-size=16384,--build-id", + "RUSTFLAGS" to "-C codegen-units=1 -C embed-bitcode -C lto=fat -C opt-level=z -C link-args=-Wl,-z,max-page-size=16384,--build-id", "RUSTC_BOOTSTRAP" to "1" // Required for using unstable features in the Rust compiler ) } diff --git a/test/platform/jvm/BUILD b/test/platform/jvm/BUILD index 3a024c863..3e3dab181 100644 --- a/test/platform/jvm/BUILD +++ b/test/platform/jvm/BUILD @@ -1,29 +1,12 @@ -load("@rules_cc//cc:defs.bzl", "cc_binary") -load("//bazel:bitdrift_build_system.bzl", "bitdrift_rust_library") +load("//bazel:bitdrift_build_system.bzl", "bitdrift_rust_shared_library") -bitdrift_rust_library( - name = "test_jni", - testonly = True, - extra_aliases = {"//platform/jvm:capture_jni": "capture"}, - deps = [ - "//platform/jvm:capture_jni", - "//platform/shared:platform-shared", - "//platform/test_helpers", - ], - alwayslink = True, -) - -cc_binary( +bitdrift_rust_shared_library( name = "capture", testonly = True, - linkopts = [ - "-lm", # Required to avoid dlopen runtime failures unrelated to rust - "-lz", # Link against system zlib library - ], - linkshared = True, visibility = ["//visibility:public"], deps = [ - ":test_jni", - "//platform/jvm:capture_jni", + "//platform/jvm:capture", + "//platform/shared:platform-shared", + "//platform/test_helpers", ], )