Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new feature to allow building ckb-std using clang as C compiler #67

Merged
merged 2 commits into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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