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

Rust Bazel build is failing with a compilation issue in [email protected] #1786

Closed
mgingios opened this issue Oct 31, 2023 · 5 comments
Closed

Comments

@mgingios
Copy link

mgingios commented Oct 31, 2023

Hello,

I have a Rust client/server project that is built with Bazel. The build aborts at the following location in ring:

--stderr:
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: NotPresent', external/crate_index__ring-0.17.5/build.rs:797:55

I can provide access to the source in github, if desired. Here is the log of the build in case it can be helpful:

/usr/bin/make -f /Users/mike/Git/rust/abitofhelp/helloworld-tonic-bsr-bazel/Makefile -C /Users/mike/Git/rust/abitofhelp/helloworld-tonic-bsr-bazel baz_build_all
Loading: 
Loading: 
Loading: 
    Fetching repository @crate_index; starting
Loading: 
    Fetching repository @crate_index; Restarting.
Loading: 
    Fetching repository @crate_index; Generating crate BUILD files.
Loading: 
Loading: 0 packages loaded
Analyzing: 3 targets (4 packages loaded, 0 targets configured)
Analyzing: 3 targets (85 packages loaded, 7 targets configured)
    currently loading: @rules_rust//rust/rust_analyzer
Analyzing: 3 targets (191 packages loaded, 4540 targets configured)
    currently loading: @crate_index__syn-2.0.38//
    Fetching ...sitory @local_config_xcode; Fetching the default Xcode version
Analyzing: 3 targets (194 packages loaded, 4988 targets configured)
    Fetching repository @local_config_xcode; Building xcode-locator
Analyzing: 3 targets (194 packages loaded, 4988 targets configured)
    Fetching repository @local_config_xcode; Running xcode-locator
Analyzing: 3 targets (194 packages loaded, 4988 targets configured)
    Fetching ...config_xcode; Fetching SDK information for Xcode 15.0.1.15A507
Analyzing: 3 targets (194 packages loaded, 4988 targets configured)
    currently loading: @local_config_xcode//
INFO: Analyzed 3 targets (195 packages loaded, 5227 targets configured).
 checking cached actions
INFO: Found 3 targets...
 checking cached actions
[0 / 5] [Prepa] BazelWorkspaceStatusAction stable-status.txt
[129 / 263] checking cached actions
[230 / 263] 2 actions running
    Compiling Rust rlib syn v2.0.38 (91 files) [for tool]; 0s darwin-sandbox
    Running Cargo build script ring; 0s darwin-sandbox
ERROR: /private/var/tmp/_bazel_mike/e86a93cbfb4a68ed0b4feea0a1eefc57/external/crate_index__ring-0.17.5/BUILD.bazel:166:19: Running Cargo build script ring failed: (Exit 1): cargo_build_script_runner failed: error executing command (from target @crate_index__ring-0.17.5//:ring_build_script) bazel-out/darwin-opt-exec-2B5CBBC6/bin/external/rules_rust/cargo/cargo_build_script_runner/cargo_build_script_runner ... (remaining 10 arguments skipped)

Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
Build script process failed with exit code 101
--stdout:
cargo:rerun-if-env-changed=RING_PREGENERATE_ASM

--stderr:
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: NotPresent', external/crate_index__ring-0.17.5/build.rs:797:55
stack backtrace:
   0:        0x10a848546 - std::backtrace_rs::backtrace::libunwind::trace::h0a908cd09b5a35f9
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:        0x10a848546 - std::backtrace_rs::backtrace::trace_unsynchronized::hc0e7d5d16c14a788
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:        0x10a848546 - std::sys_common::backtrace::_print_fmt::hcf9ca6805c7eb2fe
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/sys_common/backtrace.rs:65:5
   3:        0x10a848546 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hae51cb91d407e2ef
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/sys_common/backtrace.rs:44:22
   4:        0x10a8621cb - core::fmt::write::h746bc0969202388b
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/core/src/fmt/mod.rs:1254:17
   5:        0x10a844a8c - std::io::Write::write_fmt::h4098c2c7437a0bd7
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/io/mod.rs:1698:15
   6:        0x10a84831a - std::sys_common::backtrace::_print::he6d3aef1f6c73e2d
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/sys_common/backtrace.rs:47:5
   7:        0x10a84831a - std::sys_common::backtrace::print::h8360bf0158e89b36
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/sys_common/backtrace.rs:34:9
   8:        0x10a84a180 - std::panicking::default_hook::{{closure}}::hedf04c568eb6e0bc
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/panicking.rs:269:22
   9:        0x10a849f30 - std::panicking::default_hook::h62889b2c29e2347d
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/panicking.rs:288:9
  10:        0x10a84a6da - std::panicking::rust_panic_with_hook::h22edd02828aff274
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/panicking.rs:691:13
  11:        0x10a84a5f4 - std::panicking::begin_panic_handler::{{closure}}::h6895f44a9b7e2caa
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/panicking.rs:582:13
  12:        0x10a848989 - std::sys_common::backtrace::__rust_end_short_backtrace::h013519e9b77978c5
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/sys_common/backtrace.rs:150:18
  13:        0x10a84a33d - rust_begin_unwind
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/panicking.rs:578:5
  14:        0x10a86cb63 - core::panicking::panic_fmt::h2a51b60c12d11322
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/core/src/panicking.rs:67:14
  15:        0x10a86cf15 - core::result::unwrap_failed::h52a6a55d409027df
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/core/src/result.rs:1687:5
  16:        0x10a7f8e0d - build_script_build::ring_core_prefix::hd7a69e5bc5789619
  17:        0x10a7f4fb4 - build_script_build::main::hc7e526b413791d47
  18:        0x10a7fd946 - std::sys_common::backtrace::__rust_begin_short_backtrace::hc134345a10977538
  19:        0x10a7fa60c - std::rt::lang_start::{{closure}}::hb93924bf202d1467
  20:        0x10a840ec2 - core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once::h4d31ab51fa4afcb3
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/core/src/ops/function.rs:287:13
  21:        0x10a840ec2 - std::panicking::try::do_call::h29870f82be4076a9
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/panicking.rs:485:40
  22:        0x10a840ec2 - std::panicking::try::h5d28bc317561a503
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/panicking.rs:449:19
  23:        0x10a840ec2 - std::panic::catch_unwind::hcec89f8ee3292969
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/panic.rs:140:14
  24:        0x10a840ec2 - std::rt::lang_start_internal::{{closure}}::h8aa82e7014dd312d
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/rt.rs:148:48
  25:        0x10a840ec2 - std::panicking::try::do_call::hd2313fc9b34e2403
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/panicking.rs:485:40
  26:        0x10a840ec2 - std::panicking::try::hc5bb97f422b5bdd9
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/panicking.rs:449:19
  27:        0x10a840ec2 - std::panic::catch_unwind::h8202c14898aaf8af
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/panic.rs:140:14
  28:        0x10a840ec2 - std::rt::lang_start_internal::h36134e47b0b0d769
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/rt.rs:148:20
  29:        0x10a7f9b8c - _main
  30:     0x7ff80617e3a6 - <unknown>

[231 / 263] @crate_index__syn-2.0.38//:syn; 0s darwin-sandbox
INFO: Elapsed time: 6.656s, Critical Path: 0.52s
[232 / 263] checking cached actions
INFO: 3 processes: 3 internal.
[232 / 263] checking cached actions
FAILED: Build did NOT complete successfully
make: *** [baz_build_all] Error 1

Process finished with exit code 2
@briansmith
Copy link
Owner

Like 797 is:

    let links = std::env::var("CARGO_MANIFEST_LINKS").unwrap();

@wmcrobertsq
Copy link

Upgrade to rules_rust 0.29.0. Adds in support for CARGO_MANIFEST_LINKS.

References:
https://github.com/bazelbuild/rules_rust/releases/tag/0.29.0
bazelbuild/rules_rust#2190

@wmcrobertsq
Copy link

As a work-around if you can't upgrade to rules_rust 0.29.0, you can add in a crate.annotation to inject the environment variable.

.
.
# Crates index for external dependencies.
crates_repository(
    name = "crate_index",
    cargo_lockfile = "//:Cargo.lock",
    lockfile = "//:Cargo.bazel.lock",
    annotations = {
        "ring": [crate.annotation(
            build_script_env = {"CARGO_MANIFEST_LINKS": "ring_core_0_17_5"}
        )],
    },
    packages = {
		.
		.
		.
	}
)
.
.

References
http://bazelbuild.github.io/rules_rust/crate_universe.html#crates_repository-annotations
http://bazelbuild.github.io/rules_rust/crate_universe.html#crate.annotation-build_script_env

@briansmith
Copy link
Owner

As a work-around if you can't upgrade to rules_rust 0.29.0, you can add in a crate.annotation to inject the environment variable.

If you do this, I would do it in some way that automates the updating of this field so that it doesn't get out of sync, since the use of the environment variable is a critical memory-safety requirement necessary for allowing multiple versionf of ring to coexist.

@briansmith
Copy link
Owner

Issue #1977 tracks improving ring's build machinery to directly support Bazel (and GN). Issue #1920 tracks improving the documentation and creating a checking of what to do when updating ring when using an alternative build system.

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

No branches or pull requests

3 participants