forked from cryptape/ckb-auth
-
Notifications
You must be signed in to change notification settings - Fork 12
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
Support clang #9
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c1cd1ce
Update ckb-c-stdlib
joii2020 8ba3c6c
Format Makefile
joii2020 d664c1a
Support llvm
joii2020 69bb1ad
Add clang CI
joii2020 e7ed2d8
CI Install clang-16
joii2020 d1915a7
Fix CI about always_success
joii2020 2123db9
Revert Makfile modifications in this PR
joii2020 a9bd4b2
Handle Makefile.clang code as suggested
joii2020 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
|
||
name: Clang | ||
|
||
on: [push, pull_request] | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
submodules: recursive | ||
- name: Install llvm 16 | ||
run: sudo apt-get purge --auto-remove llvm python3-lldb-14 llvm-14 && wget https://apt.llvm.org/llvm.sh && chmod +x llvm.sh && sudo ./llvm.sh 16 | ||
- name: Install litecoin for tests | ||
run: | | ||
tarball=litecoin.tar.gz | ||
wget -O "$tarball" https://download.litecoin.org/litecoin-0.21.2.2/linux/litecoin-0.21.2.2-x86_64-linux-gnu.tar.gz | ||
tar xvzf "$tarball" | ||
sudo cp -r litecoin-*/* /usr/local/ | ||
litecoin-cli --help | ||
- name: Install monero wallet cli for tests | ||
run: | | ||
tarball=monero-wallet-cli.tar.gz | ||
wget -O "$tarball" https://downloads.getmonero.org/cli/monero-linux-x64-v0.18.2.2.tar.bz2 | ||
tar xvaf "$tarball" | ||
sudo cp -r monero-*/* /usr/local/bin/ | ||
monero-wallet-cli --help | ||
- name: Install solana cli for tests | ||
run: | | ||
tarball=solana-release-x86_64-unknown-linux-gnu.tar.bz2 | ||
wget -O "$tarball" https://github.com/solana-labs/solana/releases/download/v1.16.1/solana-release-x86_64-unknown-linux-gnu.tar.bz2 | ||
tar xvaf "$tarball" | ||
sudo cp -r solana-*/* /usr/local/ | ||
solana --help | ||
solana-keygen new --force --no-bip39-passphrase | ||
- name: Build contract with clang | ||
run: make -f Makefile.clang all | ||
- name: Build example with clang | ||
run: make -f examples/auth-demo/Makefile.clang all | ||
- name: Run auth_rust tests | ||
run: cd tests/auth_rust && cargo test | ||
- name: Install ckb-debugger | ||
run: cd tests/auth_spawn_rust && make install | ||
- name: Run auth_spawn_rust tests | ||
run: cd tests/auth_spawn_rust && make all | ||
- name: Install cardano tools | ||
run: cd tests/cardano_lock && make install_cardano_tools | ||
- name: Run cardano tests | ||
run: cd tests/cardano_lock && make all |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
CC := clang-16 | ||
LD := ld.lld-16 | ||
OBJCOPY := llvm-objcopy-16 | ||
AR := llvm-ar-16 | ||
RANLIB := llvm-ranlib-16 | ||
LLVM_CFLAGS := --target=riscv64 -march=rv64imc_zba_zbb_zbc_zbs \ | ||
-Wno-error=unused-but-set-variable \ | ||
-Wno-error=unused-command-line-argument \ | ||
-Wno-error=bitwise-instead-of-logical | ||
LLVM_AUTH_CFLAGS := -DCKB_NO_ENTRY_GP | ||
LDFLAGS := -static -Wl,--gc-sections | ||
AUTH_DYN_LIST := --dynamic-list c/auth.syms | ||
|
||
CFLAGS := -g -O3 -fPIC \ | ||
-Wall -Werror -Wno-nonnull -Wno-unused-function \ | ||
-fno-builtin-printf -fno-builtin-memcmp \ | ||
-nostdinc -nostdlib -fvisibility=hidden \ | ||
-fdata-sections -ffunction-sections \ | ||
$(GCC_CFLAGS) $(LLVM_CFLAGS) | ||
|
||
INCLUDE_SECP256K1_CFLAGS = \ | ||
-I deps/secp256k1-20210801/src -I deps/secp256k1-20210801 | ||
INCLUDE_CKB_STD_CFLAGS = \ | ||
-I deps/ckb-c-stdlib-2023 -I deps/ckb-c-stdlib-2023/libc -I deps/ckb-c-stdlib-2023/molecule | ||
INCLUDE_CFLAGS := $(INCLUDE_SECP256K1_CFLAGS) $(INCLUDE_CKB_STD_CFLAGS) \ | ||
-I c -I build -I deps/mbedtls/include -I deps/ed25519/src -I c/cardano/nanocbor | ||
|
||
AUTH_CFLAGS := $(CFLAGS) $(INCLUDE_CFLAGS) -Wno-array-bounds | ||
PASSED_MBEDTLS_CFLAGS := $(CFLAGS) -DCKB_DECLARATION_ONLY -I ../../ckb-c-stdlib-2023/libc | ||
|
||
SECP256K1_SRC_20210801 := deps/secp256k1-20210801/src/ecmult_static_pre_context.h | ||
|
||
CFLAGS_LIBECC := $(CFLAGS) \ | ||
-DUSER_NN_BIT_LEN=256 -DWORDSIZE=64 -DWITH_STDLIB -DWITH_CKB -DCKB_DECLARATION_ONLY \ | ||
-Wno-unused-variable | ||
LIBECC_OPTIMIZED_PATH := deps/libecc | ||
LIBECC_OPTIMIZED_FILES := \ | ||
${LIBECC_OPTIMIZED_PATH}/build/libarith.a \ | ||
${LIBECC_OPTIMIZED_PATH}/build/libec.a \ | ||
${LIBECC_OPTIMIZED_PATH}/build/libsign.a | ||
CFLAGS_LIBECC_OPTIMIZED = \ | ||
-I ../ckb-c-stdlib-2023 \ | ||
-I ../ckb-c-stdlib-2023/libc \ | ||
-I ../ckb-c-stdlib-2023/molecule \ | ||
$(CFLAGS_LIBECC) \ | ||
-DWITH_LL_U256_MONT | ||
CFLAGS_LINK_TO_LIBECC_OPTIMIZED := \ | ||
-DWORDSIZE=64 -DWITH_STDLIB -DWITH_CKB \ | ||
-I ${LIBECC_OPTIMIZED_PATH}/src -I ${LIBECC_OPTIMIZED_PATH}/src/external_deps | ||
|
||
all: \ | ||
build/secp256k1_data_info_20210801.h \ | ||
$(SECP256K1_SRC_20210801) \ | ||
deps/mbedtls/library/libmbedcrypto.a \ | ||
build/auth_libecc \ | ||
build/auth \ | ||
build/always_success | ||
|
||
build/always_success: c/always_success.c | ||
$(CC) $(AUTH_CFLAGS) $(LDFLAGS) -o $@ $< | ||
$(OBJCOPY) --only-keep-debug $@ $@.debug | ||
$(OBJCOPY) --strip-debug --strip-all $@ | ||
|
||
build/secp256k1_data_info_20210801.h: build/dump_secp256k1_data_20210801 | ||
$< | ||
|
||
build/dump_secp256k1_data_20210801: c/dump_secp256k1_data_20210801.c $(SECP256K1_SRC_20210801) | ||
mkdir -p build | ||
gcc -I deps/ckb-c-stdlib-2023 -I deps/secp256k1-20210801/src -I deps/secp256k1-20210801 -o $@ $< | ||
|
||
$(SECP256K1_SRC_20210801): | ||
cd deps/secp256k1-20210801 && \ | ||
./autogen.sh && \ | ||
CC=$(CC) LD=$(LD) ./configure --with-bignum=no --with-asm=no \ | ||
--enable-ecmult-static-precomputation --enable-endomorphism --enable-module-recovery \ | ||
&& \ | ||
make src/ecmult_static_pre_context.h src/ecmult_static_context.h | ||
|
||
$(LIBECC_OPTIMIZED_FILES): libecc | ||
|
||
libecc: | ||
make -C ${LIBECC_OPTIMIZED_PATH} LIBECC_WITH_LL_U256_MONT=1 \ | ||
CC=${CC} LD=${LD} AR=$(AR) RANLIB=$(RANLIB) CFLAGS="$(CFLAGS_LIBECC_OPTIMIZED)" | ||
|
||
deps/mbedtls/library/libmbedcrypto.a: | ||
cp deps/mbedtls-config-template.h deps/mbedtls/include/mbedtls/config.h | ||
make -C deps/mbedtls/library \ | ||
APPLE_BUILD=0 AR=$(AR) CC=${CC} LD=${LD} CFLAGS="${PASSED_MBEDTLS_CFLAGS}" \ | ||
libmbedcrypto.a | ||
|
||
build/nanocbor/%.o: c/cardano/nanocbor/%.c | ||
mkdir -p build/nanocbor | ||
$(CC) -c -DCKB_DECLARATION_ONLY -I c/cardano -I c/cardano/nanocbor $(AUTH_CFLAGS) -o $@ $^ | ||
build/libnanocbor.a: build/nanocbor/encoder.o build/nanocbor/decoder.o | ||
$(AR) cr $@ $^ | ||
build/ed25519/%.o: deps/ed25519/src/%.c | ||
mkdir -p build/ed25519 | ||
$(CC) -c -DCKB_DECLARATION_ONLY $(AUTH_CFLAGS) -o $@ $^ | ||
build/libed25519.a: \ | ||
build/ed25519/sign.o \ | ||
build/ed25519/verify.o \ | ||
build/ed25519/sha512.o \ | ||
build/ed25519/sc.o \ | ||
build/ed25519/keypair.o \ | ||
build/ed25519/key_exchange.o \ | ||
build/ed25519/ge.o \ | ||
build/ed25519/fe.o \ | ||
build/ed25519/add_scalar.o | ||
$(AR) cr $@ $^ | ||
|
||
build/auth: \ | ||
c/auth.c \ | ||
c/cardano/cardano_lock_inc.h \ | ||
c/ripple.h \ | ||
deps/mbedtls/library/libmbedcrypto.a \ | ||
build/libed25519.a \ | ||
build/libnanocbor.a | ||
$(CC) $(AUTH_CFLAGS) $(LLVM_AUTH_CFLAGS) -c -o $@.o c/auth.c | ||
$(LD) --shared --gc-sections $(AUTH_DYN_LIST) \ | ||
-o $@ \ | ||
$@.o \ | ||
deps/mbedtls/library/libmbedcrypto.a \ | ||
build/libed25519.a \ | ||
build/libnanocbor.a | ||
cp $@ $@.debug | ||
$(OBJCOPY) --strip-debug --strip-all $@ | ||
ls -lh $@ | ||
|
||
build/auth_libecc: c/auth_libecc.c $(LIBECC_OPTIMIZED_FILES) | ||
$(CC) $(AUTH_CFLAGS) $(LLVM_AUTH_CFLAGS) $(CFLAGS_LINK_TO_LIBECC_OPTIMIZED) -c -o $@.o c/auth_libecc.c | ||
$(LD) --shared --gc-sections $(AUTH_DYN_LIST) \ | ||
-o $@ \ | ||
$@.o \ | ||
$(LIBECC_OPTIMIZED_FILES) | ||
cp $@ $@.debug | ||
$(OBJCOPY) --strip-debug --strip-all $@ | ||
ls -lh $@ | ||
|
||
fmt: | ||
clang-format -i -style="{BasedOnStyle: Google, IndentWidth: 4}" c/*.c c/*.h | ||
|
||
clean: | ||
rm -rf build/*.debug | ||
rm -f build/auth build/auth_libecc build/auth_demo | ||
rm -rf build/secp256k1_data_info_20210801.h build/dump_secp256k1_data_20210801 | ||
rm -rf build/ed25519 build/libed25519.a build/nanocbor build/libnanocbor.a | ||
cd deps/secp256k1-20210801 && [ -f "Makefile" ] && make clean | ||
make -C deps/mbedtls/library clean | ||
make -C deps/libecc clean | ||
|
||
.PHONY: all | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule ckb-c-stdlib-2023
updated
3 files
+1 −1 | ckb_consts.h | |
+5 −4 | ckb_dlfcn.h | |
+2 −3 | ckb_syscalls.h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
CC := clang-16 | ||
LD := ld.lld-16 | ||
OBJCOPY := llvm-objcopy-16 | ||
AR := llvm-ar-16 | ||
RANLIB := llvm-ranlib-16 | ||
LLVM_CFLAGS := --target=riscv64 -march=rv64imc_zba_zbb_zbc_zbs \ | ||
-Wno-error=unused-but-set-variable \ | ||
-Wno-error=unused-command-line-argument \ | ||
-Wno-error=bitwise-instead-of-logical | ||
|
||
CFLAGS := $(LLVM_CFLAGS) $(GCC_CFLAGS) \ | ||
-O3 -g -Wall -Werror -Wno-nonnull -Wno-unused-function \ | ||
-fno-builtin-printf -fno-builtin-memcmp \ | ||
-nostdinc -nostdlib -fvisibility=hidden -fdata-sections -ffunction-sections \ | ||
-I deps/secp256k1/src -I deps/secp256k1 \ | ||
-I deps/ckb-c-std-lib -I deps/ckb-c-std-lib/libc \ | ||
-I deps/ckb-c-std-lib/molecule \ | ||
-I c \ | ||
-I build | ||
LDFLAGS := -Wl,-static -Wl,--gc-sections | ||
AUTH_CFLAGS=$(subst ckb-c-std-lib,ckb-c-stdlib-2023,$(CFLAGS)) -Wno-array-bounds | ||
|
||
all: build/auth_demo | ||
|
||
build/auth_demo: examples/auth-demo/auth_demo.c c/ckb_auth.h | ||
$(CC) $(AUTH_CFLAGS) $(LDFLAGS) -o $@ examples/auth-demo/auth_demo.c | ||
$(OBJCOPY) --only-keep-debug $@ $@.debug | ||
$(OBJCOPY) --strip-debug --strip-all $@ | ||
|
||
clean: | ||
rm -rf build/auth_demo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use
?=
instead of:=
. Give a chance to setCC
from environment.