osmosis-labs / test-tube

Test tube for cosmos-sdk chains integration test, written in Rust!
Apache License 2.0
53 stars 31 forks source link

Error: linking with cc failed #28

Closed CyberHoward closed 4 months ago

CyberHoward commented 1 year ago

When using test-tube as an execution environment I run into the following error:

error: linking with `cc` failed: exit status: 1
|
  = note: LC_ALL="C" PATH="/Users/robin/.rustup/toolchains/stable-aarch
  // a dump....
  ct/abstract/framework/target/debug/deps/authz-2cb5cbbc2d1e019a" "-Wl,-dead_strip" "-nodefaultlibs"
  = note: ld: warning: ignoring file /Users/robin/Programming/Abstract/abstract/framework/target/debug/deps/libosmosistesttube.dylib, building for macOS-arm64 but attempting to link with file built for macOS-x86_64
          Undefined symbols for architecture arm64:
            "_AccountNumber", referenced from:
                test_tube::runner::app::BaseApp::create_signed_tx::heeb23fb2f1dc67e9 in authz-2cb5cbbc2d1e019a.pofc1mhaai8ywix.rcgu.o
            "_AccountSequence", referenced from:
                test_tube::runner::app::BaseApp::create_signed_tx::heeb23fb2f1dc67e9 in authz-2cb5cbbc2d1e019a.pofc1mhaai8ywix.rcgu.o
            "_BeginBlock", referenced from:
                test_tube::runner::app::BaseApp::run_block::h35beeb6f6973b738 in authz-2cb5cbbc2d1e019a.pofc1mhaai8ywix.rcgu.o
                test_tube::runner::app::BaseApp::run_block::h4f5cf920549feaf9 in authz-2cb5cbbc2d1e019a.pofc1mhaai8ywix.rcgu.o
                test_tube::runner::app::BaseApp::run_block::h9d5e1886d063572f in authz-2cb5cbbc2d1e019a.pofc1mhaai8ywix.rcgu.o
                test_tube::runner::app::BaseApp::init_account::hb6c1758ff816e7c9 in libtest_tube-32dac9dd450a6ea7.rlib(test_tube-32dac9dd450a6ea7.test_tube.585259ba-cgu.7.rcgu.o)
            "_EndBlock", referenced from:
                test_tube::runner::app::BaseApp::run_block::h35beeb6f6973b738 in authz-2cb5cbbc2d1e019a.pofc1mhaai8ywix.rcgu.o
                test_tube::runner::app::BaseApp::run_block::h4f5cf920549feaf9 in authz-2cb5cbbc2d1e019a.pofc1mhaai8ywix.rcgu.o
                test_tube::runner::app::BaseApp::run_block::h9d5e1886d063572f in authz-2cb5cbbc2d1e019a.pofc1mhaai8ywix.rcgu.o
                test_tube::runner::app::BaseApp::init_account::hb6c1758ff816e7c9 in libtest_tube-32dac9dd450a6ea7.rlib(test_tube-32dac9dd450a6ea7.test_tube.585259ba-cgu.7.rcgu.o)
            "_Execute", referenced from:
                _$LT$test_tube..runner..app..BaseApp$u20$as$u20$test_tube..runner..Runner$GT$::execute_multiple_raw::_$u7b$$u7b$closure$u7d$$u7d$::h2352f24e142551de in authz-2cb5cbbc2d1e019a.pofc1mhaai8ywix.rcgu.o
                _$LT$test_tube..runner..app..BaseApp$u20$as$u20$test_tube..runner..Runner$GT$::execute_multiple_raw::_$u7b$$u7b$closure$u7d$$u7d$::h514c07ab6259dcc1 in authz-2cb5cbbc2d1e019a.pofc1mhaai8ywix.rcgu.o
                _$LT$test_tube..runner..app..BaseApp$u20$as$u20$test_tube..runner..Runner$GT$::execute_multiple_raw::_$u7b$$u7b$closure$u7d$$u7d$::h6fe04a9bd8ec67c7 in authz-2cb5cbbc2d1e019a.pofc1mhaai8ywix.rcgu.o
            "_InitAccount", referenced from:
                test_tube::runner::app::BaseApp::init_account::hb6c1758ff816e7c9 in libtest_tube-32dac9dd450a6ea7.rlib(test_tube-32dac9dd450a6ea7.test_tube.585259ba-cgu.7.rcgu.o)
            "_InitTestEnv", referenced from:
                test_tube::runner::app::BaseApp::new::h1f50c7e5febe166b in libtest_tube-32dac9dd450a6ea7.rlib(test_tube-32dac9dd450a6ea7.test_tube.585259ba-cgu.7.rcgu.o)
            "_Query", referenced from:
                _$LT$test_tube..runner..app..BaseApp$u20$as$u20$test_tube..runner..Runner$GT$::query::h6e7977d2643c0655 in authz-2cb5cbbc2d1e019a.pofc1mhaai8ywix.rcgu.o
            "_Simulate", referenced from:
                test_tube::runner::app::BaseApp::simulate_tx::h69440b7504931d3f in authz-2cb5cbbc2d1e019a.pofc1mhaai8ywix.rcgu.o
          ld: symbol(s) not found for architecture arm64
          clang: error: linker command failed with exit code 1 (use -v to see invocation)

Are there any pre-requisites that I might not have installed? I didn't see any in the readme. Running on an M1 max.

CyberHoward commented 1 year ago

Looks like this is because osmosisd only supports x86.

https://docs.osmosis.zone/osmosis-core/osmosisd/

apollo-sturdy commented 1 year ago

I got this just now on our CI: https://github.com/mars-protocol/red-bank/actions/runs/5621988241/job/15233817436?pr=267

Not sure why it happened. I managed to solve it by running the job on macos-latest instead of ubuntu-latest.

apollo-sturdy commented 1 year ago

@CyberHoward Are you running linux? Perhaps its a linux issue.

CyberHoward commented 1 year ago

No, running the latest Mac OS.

njerschow commented 1 year ago

Also seeing this. looks like test-tube/packages/osmosis-test-tube/libosmosistesttube is build for x86 and when running on mac os M1/2 linking for arm architecture fails

cc @iboss-ptk

JakeHartnell commented 1 year ago

Also having this issue. Makes it more annoying to write tests with this library... and it's so nice I want to use it.

j0nl1 commented 1 year ago

I also have the same issue running on Apple M1 Max

CyberHoward commented 1 year ago

A temporary fix I've found is to run the test in a x86 docker container. dockerfile.

But it's a lot slower.

iboss-ptk commented 11 months ago

@CyberHoward @njerschow @j0nl1 @JakeHartnell

I was really wondering about this issue since I'm on m1 max as well and there is no issue.

But one possibility might be because of rust toolchain .

run rustup show and check if active toolchain some variant of *-aarch64-apple-darwin

you might be on x86_64-apple-darwin and other things might work for some reason I'm unsure of but this might cause linker to confuse.

CyberHoward commented 11 months ago
stable-aarch64-apple-darwin (default)
rustc 1.72.0 (5680fa18f 2023-08-23)

Running the aarch toolchain.

iboss-ptk commented 11 months ago

Then how about

export GOOS="darwin"
export GOARCH="arm64"

(try cargo clean first just to be sure it rebuilds libosmosistesttube)

CyberHoward commented 11 months ago

Did that, now the osmosis-test-tube build fails:

error: failed to run custom build command for `osmosis-test-tube v19.0.0`
note: To improve backtraces for build dependencies, set the CARGO_PROFILE_TEST_BUILD_OVERRIDE_DEBUG=true environment variable to enable debug information generation.

Caused by:
  process didn't exit successfully: `abstract/modules/target/debug/build/osmosis-test-tube-066cc009cbc73844/build-script-build` (exit status: 101)
  --- stdout
  cargo:rerun-if-changed=./libosmosistesttube

  --- stderr
  go: no Go source files
  thread 'main' panicked at 'failed to build go code', /Users/robin/.cargo/registry/src/index.crates.io-6f17d22bba15001f/osmosis-test-tube-19.0.0/build.rs:114:9
  stack backtrace:
     0: rust_begin_unwind
               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/std/src/panicking.rs:593:5
     1: core::panicking::panic_fmt
               at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/core/src/panicking.rs:67:14
     2: build_script_build::build_libosmosistesttube
     3: build_script_build::main
     4: core::ops::function::FnOnce::call_once

Which is:

let exit_status = Command::new("go")
        .current_dir(manifest_dir.join("libosmosistesttube"))
        .arg("build")
        .arg("-buildmode=c-shared")
        .arg("-o")
        .arg(out)
        .arg("main.go")
        .spawn()
        .unwrap()
        .wait()
        .unwrap();

    if !exit_status.success() {
        panic!("failed to build go code"); // <--- This line
    }

Thanks for the help btw, happy to try some more suggestions.

Edit: will try cloning and building this repo locally

Edit 2: The output of the shell command that fails is:

Output { status: ExitStatus(unix_wait_status(256)), stdout: "", stderr: "go: no Go source files\n" 

Edit 3: A quick google search pointed out setting CGO_ENABLED=1. This allowed me to build the repo.

CyberHoward commented 11 months ago

In summary doing the following fixed the issue for me:

cargo clean
export GOOS="darwin"
export GOARCH="arm64"
export CGO_ENABLED=1

@JakeHartnell @njerschow @j0nl1 Mind trying it out and letting us know if it worked?

iboss-ptk commented 11 months ago

@CyberHoward Nice!

Out of curiosity, what's the output of your go version?

CyberHoward commented 11 months ago

@CyberHoward Nice!

Out of curiosity, what's the output of your go version?

go version go1.19.4 darwin/amd64

iboss-ptk commented 11 months ago

Oh, that's probably why. Mine is go1.20.4 darwin/arm64.

iboss-ptk commented 11 months ago

Screen Shot 2566-09-28 at 14 52 13 darwin/amd64 is for x86-64 arch

cfkelly18 commented 11 months ago

Same here with an M2 mac, im running go version go1.21.3 darwin/arm64. Haven't been able to resolve it even with @CyberHoward's fix above

JakeHartnell commented 11 months ago

Update, works for me with latest versions. Also running it in DAO DAO CI: https://github.com/DA0-DA0/dao-contracts/blob/95e4f73a170705deeb3689341c51f3a3b126e3e9/.github/workflows/test_tube.yml

iboss-ptk commented 4 months ago

OP issue is resolved, please open new issue if there is any similar one.