Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom toolchain fails if stdlib is not coupled to compiler #213

Closed
RafaelMarinheiro opened this issue Apr 8, 2019 · 1 comment · Fixed by #258
Closed

Custom toolchain fails if stdlib is not coupled to compiler #213

RafaelMarinheiro opened this issue Apr 8, 2019 · 1 comment · Fixed by #258

Comments

@RafaelMarinheiro
Copy link

I'm trying to create a custom toolchain in which the compiler and the stdlib are in separate repositories. I'm trying to do this to make bazel download only the pieces I want.

An example toolchain definition looks as follows (note that rust_lib comes from a different repo):

rust_toolchain(
    name = "rust-toolchain-x86_64-unknown-linux-gnu-to-x86_64-unknown-linux-gnu-impl",
    rust_doc = "@rustc_1.33.0_x86_64-unknown-linux-gnu//:rustdoc",
    rust_lib = "@rust_std_1.33.0_x86_64-unknown-linux-gnu//:rust_lib",
    rustc = "@rustc_1.33.0_x86_64-unknown-linux-gnu//:rustc",
    rustc_lib = "@rustc_1.33.0_x86_64-unknown-linux-gnu//:rustc_lib",
    staticlib_ext = ".a",
    dylib_ext = ".so",
    os = "linux",
    exec_triple = "x86_64-unknown-linux-gnu",
    target_triple = "x86_64-unknown-linux-gnu",
    visibility = ["//visibility:public"],
)

toolchain(
    name = "rust-toolchain-x86_64-unknown-linux-gnu-to-x86_64-unknown-linux-gnu",
    exec_compatible_with = ["@bazel_tools//platforms:linux", "@bazel_tools//platforms:x86_64"],
    target_compatible_with = ["@bazel_tools//platforms:linux", "@bazel_tools//platforms:x86_64"],
    toolchain = "rust-toolchain-x86_64-unknown-linux-gnu-to-x86_64-unknown-linux-gnu-impl",
    toolchain_type = "@io_bazel_rules_rust//rust:toolchain",
)

In this case both the compiler and the library are targeting the same platform. When I try to compile a hello world I get the following error:

$ bazel build -s //hello:hello
INFO: Analysed target //hello:hello (13 packages loaded, 230 targets configured).
INFO: Found 1 target...
SUBCOMMAND: # //hello:hello [action 'Compiling Rust bin hello (1 files)']
(cd /home/marinheiro/.cache/bazel/_bazel_marinheiro/d06419e7e664fd9ccf9c83b04640a470/execroot/testing && \
  exec env - \
    CARGO_PKG_AUTHORS='' \
    CARGO_PKG_DESCRIPTION='' \
    CARGO_PKG_HOMEPAGE='' \
    CARGO_PKG_NAME=hello \
    CARGO_PKG_VERSION=0.0.0 \
    CARGO_PKG_VERSION_MAJOR=0 \
    CARGO_PKG_VERSION_MINOR=0 \
    CARGO_PKG_VERSION_PATCH=0 \
    CARGO_PKG_VERSION_PRE='' \
  /bin/bash -c 'external/rustc_1.33.0_x86_64-unknown-linux-gnu/bin/rustc "$@" --remap-path-prefix="$(pwd)"=__bazel_redacted_pwd' '' hello/hello.rs '--crate-name=hello' '--crate-type=bin' '--codegen=metadata=' '--out-dir=bazel-out/k8-fastbuild/bin/hello' '--codegen=extra-filename=' '--codegen=opt-level=0' '--codegen=debuginfo=0' '--emit=dep-info,link' '--color=always' '--target=x86_64-unknown-linux-gnu' '--codegen=linker=/usr/bin/gcc' --codegen 'link-args=-fuse-ld=gold -Wl,-no-as-needed -Wl,-z,relro,-z,now -B/usr/bin -pass-exit-codes -lstdc++ -lm')
ERROR: /home/marinheiro/Code/embedded/hello/BUILD:6:1: error executing shell command: '/bin/bash -c external/rustc_1.33.0_x86_64-unknown-linux-gnu/bin/rustc "$@" --remap-path-prefix="$(pwd)"=__bazel_redacted_pwd  hello/hello.rs --crate-name=hello --crate-t
ype=bin --codegen=metadata= ...' failed (Exit 1) bash failed: error executing command /bin/bash -c 'external/rustc_1.33.0_x86_64-unknown-linux-gnu/bin/rustc "$@" --remap-path-prefix="$(pwd)"=__bazel_redacted_pwd' '' hello/hello.rs '--crate-name=hello' '--crate-type=bin' ... (remaining 11 argument(s) skipped)

Use --sandbox_debug to see verbose messages from the sandbox
error[E0463]: can't find crate for `std`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0463`.
Target //hello:hello failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 0.246s, Critical Path: 0.08s
INFO: 0 processes.
FAILED: Build did NOT complete successfull

From the output it looks like the generated command does not add the stdlib to the linker search path. Looking through the code it seems that it simply ignores that. Fixing it could be as simple as simply adding the -L flag to the generated command. I have not tried that yet, though.

@mfarrugi
Copy link
Collaborator

mfarrugi commented Apr 8, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants