diff --git a/crate_universe/Cargo.lock b/crate_universe/Cargo.lock index 4bebf73ab8..1c3b662e25 100644 --- a/crate_universe/Cargo.lock +++ b/crate_universe/Cargo.lock @@ -243,9 +243,9 @@ dependencies = [ [[package]] name = "cfg-expr" -version = "0.18.0" +version = "0.20.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a2b34126159980f92da2a08bdec0694fd80fb5eb9e48aff25d20a0d8dfa710d" +checksum = "9acd0bdbbf4b2612d09f52ba61da432140cb10930354079d0d53fafc12968726" dependencies = [ "smallvec", ] diff --git a/crate_universe/Cargo.toml b/crate_universe/Cargo.toml index 88fb9e6989..8286841527 100644 --- a/crate_universe/Cargo.toml +++ b/crate_universe/Cargo.toml @@ -69,7 +69,7 @@ cargo_metadata = "0.19.2" cargo_toml = "0.22.1" cargo-lock = "10.1.0" cargo-platform = "0.1.9" -cfg-expr = "0.18.0" +cfg-expr = "0.20.4" clap = { version = "4.5.37", features = ["derive", "env"] } crates-index = { version = "3.7.0", default-features = false, features = [ "git", diff --git a/examples/all_deps_vendor/MODULE.bazel b/examples/all_deps_vendor/MODULE.bazel index 6e9d996faa..c3a90f5af7 100644 --- a/examples/all_deps_vendor/MODULE.bazel +++ b/examples/all_deps_vendor/MODULE.bazel @@ -23,7 +23,7 @@ local_path_override( # Rust toolchain RUST_EDITION = "2021" -RUST_VERSION = "1.79.0" +RUST_VERSION = "1.86.0" rust = use_extension("@rules_rust//rust:extensions.bzl", "rust") rust.toolchain( diff --git a/rust/platform/BUILD.bazel b/rust/platform/BUILD.bazel index d5513b1e79..b19c75fa6b 100644 --- a/rust/platform/BUILD.bazel +++ b/rust/platform/BUILD.bazel @@ -21,6 +21,26 @@ constraint_value( constraint_setting = ":wasi_version", ) +constraint_setting( + name = "qnx_version", + default_constraint_value = ":qnx7", # For backwards compatibility +) + +constraint_value( + name = "qnx7", + constraint_setting = ":qnx_version", +) + +constraint_value( + name = "qnx7_iosock", + constraint_setting = ":qnx_version", +) + +constraint_value( + name = "qnx8", + constraint_setting = ":qnx_version", +) + package_group( name = "function_transition_allowlist", packages = [ diff --git a/rust/platform/triple_mappings.bzl b/rust/platform/triple_mappings.bzl index 6070591e6b..5612bc35ab 100644 --- a/rust/platform/triple_mappings.bzl +++ b/rust/platform/triple_mappings.bzl @@ -75,7 +75,12 @@ SUPPORTED_T2_PLATFORM_TRIPLES = { _T3_PLATFORM_TRIPLES = { "aarch64-unknown-nto-qnx710": _support(std = True, host_tools = False), + "aarch64-unknown-nto-qnx710_iosock": _support(std = True, host_tools = False), + "aarch64-unknown-nto-qnx800": _support(std = True, host_tools = False), "wasm64-unknown-unknown": _support(std = False, host_tools = False), + "x86_64-pc-nto-qnx710": _support(std = True, host_tools = False), + "x86_64-pc-nto-qnx710_iosock": _support(std = True, host_tools = False), + "x86_64-pc-nto-qnx800": _support(std = True, host_tools = False), } # The only T3 triples that are supported are ones with at least a stdlib @@ -282,6 +287,12 @@ _SYSTEM_TO_STDLIB_LINKFLAGS = { "windows": ["advapi32.lib", "ws2_32.lib", "userenv.lib", "Bcrypt.lib"], } +_NTO_ABI_TO_CONSTRAINT = { + "qnx710": "@rules_rust//rust/platform:qnx7", + "qnx710_iosock": "@rules_rust//rust/platform:qnx7_iosock", + "qnx800": "@rules_rust//rust/platform:qnx8", +} + def cpu_arch_to_constraints(cpu_arch, *, system = None): """Returns a list of constraint values which represents a triple's CPU. @@ -346,6 +357,9 @@ def abi_to_constraints(abi, *, arch = None, system = None): else: all_abi_constraints.append("@build_bazel_apple_support//constraints:device") + if system == "nto": + all_abi_constraints.append(_NTO_ABI_TO_CONSTRAINT[abi]) + # TODO(bazelbuild/platforms#38): Implement when C++ toolchain is more mature and we # figure out how they're doing this return all_abi_constraints diff --git a/rust/private/rustc.bzl b/rust/private/rustc.bzl index 48be035043..49d51e4e14 100644 --- a/rust/private/rustc.bzl +++ b/rust/private/rustc.bzl @@ -71,6 +71,8 @@ AliasableDepInfo = provider( _error_format_values = ["human", "json", "short"] +_OS_WITH_DYLINK_SUPPORT = ["linux", "darwin", "macos", "android", "nto"] + ErrorFormatInfo = provider( doc = "Set the --error-format flag for all rustc invocations", fields = {"error_format": "(string) [" + ", ".join(_error_format_values) + "]"}, @@ -1974,7 +1976,7 @@ def _compute_rpaths(toolchain, output_dir, dep_info, use_pic): # without a version of Bazel that includes # https://github.com/bazelbuild/bazel/pull/13427. This is known to not be # included in Bazel 4.1 and below. - if toolchain.target_os not in ["linux", "darwin", "macos", "android"]: + if toolchain.target_os not in _OS_WITH_DYLINK_SUPPORT: fail("Runtime linking is not supported on {}, but found {}".format( toolchain.target_os, dep_info.transitive_noncrates, diff --git a/test/unit/platform_triple/BUILD.bazel b/test/unit/platform_triple/BUILD.bazel index bb30c72b66..d2507f09f8 100644 --- a/test/unit/platform_triple/BUILD.bazel +++ b/test/unit/platform_triple/BUILD.bazel @@ -1,5 +1,6 @@ load(":platform_triple_test.bzl", "platform_triple_test_suite") load(":wasi_platform_test.bzl", "wasi_platform_test_suite") +load(":qnx_version_test.bzl", "qnx_version_constraints_test") platform_triple_test_suite( name = "platform_triple_test_suite", @@ -8,3 +9,7 @@ platform_triple_test_suite( wasi_platform_test_suite( name = "wasi_platform_test_suite", ) + +qnx_version_constraints_test( + name = "qnx_version_test_suite", +) diff --git a/test/unit/platform_triple/qnx_version_test.bzl b/test/unit/platform_triple/qnx_version_test.bzl new file mode 100644 index 0000000000..2dd1fdbad2 --- /dev/null +++ b/test/unit/platform_triple/qnx_version_test.bzl @@ -0,0 +1,108 @@ +"""Tests for WASI platform constraint mappings""" + +load("@bazel_skylib//lib:unittest.bzl", "asserts", "unittest") +load("//rust/platform:triple_mappings.bzl", "triple_to_constraint_set") + +def _qnx_version_constraints_test_impl(ctx): + env = unittest.begin(ctx) + + # Test aarch64 QNX7 constraints + qnx_version_constraints = triple_to_constraint_set("aarch64-unknown-nto-qnx710") + asserts.equals( + env, + [ + "@platforms//cpu:aarch64", + "@platforms//os:qnx", + "@rules_rust//rust/platform:qnx7", + ], + qnx_version_constraints, + "aarch64-unknown-nto-qnx710 doesn't map to the appropriate constraints", + ) + + # Test aarch64 QNX7 with iopkt constraints + qnx_version_constraints = triple_to_constraint_set("aarch64-unknown-nto-qnx710_iosock") + asserts.equals( + env, + [ + "@platforms//cpu:aarch64", + "@platforms//os:qnx", + "@rules_rust//rust/platform:qnx7_iosock", + ], + qnx_version_constraints, + "aarch64-unknown-nto-qnx710_iosock doesn't map to the appropriate constraints", + ) + + # Test aarch64 QNX8 constraints + qnx_version_constraints = triple_to_constraint_set("aarch64-unknown-nto-qnx800") + asserts.equals( + env, + [ + "@platforms//cpu:aarch64", + "@platforms//os:qnx", + "@rules_rust//rust/platform:qnx8", + ], + qnx_version_constraints, + "aarch64-unknown-nto-qnx800 doesn't map to the appropriate constraints", + ) + + # Test x86_64 QNX7 constraints + qnx_version_constraints = triple_to_constraint_set("x86_64-pc-nto-qnx710") + asserts.equals( + env, + [ + "@platforms//cpu:x86_64", + "@platforms//os:qnx", + "@rules_rust//rust/platform:qnx7", + ], + qnx_version_constraints, + "x86_64-pc-nto-qnx710 doesn't map to the appropriate constraints", + ) + + # Test x86_64 QNX7 with iosock constraints + qnx_version_constraints = triple_to_constraint_set("x86_64-pc-nto-qnx710_iosock") + asserts.equals( + env, + [ + "@platforms//cpu:x86_64", + "@platforms//os:qnx", + "@rules_rust//rust/platform:qnx7_iosock", + ], + qnx_version_constraints, + "x86_64-pc-nto-qnx710_iosock doesn't map to the appropriate constraints", + ) + + # Test x86_64 QNX8 constraints + qnx_version_constraints = triple_to_constraint_set("x86_64-pc-nto-qnx800") + asserts.equals( + env, + [ + "@platforms//cpu:x86_64", + "@platforms//os:qnx", + "@rules_rust//rust/platform:qnx8", + ], + qnx_version_constraints, + "x86_64-pc-nto-qnx800 doesn't map to the appropriate constraints", + ) + + return unittest.end(env) + +_qnx_version_constraints_test = unittest.make(_qnx_version_constraints_test_impl) + +def qnx_version_constraints_test(name, **kwargs): + """Define a test suite for the QNX version to constraints mappings + + Args: + name (str): The name of the test suite. + **kwargs (dict): Additional keyword arguments for the test_suite. + """ + _qnx_version_constraints_test( + name = "qnx_version_constraints_test", + ) + + native.test_suite( + name = name, + tests = [ + ":qnx_version_constraints_test", + ], + **kwargs + )