Skip to content

Commit

Permalink
Merge pull request #67 from xxuejie/build-with-clang
Browse files Browse the repository at this point in the history
Add new feature to allow building ckb-std using clang as C compiler
  • Loading branch information
xxuejie authored Aug 23, 2023
2 parents 11da8e3 + 693deb0 commit 4d2c5b5
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 6 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/build-with-clang.yml
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
28 changes: 22 additions & 6 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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") {
Expand Down

0 comments on commit 4d2c5b5

Please sign in to comment.