From 2bec9f862a68017181d4d214f505b621236d2327 Mon Sep 17 00:00:00 2001 From: mohanson Date: Tue, 20 Aug 2024 17:37:27 +0800 Subject: [PATCH 1/3] Add a sample for showing how to build binary with clang --- .gitignore | 1 + tests/programs/_build_clang.sh | 7 ++++++ tests/programs/_build_clang_native.sh | 27 +++++++++++++++++++++++ tests/programs/clang_sample | Bin 0 -> 8392 bytes tests/programs/clang_sample.c | 3 +++ tests/test_misc.rs | 30 ++++++++++++++++++++++++++ 6 files changed, 68 insertions(+) create mode 100644 tests/programs/_build_clang.sh create mode 100644 tests/programs/_build_clang_native.sh create mode 100755 tests/programs/clang_sample create mode 100644 tests/programs/clang_sample.c diff --git a/.gitignore b/.gitignore index 978349dd..7a23bd9e 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ Cargo.lock .deps/ /examples/is13 *.DS_Store +tests/programs/deps diff --git a/tests/programs/_build_clang.sh b/tests/programs/_build_clang.sh new file mode 100644 index 00000000..5d64e671 --- /dev/null +++ b/tests/programs/_build_clang.sh @@ -0,0 +1,7 @@ +set -ex + +DOCKER="${DOCKER:-docker}" +# docker pull docker.io/cryptape/llvm-n-rust:20240630 +DOCKER_IMAGE="${DOCKER_IMAGE:-docker.io/cryptape/llvm-n-rust@sha256:bafaf76d4f342a69b8691c08e77a330b7740631f3d1d9c9bee4ead521b29ee55}" + +$DOCKER run --rm -e UID=`id -u` -e GID=`id -g` $DOCKER_RUN_ARGS -v `pwd`:/code $DOCKER_IMAGE bash _build_clang_native.sh diff --git a/tests/programs/_build_clang_native.sh b/tests/programs/_build_clang_native.sh new file mode 100644 index 00000000..dfe10589 --- /dev/null +++ b/tests/programs/_build_clang_native.sh @@ -0,0 +1,27 @@ +set -ex + +ROOT_DIR=$(pwd) +CC="clang-18" +LD="ld.lld-18" +CCFLAGS="--target=riscv64 -march=rv64imac_zba_zbb_zbc_zbs -nostdinc -isystem $ROOT_DIR/deps/musl/release/include -c -fdata-sections -ffunction-sections" +LDFLAGS="--gc-sections -nostdlib --sysroot $ROOT_DIR/deps/musl/release -L$ROOT_DIR/deps/musl/release/lib -lc -lgcc" + +if [ ! -d deps ]; then + mkdir deps +fi + +if [ ! -d deps/musl ]; then + cd deps + git clone https://github.com/xxuejie/musl + cd musl + git checkout 603d5e9 + cd ../.. +fi + +if [ ! -d deps/musl/release ]; then + cd deps/musl + CLANG=$CC ./ckb/build.sh + cd - +fi + +$CC $CCFLAGS clang_sample.c -o clang_sample.o && $LD $LDFLAGS clang_sample.o -o clang_sample && rm clang_sample.o diff --git a/tests/programs/clang_sample b/tests/programs/clang_sample new file mode 100755 index 0000000000000000000000000000000000000000..9d523ae417e6e9fc5b35475a258847f46e22fdad GIT binary patch literal 8392 zcmbuE4RBP|y}le<|k+QcQGZHI}19d$m>u#eS&RCTKsVj@3v%-YWvBX^VzTiK3(C{m;4o zlWfjr-%Q6lvwP0{o&WiN-T%4w+}#H~o4poA0dZL1U%<{zWt*&m2C7$@9Y!ml9IW`g z6l~Z6q;qDDSMb?P#+?5jW&@(NnPPmD&6__+kmmK%sc0d~lw?@NkKp~}r)aNbm~x^` zoX33aSYnQMtTqjZmej*V;Rb=PO@!;%ynpvd188RPJx})J`5Op`R+v??tyl9VAxrUS z`6oZUR8v`}`no!ft^$a64u7&VdUWQ~*?3f)u#^rb6o~vP zdJNpBGhV8&_gtT~@46q_A71-??d;fK=ar~e>w9yMNyVel9}jzvOxvxkxA-27TeEWd z-!=T>prKzgFUHfOP=-==HTvijTyr=p5?>e^qg7j#=* zwyUqHahn@Pkac>M4V@d5>M3~1d8?;oI&OPS&5MRm``a(Nv#nRkn8zjL@mTbjD`Ti4 z-t+!!{2lJ^fL4BLu=8&!`a3%3?<#Nqv|Vkv#dpk({`R83qvY?ruQf}jU`UaD9jS3E zT^%A@1>Lr{F|y1lxcE7vO0{NBu=!DsmU-r>B_7)wmY3OiJbm<-T?H$Ph($Rc(a@cb zcn(j*vH0_OM7GyV`|9cHt9G?J1Qf>!&?XJ>db?xYP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*;@8gXCEu65ziCxKkwZC zxil{Jk8}#`Z(lZ_9;?`|F^d-6i=GZ-un~h zi{Jmm{IkrtghRG}JB~3C`4?F+e|5rK))neRn}-a2Z Date: Tue, 20 Aug 2024 17:41:58 +0800 Subject: [PATCH 2/3] CCFLAGS => CFLAGS --- tests/programs/_build_clang_native.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/programs/_build_clang_native.sh b/tests/programs/_build_clang_native.sh index dfe10589..2fda2995 100644 --- a/tests/programs/_build_clang_native.sh +++ b/tests/programs/_build_clang_native.sh @@ -3,7 +3,7 @@ set -ex ROOT_DIR=$(pwd) CC="clang-18" LD="ld.lld-18" -CCFLAGS="--target=riscv64 -march=rv64imac_zba_zbb_zbc_zbs -nostdinc -isystem $ROOT_DIR/deps/musl/release/include -c -fdata-sections -ffunction-sections" +CFLAGS="--target=riscv64 -march=rv64imac_zba_zbb_zbc_zbs -nostdinc -isystem $ROOT_DIR/deps/musl/release/include -c -fdata-sections -ffunction-sections" LDFLAGS="--gc-sections -nostdlib --sysroot $ROOT_DIR/deps/musl/release -L$ROOT_DIR/deps/musl/release/lib -lc -lgcc" if [ ! -d deps ]; then @@ -24,4 +24,4 @@ if [ ! -d deps/musl/release ]; then cd - fi -$CC $CCFLAGS clang_sample.c -o clang_sample.o && $LD $LDFLAGS clang_sample.o -o clang_sample && rm clang_sample.o +$CC $CFLAGS clang_sample.c -o clang_sample.o && $LD $LDFLAGS clang_sample.o -o clang_sample && rm clang_sample.o From d5e6d251ee0ab8ae748ba49ab96db1c7252427e4 Mon Sep 17 00:00:00 2001 From: mohanson Date: Wed, 21 Aug 2024 10:02:32 +0800 Subject: [PATCH 3/3] Using tweakable variables in bash script --- tests/programs/_build_clang_native.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/programs/_build_clang_native.sh b/tests/programs/_build_clang_native.sh index 2fda2995..b9d3dba0 100644 --- a/tests/programs/_build_clang_native.sh +++ b/tests/programs/_build_clang_native.sh @@ -1,8 +1,8 @@ set -ex ROOT_DIR=$(pwd) -CC="clang-18" -LD="ld.lld-18" +CLANG="${CLANG:-clang-18}" +LD="${CLANG/clang/ld.lld}" CFLAGS="--target=riscv64 -march=rv64imac_zba_zbb_zbc_zbs -nostdinc -isystem $ROOT_DIR/deps/musl/release/include -c -fdata-sections -ffunction-sections" LDFLAGS="--gc-sections -nostdlib --sysroot $ROOT_DIR/deps/musl/release -L$ROOT_DIR/deps/musl/release/lib -lc -lgcc" @@ -20,8 +20,8 @@ fi if [ ! -d deps/musl/release ]; then cd deps/musl - CLANG=$CC ./ckb/build.sh + CLANG=$CLANG ./ckb/build.sh cd - fi -$CC $CFLAGS clang_sample.c -o clang_sample.o && $LD $LDFLAGS clang_sample.o -o clang_sample && rm clang_sample.o +$CLANG $CFLAGS clang_sample.c -o clang_sample.o && $LD $LDFLAGS clang_sample.o -o clang_sample && rm clang_sample.o