nervosnetwork / capsule

Capsule is an out-of-box development framework for creating smart contract on Nervos' CKB.
MIT License
60 stars 34 forks source link

Should not load x86 docker images for cross #130

Closed duanyytop closed 1 year ago

duanyytop commented 1 year ago

Bug description

Should not load x86 docker images for cross

> cross build -p joyid-lock --release
Unable to find image 'ghcr.io/cross-rs/x86_64-unknown-linux-gnu:main' locally
main: Pulling from cross-rs/x86_64-unknown-linux-gnu
edaedc954fb5: Pull complete 
c6077a2cc41a: Pull complete 
50ab2986c99f: Pull complete 
678ffa738a4e: Pull complete 
b421ee7848df: Pull complete 
484a764f3dc4: Pull complete 
67e6443952a5: Pull complete 
5dc94db61e37: Pull complete 
144f8786ac8f: Pull complete 
80ac8dae6b94: Pull complete 
dc4eb81c27c0: Pull complete 
e4679d20334d: Pull complete 
3ce4ce3641cc: Pull complete 
fef558c2d27d: Pull complete 
Digest: sha256:079d0fb10d7fb863e743fbd20876c91177209f812dd7f463c2a2b85b5059fd43
Status: Downloaded newer image for ghcr.io/cross-rs/x86_64-unknown-linux-gnu:main
   Compiling ckb-lib-rsa v0.1.0 (/home/dylan/ckb/contracts/joyid-contract/ckb-lib-rsa)
   Compiling ckb-lib-secp256k1 v0.1.0 (/home/dylan/ckb/contracts/joyid-contract/ckb-lib-secp256k1)
   Compiling ckb-lib-smt v0.1.0 (/home/dylan/ckb/contracts/joyid-contract/ckb-lib-smt)
   Compiling ckb-lib-secp256r1 v0.1.0 (/home/dylan/ckb/contracts/joyid-contract/ckb-lib-secp256r1)
error[E0432]: unresolved import `ckb_std::dynamic_loading_c_impl`
 --> ckb-lib-secp256r1/src/libsecp256r1.rs:2:14
  |
2 | use ckb_std::dynamic_loading_c_impl::{CKBDLContext, Symbol};
  |              ^^^^^^^^^^^^^^^^^^^^^^ could not find `dynamic_loading_c_impl` in `ckb_std`

error[E0432]: unresolved import `ckb_std::dynamic_loading_c_impl`

The suggestion from xjd is adding Cross.toml file and upgrading ckb-std:

> cat Cross.toml
[build]
default-target = "riscv64imac-unknown-none-elf"

[target.riscv64imac-unknown-none-elf]
image = "nervos/ckb-riscv-gnu-toolchain:focal-20230214"

Environment

capsule --version
Capsule 0.10.1

ckb-cli --version
ckb-cli 1.4.0 (31c858e 2023-07-18)
blckngm commented 1 year ago

How is your project structured? You may try some alternative ways to configure cross: https://github.com/cross-rs/cross#configuration

XuJiandong commented 1 year ago

This issue occurs when the project is incorrectly migrated, with the Cross.toml file missing in the migration process. I believe it would be beneficial to include a checking mechanism in the capsule to detect the presence of the Cross.toml file.

duanyytop commented 1 year ago

Any updates? Do we need to do additional cross configuration separately?

I guess this error occurs when using capsule v0.10.1 and the contract depends on the dynamic link library? Maybe you guys can try.

blckngm commented 1 year ago

How is your project structured? Is there a cargo workspace in the root directory like the template? In which directory did you run capsule build or cross build?

XuJiandong commented 1 year ago

Any updates? Do we need to do additional cross configuration separately?

I guess this error occurs when using capsule v0.10.1 and the contract depends on the dynamic link library? Maybe you guys can try.

Your project was incorrectly migrated. That's why the cross.toml is missing.

duanyytop commented 1 year ago

How is your project structured? Is there a cargo workspace in the root directory like the template? In which directory did you run capsule build or cross build?

ll
total 128K
drwxrwxr-x  3 dylan dylan 4.0K Jul 28 17:25 build
drwxrwxr-x  4 dylan dylan 4.0K Jul 28 16:36 c
-rw-rw-r--  1 dylan dylan  108 Aug 21 13:45 capsule.toml
-rw-rw-r--  1 dylan dylan  49K Aug 21 17:19 Cargo.lock
-rw-rw-r--  1 dylan dylan  231 Jul 31 09:31 Cargo.toml
drwxrwxr-x  3 dylan dylan 4.0K Jul 28 16:36 ckb-lib-rsa
drwxrwxr-x  3 dylan dylan 4.0K Jul 28 16:36 ckb-lib-secp256k1
drwxrwxr-x  3 dylan dylan 4.0K Jul 28 16:36 ckb-lib-secp256r1
drwxrwxr-x  3 dylan dylan 4.0K Jul 28 16:36 ckb-lib-smt
drwxrwxr-x 11 dylan dylan 4.0K Jul 28 17:40 ckb-miscellaneous-scripts
drwxrwxr-x 10 dylan dylan 4.0K Jul 28 16:36 ckb-production-scripts
drwxrwxr-x  3 dylan dylan 4.0K Jul 28 16:36 contracts
-rw-rw-r--  1 dylan dylan  590 Jul 28 16:36 deployment.toml
-rw-rw-r--  1 dylan dylan  427 Jul 28 16:36 Makefile
drwxrwxr-x  2 dylan dylan 4.0K Jul 28 16:36 migrations
-rw-rw-r--  1 dylan dylan  468 Jul 28 16:36 README.md
-rw-rw-r--  1 dylan dylan  291 Jul 28 16:36 rustfmt.toml
-rw-rw-r--  1 dylan dylan   18 Aug 21 17:25 rust-toolchain
drwxrwxr-x  4 dylan dylan 4.0K Aug 21 17:45 target
drwxrwxr-x  3 dylan dylan 4.0K Aug 11 09:27 tests

And the root Cargo.toml is as below:

[workspace]
members = ["tests", "contracts/joyid-lock", "ckb-lib-secp256r1", "ckb-lib-smt", "ckb-lib-secp256k1", "ckb-lib-rsa"]

I run capsule build in root directory

duanyytop commented 1 year ago

Any updates? Do we need to do additional cross configuration separately? I guess this error occurs when using capsule v0.10.1 and the contract depends on the dynamic link library? Maybe you guys can try.

Your project was incorrectly migrated. That's why the cross.toml is missing.

Do I need to add Cross.toml to my project? Or does the capsule handle the absence of Cross.toml ?

blckngm commented 1 year ago

You do need to add the Cross.toml file in the project root. Does it work when the file exists?

blckngm commented 1 year ago

See also https://github.com/nervosnetwork/capsule/wiki/Upgrade-an-existing-project-to-capsule-0.10

duanyytop commented 1 year ago

The issue is fixed by adding Cross.toml to root directory, but the other issue occurs and the log is as below:

The ckb-std version is v0.14.2 for all sub modules except for ckb-production-scripts whose ckb-std version is v0.7.3

capsule build --release
Building contract joyid-lock
RUSTFLAGS=--remap-path-prefix=/home/dylan=~ --remap-path-prefix=/home/dylan/ckb/contracts/joyid-contract=
$ cross build -p joyid-lock --release
   Compiling ckb-std v0.10.0
   Compiling ckb-lib-rsa v0.1.0 (/home/dylan/ckb/contracts/joyid-contract/ckb-lib-rsa)
   Compiling ckb-lib-smt v0.1.0 (/home/dylan/ckb/contracts/joyid-contract/ckb-lib-smt)
   Compiling ckb-lib-secp256k1 v0.1.0 (/home/dylan/ckb/contracts/joyid-contract/ckb-lib-secp256k1)
   Compiling ckb-lib-secp256r1 v0.1.0 (/home/dylan/ckb/contracts/joyid-contract/ckb-lib-secp256r1)
The following warnings were emitted during compilation:

warning: In file included from dl-c-impl/ckb-c-stdlib/libc/entry.h:5,
warning:                  from dl-c-impl/ckb-c-stdlib/libc/stddef.h:6,
warning:                  from dl-c-impl/ckb-c-stdlib/ckb_syscalls.h:4,
warning:                  from dl-c-impl/ckb-c-stdlib/ckb_dlfcn.h:4,
warning:                  from dl-c-impl/lib.c:5:
warning: dl-c-impl/ckb-c-stdlib/libc/src/impl.c: In function 'cycle':
warning: dl-c-impl/ckb-c-stdlib/libc/src/impl.c:391:9: error: storing the address of local variable 'tmp' in '*ar_32(D) + _2' [-Werror=dangling-pointer=]
warning:   391 |   ar[n] = tmp;
warning:       |   ~~~~~~^~~~~
warning: dl-c-impl/ckb-c-stdlib/libc/src/impl.c:383:17: note: 'tmp' declared here
warning:   383 |   unsigned char tmp[256];
warning:       |                 ^~~
warning: dl-c-impl/ckb-c-stdlib/libc/src/impl.c:383:17: note: 'ar' declared here
warning: cc1: all warnings being treated as errors

error: failed to run custom build command for `ckb-std v0.10.0`

Caused by:
  process didn't exit successfully: `/target/release/build/ckb-std-a905efdb213178f3/build-script-build` (exit status: 1)
  --- stdout
  TARGET = Some("riscv64imac-unknown-none-elf")
  OPT_LEVEL = Some("s")
  HOST = Some("x86_64-unknown-linux-gnu")
  cargo:rerun-if-env-changed=CC_riscv64imac-unknown-none-elf
  CC_riscv64imac-unknown-none-elf = None
  cargo:rerun-if-env-changed=CC_riscv64imac_unknown_none_elf
  CC_riscv64imac_unknown_none_elf = None
  cargo:rerun-if-env-changed=TARGET_CC
  TARGET_CC = None
  cargo:rerun-if-env-changed=CC
  CC = None
  RUSTC_LINKER = None
  cargo:rerun-if-env-changed=CROSS_COMPILE
  CROSS_COMPILE = None
  cargo:rerun-if-env-changed=CFLAGS_riscv64imac-unknown-none-elf
  CFLAGS_riscv64imac-unknown-none-elf = None
  cargo:rerun-if-env-changed=CFLAGS_riscv64imac_unknown_none_elf
  CFLAGS_riscv64imac_unknown_none_elf = None
  cargo:rerun-if-env-changed=TARGET_CFLAGS
  TARGET_CFLAGS = None
  cargo:rerun-if-env-changed=CFLAGS
  CFLAGS = None
  cargo:rerun-if-env-changed=CRATE_CC_NO_DEFAULTS
  CRATE_CC_NO_DEFAULTS = None
  DEBUG = Some("false")
  CARGO_CFG_TARGET_FEATURE = Some("a,c,m")
  running: "riscv64-unknown-elf-gcc" "-Os" "-ffunction-sections" "-fdata-sections" "-march=rv64imac" "-mabi=lp64" "-mcmodel=medany" "-Wall" "-Wextra" "-o" "/target/riscv64imac-unknown-none-elf/release/build/ckb-std-7f8999f73c4cf9f5/out/src/asm/syscall.o" "-c" "src/asm/syscall.S"
  exit status: 0
  cargo:rerun-if-env-changed=AR_riscv64imac-unknown-none-elf
  AR_riscv64imac-unknown-none-elf = None
  cargo:rerun-if-env-changed=AR_riscv64imac_unknown_none_elf
  AR_riscv64imac_unknown_none_elf = None
  cargo:rerun-if-env-changed=TARGET_AR
  TARGET_AR = None
  cargo:rerun-if-env-changed=AR
  AR = None
  running: ZERO_AR_DATE="1" "riscv64-unknown-elf-ar" "cq" "/target/riscv64imac-unknown-none-elf/release/build/ckb-std-7f8999f73c4cf9f5/out/libckb-syscall.a" "/target/riscv64imac-unknown-none-elf/release/build/ckb-std-7f8999f73c4cf9f5/out/src/asm/syscall.o"
  exit status: 0
  running: "riscv64-unknown-elf-ar" "s" "/target/riscv64imac-unknown-none-elf/release/build/ckb-std-7f8999f73c4cf9f5/out/libckb-syscall.a"
  exit status: 0
  cargo:rustc-link-lib=static=ckb-syscall
  cargo:rustc-link-search=native=/target/riscv64imac-unknown-none-elf/release/build/ckb-std-7f8999f73c4cf9f5/out
  TARGET = Some("riscv64imac-unknown-none-elf")
  OPT_LEVEL = Some("s")
  HOST = Some("x86_64-unknown-linux-gnu")
  cargo:rerun-if-env-changed=CC_riscv64imac-unknown-none-elf
  CC_riscv64imac-unknown-none-elf = None
  cargo:rerun-if-env-changed=CC_riscv64imac_unknown_none_elf
  CC_riscv64imac_unknown_none_elf = None
  cargo:rerun-if-env-changed=TARGET_CC
  TARGET_CC = None
  cargo:rerun-if-env-changed=CC
  CC = None
  RUSTC_LINKER = None
  cargo:rerun-if-env-changed=CROSS_COMPILE
  CROSS_COMPILE = None
  cargo:rerun-if-env-changed=CFLAGS_riscv64imac-unknown-none-elf
  CFLAGS_riscv64imac-unknown-none-elf = None
  cargo:rerun-if-env-changed=CFLAGS_riscv64imac_unknown_none_elf
  CFLAGS_riscv64imac_unknown_none_elf = None
  cargo:rerun-if-env-changed=TARGET_CFLAGS
  TARGET_CFLAGS = None
  cargo:rerun-if-env-changed=CFLAGS
  CFLAGS = None
  cargo:rerun-if-env-changed=CRATE_CC_NO_DEFAULTS
  CRATE_CC_NO_DEFAULTS = None
  DEBUG = Some("false")
  running: "riscv64-unknown-elf-gcc" "-Os" "-ffunction-sections" "-fdata-sections" "-march=rv64imac" "-mabi=lp64" "-mcmodel=medany" "-static" "-I" "dl-c-impl/ckb-c-stdlib" "-I" "dl-c-impl/ckb-c-stdlib/libc" "-Wall" "-Wextra" "-O3" "-fno-builtin-printf" "-fno-builtin-memcmp" "-nostdinc" "-nostdlib" "-fvisibility=hidden" "-fdata-sections" "-ffunction-sections" "-Wall" "-Werror" "-Wno-unused-parameter" "-Wno-nonnull" "-Wno-nonnull-compare" "-nostartfiles" "-D__SHARED_LIBRARY__" "-o" "/target/riscv64imac-unknown-none-elf/release/build/ckb-std-7f8999f73c4cf9f5/out/dl-c-impl/lib.o" "-c" "dl-c-impl/lib.c"
  cargo:warning=In file included from dl-c-impl/ckb-c-stdlib/libc/entry.h:5,
  cargo:warning=                 from dl-c-impl/ckb-c-stdlib/libc/stddef.h:6,
  cargo:warning=                 from dl-c-impl/ckb-c-stdlib/ckb_syscalls.h:4,
  cargo:warning=                 from dl-c-impl/ckb-c-stdlib/ckb_dlfcn.h:4,
  cargo:warning=                 from dl-c-impl/lib.c:5:
  cargo:warning=dl-c-impl/ckb-c-stdlib/libc/src/impl.c: In function 'cycle':
  cargo:warning=dl-c-impl/ckb-c-stdlib/libc/src/impl.c:391:9: error: storing the address of local variable 'tmp' in '*ar_32(D) + _2' [-Werror=dangling-pointer=]
  cargo:warning=  391 |   ar[n] = tmp;
  cargo:warning=      |   ~~~~~~^~~~~
  cargo:warning=dl-c-impl/ckb-c-stdlib/libc/src/impl.c:383:17: note: 'tmp' declared here
  cargo:warning=  383 |   unsigned char tmp[256];
  cargo:warning=      |                 ^~~
  cargo:warning=dl-c-impl/ckb-c-stdlib/libc/src/impl.c:383:17: note: 'ar' declared here
  cargo:warning=cc1: all warnings being treated as errors
  exit status: 1

  --- stderr

  error occurred: Command "riscv64-unknown-elf-gcc" "-Os" "-ffunction-sections" "-fdata-sections" "-march=rv64imac" "-mabi=lp64" "-mcmodel=medany" "-static" "-I" "dl-c-impl/ckb-c-stdlib" "-I" "dl-c-impl/ckb-c-stdlib/libc" "-Wall" "-Wextra" "-O3" "-fno-builtin-printf" "-fno-builtin-memcmp" "-nostdinc" "-nostdlib" "-fvisibility=hidden" "-fdata-sections" "-ffunction-sections" "-Wall" "-Werror" "-Wno-unused-parameter" "-Wno-nonnull" "-Wno-nonnull-compare" "-nostartfiles" "-D__SHARED_LIBRARY__" "-o" "/target/riscv64imac-unknown-none-elf/release/build/ckb-std-7f8999f73c4cf9f5/out/dl-c-impl/lib.o" "-c" "dl-c-impl/lib.c" with args "riscv64-unknown-elf-gcc" did not execute successfully (status code exit status: 1).

error: command exited with non-zero code `cross build -p joyid-lock --release`: 101
make: *** [Makefile:7: build-release] Error 255
duanyytop commented 1 year ago

Thanks a lot. All issues are fixed and I will close the issues