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

bug: mc-util-build-script sometimes panics during the build #9

Closed
cbeck88 opened this issue Sep 1, 2021 · 3 comments
Closed

bug: mc-util-build-script sometimes panics during the build #9

cbeck88 opened this issue Sep 1, 2021 · 3 comments
Assignees

Comments

@cbeck88
Copy link

cbeck88 commented Sep 1, 2021

Steps to reproduce:

Go to libmobilecoin (or android-bindings) and attempt to build in the mobile profile:

Here we reproduce the issue inside the dev docker container:

root@561c93eeaf77:/tmp/mobilenode/libmobilecoin# cargo build -Z unstable-options --profile=mobile
   Compiling serde v1.0.118
   Compiling mc-util-build-script v1.1.2 (/tmp/mobilenode/util/build/script)
   Compiling mbedtls-sys-auto v2.26.1 (https://github.com/mobilecoinofficial/rust-mbedtls.git?rev=c7fa3f0c737f36af8f437e147131d1f5c8a90b0e#c7fa3f0c)
   Compiling mc-util-build-sgx v1.1.2 (/tmp/mobilenode/util/build/sgx)
   Compiling mc-util-build-grpc v1.1.2 (/tmp/mobilenode/util/build/grpc)
   Compiling mc-api v1.1.2 (/tmp/mobilenode/api)
   Compiling mc-attest-ake v1.1.2 (/tmp/mobilenode/attest/ake)
error: failed to run custom build command for `mc-attest-ake v1.1.2 (/tmp/mobilenode/attest/ake)`

Caused by:
  process didn't exit successfully: `/tmp/mobilenode/target/mobile/build/mc-attest-ake-337598f541ef1db0/build-script-build` (exit code: 101)
  --- stderr
  target: "x86_64-unknown-linux-gnu"
  profile: "release"
  thread 'main' panicked at 'Could not read environment: OutDir("/tmp/mobilenode/target/mobile/build/mc-attest-ake-1fb3238e24239703/out")', util/build/script/src/env.rs:212:28
  stack backtrace:
     0:     0x55d15beedd50 - std::backtrace_rs::backtrace::libunwind::trace::h4dee703919bfd40a
                                 at /rustc/07e0e2ec268c140e607e1ac7f49f145612d0f597/library/std/src/../../backtrace/src/backtrace/libunwind.rs:90:5
     1:     0x55d15beedd50 - std::backtrace_rs::backtrace::trace_unsynchronized::h457e839f1a563e20
                                 at /rustc/07e0e2ec268c140e607e1ac7f49f145612d0f597/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
     2:     0x55d15beedd50 - std::sys_common::backtrace::_print_fmt::h86a55fb30f8393c8
                                 at /rustc/07e0e2ec268c140e607e1ac7f49f145612d0f597/library/std/src/sys_common/backtrace.rs:67:5
     3:     0x55d15beedd50 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h7b3d6cac46d277e1
                                 at /rustc/07e0e2ec268c140e607e1ac7f49f145612d0f597/library/std/src/sys_common/backtrace.rs:46:22
     4:     0x55d15bf0456f - core::fmt::write::h127419eb46f2ecc9
                                 at /rustc/07e0e2ec268c140e607e1ac7f49f145612d0f597/library/core/src/fmt/mod.rs:1092:17
     5:     0x55d15beeb9a5 - std::io::Write::write_fmt::h6010cfbb4726588b
                                 at /rustc/07e0e2ec268c140e607e1ac7f49f145612d0f597/library/std/src/io/mod.rs:1578:15
     6:     0x55d15beef8bb - std::sys_common::backtrace::_print::h79b4f9652330cc9d
                                 at /rustc/07e0e2ec268c140e607e1ac7f49f145612d0f597/library/std/src/sys_common/backtrace.rs:49:5
     7:     0x55d15beef8bb - std::sys_common::backtrace::print::h330bb326a76af8cf
                                 at /rustc/07e0e2ec268c140e607e1ac7f49f145612d0f597/library/std/src/sys_common/backtrace.rs:36:9
     8:     0x55d15beef8bb - std::panicking::default_hook::{{closure}}::heb6a42a7d50a472e
                                 at /rustc/07e0e2ec268c140e607e1ac7f49f145612d0f597/library/std/src/panicking.rs:208:50
     9:     0x55d15beef383 - std::panicking::default_hook::h17e521ba6d68d6e1
                                 at /rustc/07e0e2ec268c140e607e1ac7f49f145612d0f597/library/std/src/panicking.rs:225:9
    10:     0x55d15beefe6d - std::panicking::rust_panic_with_hook::h70db735e3a6e70cb
                                 at /rustc/07e0e2ec268c140e607e1ac7f49f145612d0f597/library/std/src/panicking.rs:591:17
    11:     0x55d15beefa67 - std::panicking::begin_panic_handler::{{closure}}::h777c71c8e5a7e25c
                                 at /rustc/07e0e2ec268c140e607e1ac7f49f145612d0f597/library/std/src/panicking.rs:497:13
    12:     0x55d15beee20c - std::sys_common::backtrace::__rust_end_short_backtrace::h3e9bf30168899554
                                 at /rustc/07e0e2ec268c140e607e1ac7f49f145612d0f597/library/std/src/sys_common/backtrace.rs:141:18
    13:     0x55d15beef9c9 - rust_begin_unwind
                                 at /rustc/07e0e2ec268c140e607e1ac7f49f145612d0f597/library/std/src/panicking.rs:493:5
    14:     0x55d15bea65c1 - core::panicking::panic_fmt::h5322a082d19786c3
                                 at /rustc/07e0e2ec268c140e607e1ac7f49f145612d0f597/library/core/src/panicking.rs:92:14
    15:     0x55d15bea64b3 - core::option::expect_none_failed::h354eaa93a51d71b8
                                 at /rustc/07e0e2ec268c140e607e1ac7f49f145612d0f597/library/core/src/option.rs:1329:5
    16:     0x55d15beae3cd - core::result::Result<T,E>::expect::h2aa3b4bbf91ccb9a
    17:     0x55d15beb4b2f - <mc_util_build_script::env::Environment as core::default::Default>::default::h06dd0e849339cfad
    18:     0x55d15bea6e52 - build_script_build::main::hee41298ea6795070
    19:     0x55d15bea7116 - core::ops::function::FnOnce::call_once::hec78b32044e5661f
    20:     0x55d15bea6fd9 - std::sys_common::backtrace::__rust_begin_short_backtrace::h801904163f8958c0
    21:     0x55d15bea708c - std::rt::lang_start::{{closure}}::h2bf0628613fa731a
    22:     0x55d15bef026a - core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once::hbcc915e668c7ca11
                                 at /rustc/07e0e2ec268c140e607e1ac7f49f145612d0f597/library/core/src/ops/function.rs:259:13
    23:     0x55d15bef026a - std::panicking::try::do_call::h6b0f430d48122ddf
                                 at /rustc/07e0e2ec268c140e607e1ac7f49f145612d0f597/library/std/src/panicking.rs:379:40
    24:     0x55d15bef026a - std::panicking::try::h6ba420e2e21b5afa
                                 at /rustc/07e0e2ec268c140e607e1ac7f49f145612d0f597/library/std/src/panicking.rs:343:19
    25:     0x55d15bef026a - std::panic::catch_unwind::h8366719d1f615eee
                                 at /rustc/07e0e2ec268c140e607e1ac7f49f145612d0f597/library/std/src/panic.rs:431:14
    26:     0x55d15bef026a - std::rt::lang_start_internal::h965c28c9ce06ee73
                                 at /rustc/07e0e2ec268c140e607e1ac7f49f145612d0f597/library/std/src/rt.rs:51:25
    27:     0x55d15bea7071 - std::rt::lang_start::haec78bb97846b919
    28:     0x55d15bea6f93 - main
    29:     0x7faf7550ebf7 - __libc_start_main
    30:     0x55d15bea6c6a - _start
    31:                0x0 - <unknown>
warning: build failed, waiting for other jobs to finish...
error: build failed

(The log contains some debugging output that I added)

The issue occurs at this line:

https://github.com/mobilecoinfoundation/mobilecoin/blob/bcb3e26cc85afd3a250f2109e9cd388c0e5c814a/util/build/script/src/env.rs#L226

The code assumes that if we walk up from the out_dir that cargo creates for the crate, we will eventually either hit a directory whose name matches the "target-triple", in this case x86_64-unknown-linux-gnu, or that matches the profile, in this case "release". However, when using the named profile "mobile", the directory will be called "mobile" and not "release".

This script is deducing the profile using PROFILE env: https://github.com/mobilecoinfoundation/mobilecoin/blob/bcb3e26cc85afd3a250f2109e9cd388c0e5c814a/util/build/script/src/env.rs#L224

But this is documented: https://doc.rust-lang.org/cargo/reference/environment-variables.html

PROFILE — release for release builds, debug for other builds.

and doesn't appear to be updated when the named-profiles feature is used.

As a workaround, the build works if we pass cargo the target explicitly:

cargo build -Z unstable-options --profile=mobile --target x86_64-unknown-linux-gnu

Proposal:

In mc-util-build-script, instead of searching for a directory whose name matches PROFILE, we should search for a directory whose name matches "target", and then back up one when we find that, so that builds using named profiles will work as expected without workarounds.

@jcape
Copy link
Contributor

jcape commented Sep 1, 2021

That's fine, I'd also suggest reporting upstream.

@cbeck88
Copy link
Author

cbeck88 commented Sep 1, 2021

I left a comment on the tracking-issue for this feature: rust-lang/cargo#6988 (comment)

@jcape jcape self-assigned this Jan 30, 2023
@jcape jcape transferred this issue from mobilecoinfoundation/mobilecoin Feb 27, 2023
@jcape jcape assigned varsha888 and unassigned jcape Feb 27, 2023
@varsha888 varsha888 moved this from Todo to In Progress in Blockchain Core Mar 3, 2023
@jcape
Copy link
Contributor

jcape commented Apr 7, 2023

Fixed in #12

@jcape jcape closed this as completed Apr 7, 2023
@github-project-automation github-project-automation bot moved this from In Progress to Done in Blockchain Core Apr 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

No branches or pull requests

3 participants