Skip to content

Instantly share code, notes, and snippets.

@YorikSar
Last active February 22, 2022 15:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save YorikSar/d1cfc806b611c4506d2a1957c05653b7 to your computer and use it in GitHub Desktop.
Save YorikSar/d1cfc806b611c4506d2a1957c05653b7 to your computer and use it in GitHub Desktop.
rules_rust on macOS libiconv issue reproduction
/bazel-*
/hello

If compiling with Bazel throws error:

 % nix-shell --command "bazel run :hello" 
Starting local Bazel server and connecting to it...          
INFO: Invocation ID: 14406348-9458-4f5a-ab59-21a9e1567ce2
INFO: Analyzed target //:hello (30 packages loaded, 202 targets configured).
INFO: Found 1 target...
ERROR: /Users/tweag/workspaces/bazel_on_macos/rules_nixpkgs/examples/toolchains/rust-clean/BUILD:3:12: Compiling Rust bin hello (1 files) failed: (Exit 1): process_wrapper failed: error executing command bazel-out/darwin-opt-exec-2B5CBBC6/bin/external/rules_rust/util/proc
ess_wrapper/process_wrapper --subst 'pwd=${pwd}' -- external/rust_darwin_x86_64/bin/rustc hello.rs '--crate-name=hello' ... (remaining 17 argument(s) skipped)
                                                                    
Use --sandbox_debug to see verbose messages from the sandbox
error: linking with `external/local_config_cc/cc_wrapper.sh` failed: exit status: 1
  |          
  = note: "external/local_config_cc/cc_wrapper.sh" "-m64" "-arch" "x86_64" "bazel-out/darwin-fastbuild/bin/hello.hello.996e1e6f-cgu.0.rcgu.o" "bazel-out/darwin-fastbuild/bin/hello.hello.996e1e6f-cgu.1.rcgu.o" "bazel-out/darwin-fastbuild/bin/hello.hello.996e1e6f-cgu.2.rcgu.o" "bazel-out/darwin-fastbuild/bin/hello.hello.996e1e6f-cgu.3.rcgu.o" "bazel-out/darwin-fastbuild/bin/hello.hello.996e1e6f-cgu.4.rcgu.o" "bazel-out/darwin-fastbuild/bin/hello.hello.996e1e6f-cgu.5.rcgu.o" "bazel-out/darwin-fastbuild/bin/hello.hello.996e1e6f-cgu.6.rcgu.o" "bazel-out/darwin-fastbuild/bin/hello.hello.996e1e6f-cgu.7.rcgu.o" "bazel-out/darwin-fastbuild/bin/hello.hello.996e1e6f-cgu.8.rcgu.o" "bazel-out/darwin-fastbuild/bin/hello.hello.996e1e6f-cgu.9.rcgu.o" "bazel-out/darwin-fastbuild/bin/hello.2qbjdfrzgcayd1in.rcgu.o" "-L" "external/rust_darwin_x86_64/lib/rustlib/x86_64-apple-darwin/lib" "-L" "/private/var/tmp/_bazel_tweag/05e065ca46a9245f748c7b326be0ff58/external/rust_darwin_x86_64/lib/rustlib/x86_64-apple-darwin/lib" "/private/var/tmp/_bazel_tweag/05e065ca46a9245f748c7b326be0ff58/external/rust_darwin_x86_64/lib/rustlib/x86_64-apple-darwin/lib/libstd-8ae2edd646da4ea0.rlib" "/private/var/tmp/_bazel_tweag/05e065ca46a9245f748c7b326be0ff58/external/rust_darwin_x86_64/lib/rustlib/x86_64-apple-darwin/lib/libpanic_unwind-47c5cc91a00140fb.rlib" "/private/var/tmp/_bazel_tweag/05e065ca46a9245f748c7b326be0ff58/external/rust_darwin_x86_64/lib/rustlib/x86_64-apple-darwin/lib/libobject-0635b3ffd941fa76.rlib" "/private/var/tmp/_bazel_tweag/05e065ca46a9245f748c7b326be0ff58/external/rust_darwin_x86_64/lib/rustlib/x86_64-apple-darwin/lib/libmemchr-12f450400d05eaa8.rlib" "/private/var/tmp/_bazel_tweag/05e065ca46a9245f748c7b326be0ff58/external/rust_darwin_x86_64/lib/rustlib/x86_64-apple-darwin/lib/libaddr2line-804bd071f93d6e75.rlib" "/private/var/tmp/_bazel_tweag/05e065ca46a9245f748c7b326be0ff58/external/rust_darwin_x86_64/lib/rustlib/x86_64-apple-darwin/lib/libgimli-f332340a1082559f.rlib" "/private/var/tmp/_bazel_tweag/05e065ca46a9245f748c7b326be0ff58/external/rust_darwin_x86_64/lib/rustlib/x86_64-apple-darwin/lib/libstd_detect-dde3e8fabbe181c1.rlib" "/private/var/tmp/_bazel_tweag/05e065ca46a9245f748c7b326be0ff58/external/rust_darwin_x86_64/lib/rustlib/x86_64-apple-darwin/lib/librustc_demangle-c36c713681e58b9e.rlib" "/private/var/tmp/_bazel_tweag/05e065ca46a9245f748c7b326be0ff58/external/rust_darwin_x86_64/lib/rustlib/x86_64-apple-darwin/lib/libhashbrown-87a78d4c56f6dd13.rlib" "/private/var/tmp/_bazel_tweag/05e065ca46a9245f748c7b326be0ff58/external/rust_darwin_x86_64/lib/rustlib/x86_64-apple-darwin/lib/librustc_std_workspace_alloc-9300ab98f79fcb3b.rlib" "/private/var/tmp/_bazel_tweag/05e065ca46a9245f748c7b326be0ff58/external/rust_darwin_x86_64/lib/rustlib/x86_64-apple-darwin/lib/libunwind-cfe930b5c1e0407c.rlib" "/private/var/tmp/_bazel_tweag/05e065ca46a9245f748c7b326be0ff58/external/rust_darwin_x86_64/lib/rustlib/x86_64-apple-darwin/lib/libcfg_if-e99436e9ec713221.rlib" "/private/var/tmp/_bazel_tweag/05e065ca46a9245f748c7b326be0ff58/external/rust_darwin_x86_64/lib/rustlib/x86_64-apple-darwin/lib/liblibc-0fe32f79765a3820.rlib" "/private/var/tmp/_bazel_tweag/05e065ca46a9245f748c7b326be0ff58/external/rust_darwin_x86_64/lib/rustlib/x86_64-apple-darwin/lib/liballoc-26802d5ee2a9c482.rlib" "/private/var/tmp/_bazel_tweag/05e065ca46a9245f748c7b326be0ff58/external/rust_darwin_x86_64/lib/rustlib/x86_64-apple-darwin/lib/librustc_std_workspace_core-1ea009dd7ebe6325.rlib" "/private/var/tmp/_bazel_tweag/05e065ca46a9245f748c7b326be0ff58/external/rust_darwin_x86_64/lib/rustlib/x86_64-apple-darwin/lib/libcore-31b098f8a2fd6989.rlib" "/private/var/tmp/_bazel_tweag/05e065ca46a9245f748c7b326be0ff58/external/rust_darwin_x86_64/lib/rustlib/x86_64-apple-darwin/lib/libcompiler_builtins-bc8e57a7c90d33c8.rlib" "-lSystem" "-lresolv" "-lc" "-lm" "-liconv" "-L" "/private/var/tmp/_bazel_tweag/05e065ca46a9245f748c7b326be0ff58/external/rust_darwin_x86_64/lib/rustlib/x86_64-apple-darwin/lib" "-o" "bazel-out/darwin-fastbuild/bin/hello" "-Wl,-dead_strip" "-nodefaultlibs" "-undefined" "dynamic_lookup" "-headerpad_max_install_names" "-lstdc++" "-lm"
  = note: ld: library not found for -liconv
          clang-7: error: linker command failed with exit code 1 (use -v to see invocation)
           

error: aborting due to previous error

Target //:hello failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 9.795s, Critical Path: 1.02s
INFO: 13 processes: 4 remote cache hit, 9 internal.
FAILED: Build did NOT complete successfully
FAILED: Build did NOT complete successfully

(the same happens without nix-shell with plain bazel run :hello)

But compiling with Rust directly succeeds:

 % nix-shell --command "rustc hello.rs && ./hello"
Hello world!
fn main() {
println!("Hello world!");
}
{
"owner": "NixOS",
"repo": "nixpkgs",
"branch": "21.11",
"rev": "506445d88e183bce80e47fc612c710eb592045ed",
"sha256": "162dywda2dvfj1248afxc45kcrg83appjd0nmdb541hl7rnncf02"
}
let
# nixpkgs-unstable as of 2021-02-19
spec = builtins.fromJSON (builtins.readFile ./nixpkgs.json);
nixpkgs = fetchTarball {
url = "https://github.com/${spec.owner}/${spec.repo}/archive/${spec.rev}.tar.gz";
sha256 = spec.sha256;
};
in
import nixpkgs
{ pkgs ? import ./nixpkgs.nix { } }:
pkgs.mkShell {
nativeBuildInputs = [ pkgs.bazel_4 pkgs.rustc pkgs.libiconv ];
}
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
# https://bazelbuild.github.io/rules_rust/#setup
revision = "dc66c1612b7a3e96531eff22136570124c8eec81"
http_archive(
name = "rules_rust",
sha256 = "9dadbcd1136f7d4f3f2e7c0790531be0fdcccc535dec42a4c5a6f2df7380e3e3",
strip_prefix = "rules_rust-{}".format(revision),
urls = [
# `main` branch as of 2021-12-01
"https://github.com/bazelbuild/rules_rust/archive/{}.tar.gz".format(revision),
],
)
load("@rules_rust//rust:repositories.bzl", "rust_repositories")
rust_repositories()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment