Skip to content

Commit

Permalink
bazel: Switch to pre-built standard library
Browse files Browse the repository at this point in the history
Now that we have the pre-built copies of the Rust standard library
for x86_64-unknown-none, we can use those instead of fetching libcore
and liballoc with the host copy of Rust and fetching compiler_builtins
directly. We also don't need to build them any more.

This takes us part of the way to getting cross-compiling for free
with rules_rust.

See #14.

Signed-off-by: SlyMarbo <[email protected]>
  • Loading branch information
SlyMarbo committed Apr 15, 2022
1 parent e847d29 commit e73072b
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 219 deletions.
45 changes: 26 additions & 19 deletions bazel/cross-compiling/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -14,35 +14,42 @@
# command line option implicitly, rather than the
# user needing to specify it explicitly.

load("//bazel/cross-compiling:librust.bzl", "find_librust_entrypoint", "rust_no_std")
load("@rules_rust//rust:defs.bzl", "rust_stdlib_filegroup")
load("//bazel:copy_file.bzl", "copy_file")
load("//bazel/cross-compiling:x86_64_cc_toolchain.bzl", "x86_64_cc_toolchain")
load("//bazel/cross-compiling:x86_64_rust_toolchain.bzl", "x86_64_rust_toolchain")

# Find the entrypoint (lib.rs) for
# the alloc and core crates.
# Package the core, compiler-builtins,
# and alloc crates.

find_librust_entrypoint(
name = "liballoc_entry",
crate = "alloc",
rustc_srcs = "@rust_linux_x86_64//lib/rustlib/src:rustc_srcs",
copy_file(
name = "liballoc.rlib",
src = "@rust_none_x86_64//:liballoc",
)

find_librust_entrypoint(
name = "libcore_entry",
crate = "core",
rustc_srcs = "@rust_linux_x86_64//lib/rustlib/src:rustc_srcs",
copy_file(
name = "libcompiler_builtins.rlib",
src = "@rust_none_x86_64//:libcompiler_builtins",
)

# Build the core, compiler-builtins,
# and alloc crates.
copy_file(
name = "libcore.rlib",
src = "@rust_none_x86_64//:libcore",
)

rust_no_std(
copy_file(
name = "librustc_std_workspace_core.rlib",
src = "@rust_none_x86_64//:librustc_std_workspace_core",
)

rust_stdlib_filegroup(
name = "bare_metal_base",
liballoc_entry = ":liballoc_entry",
libcore_entry = ":libcore_entry",
rustc = "@rust_linux_x86_64//:rustc",
rustc_srcs = "@rust_linux_x86_64//lib/rustlib/src:rustc_srcs",
target = "x86_64-unknown-none",
srcs = [
":liballoc.rlib",
":libcompiler_builtins.rlib",
":libcore.rlib",
":librustc_std_workspace_core.rlib",
],
)

# Set up our toolchains now that we have
Expand Down
176 changes: 0 additions & 176 deletions bazel/cross-compiling/librust.bzl

This file was deleted.

1 change: 0 additions & 1 deletion bazel/cross-compiling/x86_64_rust_toolchain.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ def x86_64_rust_toolchain(name, target_triple, stdlib_filegroup):
rust_std = stdlib_filegroup,
rustc = "@rust_linux_x86_64//:rustc",
rustc_lib = "@rust_linux_x86_64//:rustc_lib",
rustc_srcs = "@rust_linux_x86_64//lib/rustlib/src:rustc_srcs",
rustfmt = "@rust_linux_x86_64//:rustfmt_bin",
staticlib_ext = ".a",
stdlib_linkflags = [],
Expand Down
12 changes: 0 additions & 12 deletions bazel/deps/rust.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -160,17 +160,6 @@ def rust_deps():
],
)

http_archive(
name = "compiler_builtins",
build_file = "//bazel/third_party:compiler_builtins.BUILD",
sha256 = "80873f979f0a344a4ade87c2f70d9ccf5720b83b10c97ec7cd745895d021e85a",
strip_prefix = "compiler_builtins-0.1.70",
type = "tgz",
urls = [
"https://static.crates.io/crates/compiler_builtins/compiler_builtins-0.1.70.crate",
],
)

# Fetch libcore, liballoc, and libcompiler-builtins
# for the x86_64-unknown-none build target.

Expand All @@ -190,7 +179,6 @@ def rust_deps():

rust_register_toolchains(
edition = "2021",
include_rustc_srcs = True,
iso_date = RUST_ISO_DATE,
rustfmt_version = RUST_VERSION,
sha256s = {
Expand Down
11 changes: 0 additions & 11 deletions bazel/third_party/compiler_builtins.BUILD

This file was deleted.

0 comments on commit e73072b

Please sign in to comment.