diff --git a/.bazelci/presubmit.yml b/.bazelci/presubmit.yml index aecd38a0f5..90db471381 100644 --- a/.bazelci/presubmit.yml +++ b/.bazelci/presubmit.yml @@ -454,9 +454,16 @@ tasks: platform: macos working_directory: examples/ios_build test_flags: - - "--platforms=//:ios_x86_64" + - "--cpu=ios_x86_64" + - "--apple_platform_type=ios" test_targets: - "//..." + zig_cross_compiling: + name: Zig cross compiling test + platform: ubuntu2004 + working_directory: examples/zig_cross_compiling + build_targets: + - "//..." buildifier: version: latest diff --git a/cargo/private/cargo_build_script.bzl b/cargo/private/cargo_build_script.bzl index b752daedd3..ed9a3e2ebf 100644 --- a/cargo/private/cargo_build_script.bzl +++ b/cargo/private/cargo_build_script.bzl @@ -17,31 +17,6 @@ load("//rust/private:utils.bzl", "dedent", "expand_dict_value_locations", "find_ # Reexport for cargo_build_script_wrapper.bzl name_to_crate_name = _name_to_crate_name -def strip_target(elems): - """Remove '-target xxx' from C(XX)FLAGS. - - The cpp toolchain adds '-target xxx' and '-isysroot xxx' to CFLAGS. If it is not stripped out before - the CFLAGS are provided to build scripts, it can cause the build to take on the host architecture - instead of the target architecture. - - Args: - elems (list): A list of args - - Returns: - list: the modified args - """ - skip_next = False - out_elems = [] - for elem in elems: - if skip_next: - skip_next = False - continue - if elem == "-target" or elem == "-isysroot": - skip_next = True - continue - out_elems.append(elem) - return out_elems - def get_cc_compile_args_and_env(cc_toolchain, feature_configuration): """Gather cc environment variables from the given `cc_toolchain` @@ -59,16 +34,16 @@ def get_cc_compile_args_and_env(cc_toolchain, feature_configuration): feature_configuration = feature_configuration, cc_toolchain = cc_toolchain, ) - cc_c_args = strip_target(cc_common.get_memory_inefficient_command_line( + cc_c_args = cc_common.get_memory_inefficient_command_line( feature_configuration = feature_configuration, action_name = C_COMPILE_ACTION_NAME, variables = compile_variables, - )) - cc_cxx_args = strip_target(cc_common.get_memory_inefficient_command_line( + ) + cc_cxx_args = cc_common.get_memory_inefficient_command_line( feature_configuration = feature_configuration, action_name = CPP_COMPILE_ACTION_NAME, variables = compile_variables, - )) + ) cc_env = cc_common.get_environment_variables( feature_configuration = feature_configuration, action_name = C_COMPILE_ACTION_NAME, diff --git a/examples/.bazelignore b/examples/.bazelignore index cd22faa3b8..a921d20439 100644 --- a/examples/.bazelignore +++ b/examples/.bazelignore @@ -4,3 +4,4 @@ crate_universe crate_universe_unnamed ios ios_build +zig_cross_compiling diff --git a/examples/ios_build/platform_mappings b/examples/ios_build/platform_mappings new file mode 100644 index 0000000000..3b9c09712b --- /dev/null +++ b/examples/ios_build/platform_mappings @@ -0,0 +1,21 @@ +# https://github.com/bazelbuild/rules_apple/issues/1658 +flags: + --cpu=darwin_x86_64 + --apple_platform_type=macos + //:macos_x86_64 + + --cpu=darwin_arm64 + --apple_platform_type=macos + //:macos_arm64 + + --cpu=ios_x86_64 + --apple_platform_type=ios + //:ios_x86_64 + + --cpu=ios_sim_arm64 + --apple_platform_type=ios + //:ios_sim_arm64 + + --cpu=ios_arm64 + --apple_platform_type=ios + //:ios_arm64 diff --git a/examples/zig_cross_compiling/.bazelrc b/examples/zig_cross_compiling/.bazelrc new file mode 100644 index 0000000000..fbd75a7ea7 --- /dev/null +++ b/examples/zig_cross_compiling/.bazelrc @@ -0,0 +1 @@ +build --incompatible_enable_cc_toolchain_resolution diff --git a/examples/zig_cross_compiling/.gitignore b/examples/zig_cross_compiling/.gitignore new file mode 100644 index 0000000000..a6ef824c1f --- /dev/null +++ b/examples/zig_cross_compiling/.gitignore @@ -0,0 +1 @@ +/bazel-* diff --git a/examples/zig_cross_compiling/BUILD.bazel b/examples/zig_cross_compiling/BUILD.bazel new file mode 100644 index 0000000000..ad5b376955 --- /dev/null +++ b/examples/zig_cross_compiling/BUILD.bazel @@ -0,0 +1,26 @@ +load("@aspect_bazel_lib//lib:transitions.bzl", "platform_transition_filegroup") +load("@crate_index//:defs.bzl", "aliases", "all_crate_deps") +load("@rules_rust//rust:defs.bzl", "rust_binary") + +rust_binary( + name = "uses_ring", + srcs = ["src/main.rs"], + aliases = aliases(), + # We don't care about building this for our own platform, this just exists for the transition + tags = ["manual"], + deps = all_crate_deps(normal = True), +) + +platform( + name = "aarch64_linux", + constraint_values = [ + "@platforms//os:linux", + "@platforms//cpu:aarch64", + ], +) + +platform_transition_filegroup( + name = "uses_ring_arm", + srcs = [":uses_ring"], + target_platform = "aarch64_linux", +) diff --git a/examples/zig_cross_compiling/Cargo.bazel.lock b/examples/zig_cross_compiling/Cargo.bazel.lock new file mode 100644 index 0000000000..d27d82deef --- /dev/null +++ b/examples/zig_cross_compiling/Cargo.bazel.lock @@ -0,0 +1,206 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "bumpalo" +version = "3.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "572f695136211188308f16ad2ca5c851a712c464060ae6974944458eb83880ba" + +[[package]] +name = "cc" +version = "1.0.76" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76a284da2e6fe2092f2353e51713435363112dfd60030e22add80be333fb928f" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "direct-cargo-bazel-deps" +version = "0.0.1" +dependencies = [ + "ring", +] + +[[package]] +name = "js-sys" +version = "0.3.60" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49409df3e3bf0856b916e2ceaca09ee28e6871cf7d9ce97a692cacfdb2a25a47" +dependencies = [ + "wasm-bindgen", +] + +[[package]] +name = "libc" +version = "0.2.137" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc7fcc620a3bff7cdd7a365be3376c97191aeaccc2a603e600951e452615bf89" + +[[package]] +name = "log" +version = "0.4.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "once_cell" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86f0b0d4bf799edbc74508c1e8bf170ff5f41238e5f8225603ca7caaae2b7860" + +[[package]] +name = "proc-macro2" +version = "1.0.47" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ea3d908b0e36316caf9e9e2c4625cdde190a7e6f440d794667ed17a1855e725" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "ring" +version = "0.16.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3053cf52e236a3ed746dfc745aa9cacf1b791d846bdaf412f60a8d7d6e17c8fc" +dependencies = [ + "cc", + "libc", + "once_cell", + "spin", + "untrusted", + "web-sys", + "winapi", +] + +[[package]] +name = "spin" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" + +[[package]] +name = "syn" +version = "1.0.103" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a864042229133ada95abf3b54fdc62ef5ccabe9515b64717bcb9a1919e59445d" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "unicode-ident" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ceab39d59e4c9499d4e5a8ee0e2735b891bb7308ac83dfb4e80cad195c9f6f3" + +[[package]] +name = "untrusted" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" + +[[package]] +name = "wasm-bindgen" +version = "0.2.83" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eaf9f5aceeec8be17c128b2e93e031fb8a4d469bb9c4ae2d7dc1888b26887268" +dependencies = [ + "cfg-if", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.83" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c8ffb332579b0557b52d268b91feab8df3615f265d5270fec2a8c95b17c1142" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.83" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "052be0f94026e6cbc75cdefc9bae13fd6052cdcaf532fa6c45e7ae33a1e6c810" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.83" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07bc0c051dc5f23e307b13285f9d75df86bfdf816c5721e573dec1f9b8aa193c" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.83" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c38c045535d93ec4f0b4defec448e4291638ee608530863b1e2ba115d4fff7f" + +[[package]] +name = "web-sys" +version = "0.3.60" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bcda906d8be16e728fd5adc5b729afad4e444e106ab28cd1c7256e54fa61510f" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/examples/zig_cross_compiling/WORKSPACE.bazel b/examples/zig_cross_compiling/WORKSPACE.bazel new file mode 100644 index 0000000000..323115cd02 --- /dev/null +++ b/examples/zig_cross_compiling/WORKSPACE.bazel @@ -0,0 +1,83 @@ +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") + +BAZEL_ZIG_CC_VERSION = "v0.9.2" + +http_archive( + name = "bazel-zig-cc", + sha256 = "73afa7e1af49e3dbfa1bae9362438cdc51cb177c359a6041a7a403011179d0b5", + strip_prefix = "bazel-zig-cc-{}".format(BAZEL_ZIG_CC_VERSION), + urls = ["https://git.sr.ht/~motiejus/bazel-zig-cc/archive/{}.tar.gz".format(BAZEL_ZIG_CC_VERSION)], +) + +load("@bazel-zig-cc//toolchain:defs.bzl", zig_toolchains = "toolchains") + +zig_toolchains() + +register_toolchains( + "@zig_sdk//toolchain:linux_arm64_gnu.2.28", +) + +local_repository( + name = "rules_rust", + path = "../..", +) + +load("@rules_rust//rust:repositories.bzl", "rules_rust_dependencies", "rust_register_toolchains", "rust_repository_set") + +rules_rust_dependencies() + +load("@rules_rust//crate_universe:repositories.bzl", "crate_universe_dependencies") + +crate_universe_dependencies(bootstrap = True) + +rust_version = "1.65.0" + +rust_register_toolchains( + edition = "2021", + extra_target_triples = [], + version = rust_version, +) + +rust_repository_set( + name = "macos_x86_64", + edition = "2021", + exec_triple = "x86_64-apple-darwin", + extra_target_triples = ["aarch64-unknown-linux-gnu"], + version = rust_version, +) + +rust_repository_set( + name = "linux_x86_64", + edition = "2021", + exec_triple = "x86_64-unknown-linux-gnu", + extra_target_triples = ["aarch64-unknown-linux-gnu"], + version = rust_version, +) + +load("@rules_rust//crate_universe:defs.bzl", "crate", "crates_repository") + +crates_repository( + name = "crate_index", + cargo_lockfile = "//:Cargo.bazel.lock", + # `generator` is not necessary in official releases. + # See load satement for `cargo_bazel_bootstrap`. + generator = "@cargo_bazel_bootstrap//:cargo-bazel", + packages = { + "ring": crate.spec(version = "0.16.20"), + }, +) + +load("@crate_index//:defs.bzl", "crate_repositories") + +crate_repositories() + +http_archive( + name = "aspect_bazel_lib", + sha256 = "3534a27621725fbbf1d3e53daa0c1dda055a2732d9031b8c579f917d7347b6c4", + strip_prefix = "bazel-lib-1.16.1", + url = "https://github.com/aspect-build/bazel-lib/archive/refs/tags/v1.16.1.tar.gz", +) + +load("@aspect_bazel_lib//lib:repositories.bzl", "aspect_bazel_lib_dependencies") + +aspect_bazel_lib_dependencies() diff --git a/examples/zig_cross_compiling/src/main.rs b/examples/zig_cross_compiling/src/main.rs new file mode 100644 index 0000000000..c2873e80d4 --- /dev/null +++ b/examples/zig_cross_compiling/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("{:?}", ring::rand::SystemRandom::new()); +}