Concordium / concordium-rust-smart-contracts

Libraries and tools for writing and testing smart contracts on Concordium
https://docs.rs/concordium-std/latest/concordium_std/
Mozilla Public License 2.0
58 stars 35 forks source link

Fix linking error when using concordium_dbg! #389

Closed Bargsteen closed 10 months ago

Bargsteen commented 10 months ago

Purpose

Fix a linking error when using concordium_dbg! (see https://github.com/Concordium/concordium-rust-smart-contracts/pull/374 for more details on the debug functionality).

When running cargo concordium test --out concordium-out/module.wasm.v1 --allow-debug in the icecream example, I get the following error:

error: linking with `cc` failed: exit status: 1
  |
  = note: LC_ALL="C" PATH="/Users/kasper/.rustup/toolchains/1.72-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/bin
...
s/kasper/.rustup/toolchains/1.72-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/lib" "-o" "/Users/kasper/Developer/Concordium/rust-contracts/examples/fib/target/debug/deps/libfib.dylib" "-Wl,-dead_strip" "-dynamiclib" "-Wl,-dylib" "-nodefaultlibs"
  = note: Undefined symbols for architecture arm64:
            "_debug_print", referenced from:
                concordium_std::debug_print::h1f7e449ccf275907 in libconcordium_std-66bba2a1e91b6971.rlib(concordium_std-66bba2a1e91b6971.15091wxt0levty95.rcgu.o)
          ld: symbol(s) not found for architecture arm64
          clang: error: linker command failed with exit code 1 (use -v to see invocation)

error: could not compile `fib` (lib) due to previous error
Error: Could not build and run integration tests.

The issue is resolved by adding the debug_print dummy host function. I also added the two other methods that were missing. I assume they might cause a similar error if they were triggered.

My initial guess was that the issue only occurred if the tests.rs file imported the lib.rs file, which has the concordium_dbg! calls, but that is not the case; the error also occurs if the smart contract isn't imported in the tests.

Since this hasn't been caught yet, it might only be an issue on macOS.

Changes

Checklist