From f87171b0bdc899ed6c340ab28a9b67dc560f6bb9 Mon Sep 17 00:00:00 2001 From: Xuejie Xiao Date: Wed, 23 Aug 2023 03:19:29 +0000 Subject: [PATCH 1/2] Add new feature to allow building ckb-std using clang as C compiler --- Cargo.toml | 1 + build.rs | 28 ++++++++++++++++++++++------ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index b413a4e..66740cd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,6 +21,7 @@ calc-hash = ["ckb-types/calc-hash"] allocator = ["buddy-alloc"] simulator = ["ckb-x64-simulator"] dlopen-c = [] +build-with-clang = [] dummy-libc = [] rustc-dep-of-std = [ "alloc", diff --git a/build.rs b/build.rs index f43983a..b4a55c6 100644 --- a/build.rs +++ b/build.rs @@ -7,7 +7,8 @@ fn main() { // ckb-std only supports riscv64 target arch // but we can still use cargo check under other archs if target_arch == "riscv64" && cfg!(feature = "dlopen-c") { - cc::Build::new() + let mut build = cc::Build::new(); + build .file("dl-c-impl/lib.c") .static_flag(true) .flag("-O3") @@ -24,11 +25,26 @@ fn main() { .flag("-Werror") .flag("-Wno-unused-parameter") .flag("-Wno-nonnull") - .define("__SHARED_LIBRARY__", None) - .flag("-Wno-nonnull-compare") - .flag("-nostartfiles") - .flag("-Wno-dangling-pointer") - .compile("dl-c-impl"); + .define("__SHARED_LIBRARY__", None); + + if cfg!(feature = "build-with-clang") { + let clang = match std::env::var_os("CLANG") { + Some(val) => val, + None => "clang-16".into(), + }; + + build + .compiler(clang) + .no_default_flags(true) + .flag("--target=riscv64") + .flag("-march=rv64imc_zba_zbb_zbc_zbs"); + } else { + build + .flag("-nostartfiles") + .flag("-Wno-dangling-pointer") + .flag("-Wno-nonnull-compare"); + } + build.compile("dl-c-impl"); } if target_arch == "riscv64" && target_os == "ckb" && cfg!(feature = "dummy-libc") { From 693deb0ad225153f48ac3b66b2022fc0e375ff67 Mon Sep 17 00:00:00 2001 From: Xuejie Xiao Date: Wed, 23 Aug 2023 03:26:11 +0000 Subject: [PATCH 2/2] Add new github action to test building with clang --- .github/workflows/build-with-clang.yml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 .github/workflows/build-with-clang.yml diff --git a/.github/workflows/build-with-clang.yml b/.github/workflows/build-with-clang.yml new file mode 100644 index 0000000..7eda12c --- /dev/null +++ b/.github/workflows/build-with-clang.yml @@ -0,0 +1,19 @@ +name: Build with clang + +on: [push, pull_request] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + with: + submodules: true + - name: Install llvm 16 + run: wget https://apt.llvm.org/llvm.sh && chmod +x llvm.sh && sudo ./llvm.sh 16 && rm llvm.sh + - name: Install riscv64 target + run: rustup target add riscv64imac-unknown-none-elf + - name: Build + run: cargo build --verbose --target=riscv64imac-unknown-none-elf --features=build-with-clang