diff --git a/BUILD b/BUILD index fad7694f52..08864363aa 100644 --- a/BUILD +++ b/BUILD @@ -49,6 +49,18 @@ platform( constraint_values = [ "@platforms//cpu:x86_64", "@platforms//os:none", + "//bazel/rust:avx_ON", + "//bazel/rust:soft_float_OFF", + ], +) + +platform( + name = "x86_64-unknown-none-noavx-softfloat", + constraint_values = [ + "@platforms//cpu:x86_64", + "@platforms//os:none", + "//bazel/rust:avx_OFF", + "//bazel/rust:soft_float_ON", ], ) diff --git a/bazel/rust/BUILD b/bazel/rust/BUILD index 2e6e6e4577..a1e50223c5 100644 --- a/bazel/rust/BUILD +++ b/bazel/rust/BUILD @@ -14,4 +14,33 @@ # limitations under the License. # -package(licenses = ["notice"]) +package( + default_visibility = ["//visibility:public"], + licenses = ["notice"], +) + +# Controls the use of the +avx and +avx2 C compiler features. +constraint_setting(name = "avx") + +constraint_value( + name = "avx_ON", + constraint_setting = "avx", +) + +constraint_value( + name = "avx_OFF", + constraint_setting = "avx", +) + +# Controls the use of the soft-float C compiler feature. +constraint_setting(name = "soft_float") + +constraint_value( + name = "soft_float_ON", + constraint_setting = "soft_float", +) + +constraint_value( + name = "soft_float_OFF", + constraint_setting = "soft_float", +) diff --git a/bazel/rust/defs.bzl b/bazel/rust/defs.bzl index 34c4939a4d..b8595d87b4 100644 --- a/bazel/rust/defs.bzl +++ b/bazel/rust/defs.bzl @@ -14,8 +14,13 @@ RUST_VERSIONS = [ RUST_EDITION = "2021" -def setup_rust_dependencies(): - """Set up the various rust-related dependencies. Call this after load_rust_repositories().""" +def setup_rust_dependencies(oak_repo_name = "oak"): + """Set up the various rust-related dependencies. Call this after load_rust_repositories(). + + + Args: + oak_repo_name: to be used when Oak repo is renamed. + """ rules_rust_dependencies() rust_register_toolchains( @@ -30,23 +35,38 @@ def setup_rust_dependencies(): }, ) - _BARE_METAL_RUSTC_FLAGS = [ - "-C", - "target-feature=+avx,+avx2,-soft-float", - ] - # Creates remote repositories for Rust toolchains, required for cross-compiling. rust_repository_set( name = "rust_toolchain_repo", edition = RUST_EDITION, exec_triple = "x86_64-unknown-linux-gnu", extra_rustc_flags = { - "x86_64-unknown-none": _BARE_METAL_RUSTC_FLAGS, + "x86_64-unknown-none": ["-C", "target-feature=+avx,+avx2,-soft-float"], + }, + extra_target_triples = { + "x86_64-unknown-none": [ + "@platforms//cpu:x86_64", + "@platforms//os:none", + "@%s//bazel/rust:avx_ON" % oak_repo_name, + "@%s//bazel/rust:soft_float_OFF" % oak_repo_name, + ], + }, + versions = RUST_VERSIONS, + ) + + rust_repository_set( + name = "rust_noavx_softfloat_toolchain_repo", + edition = RUST_EDITION, + exec_triple = "x86_64-unknown-linux-gnu", + extra_rustc_flags = { + "x86_64-unknown-none": ["-C", "target-feature=+soft-float"], }, extra_target_triples = { "x86_64-unknown-none": [ "@platforms//cpu:x86_64", "@platforms//os:none", + "@%s//bazel/rust:avx_OFF" % oak_repo_name, + "@%s//bazel/rust:soft_float_ON" % oak_repo_name, ], }, versions = RUST_VERSIONS, diff --git a/bazel/test_workspace/WORKSPACE b/bazel/test_workspace/WORKSPACE index 9f786c5d20..a0cb5da0e3 100644 --- a/bazel/test_workspace/WORKSPACE +++ b/bazel/test_workspace/WORKSPACE @@ -123,7 +123,7 @@ load_rust_repositories() load("@oak2//bazel/rust:defs.bzl", "setup_rust_dependencies") -setup_rust_dependencies() +setup_rust_dependencies(oak_repo_name = "oak2") load("@rules_cc//cc:repositories.bzl", "rules_cc_dependencies", "rules_cc_toolchains") diff --git a/oak_restricted_kernel_wrapper/BUILD b/oak_restricted_kernel_wrapper/BUILD index 12bd735bd5..e0b0ec5ecc 100644 --- a/oak_restricted_kernel_wrapper/BUILD +++ b/oak_restricted_kernel_wrapper/BUILD @@ -30,7 +30,7 @@ rust_binary( ], features = ["no_libstdcxx"], # See https://github.com/f0rmiga/gcc-toolchain/blob/0.4.2/docs/README.md linker_script = ":layout.ld", - platform = "//:x86_64-unknown-none", + platform = "//:x86_64-unknown-none-noavx-softfloat", rustc_env = { "PAYLOAD_PATH": "$(location //oak_restricted_kernel_bin:oak_restricted_kernel_bin_virtio_console_channel)", }, @@ -55,7 +55,7 @@ rust_binary( ], features = ["no_libstdcxx"], # See https://github.com/f0rmiga/gcc-toolchain/blob/0.4.2/docs/README.md linker_script = ":layout.ld", - platform = "//:x86_64-unknown-none", + platform = "//:x86_64-unknown-none-noavx-softfloat", rustc_env = { "PAYLOAD_PATH": "$(location //oak_restricted_kernel_bin:oak_restricted_kernel_bin_simple_io_channel)", },