Skip to content

Commit

Permalink
Create a toolchain to build with no AVX and softfloat options
Browse files Browse the repository at this point in the history
BUG: 356600135
Change-Id: If47eefc45d943b0e3a9eaf1ff2ffb5ce3a6d6b61
  • Loading branch information
ernoc committed Aug 5, 2024
1 parent 7d89eeb commit e0b3f59
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 12 deletions.
12 changes: 12 additions & 0 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
)

Expand Down
31 changes: 30 additions & 1 deletion bazel/rust/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
36 changes: 28 additions & 8 deletions bazel/rust/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion bazel/test_workspace/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
4 changes: 2 additions & 2 deletions oak_restricted_kernel_wrapper/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
},
Expand All @@ -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)",
},
Expand Down

0 comments on commit e0b3f59

Please sign in to comment.