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 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") {