Skip to content

Commit

Permalink
Rebuild with musl and llvm-18 (#12)
Browse files Browse the repository at this point in the history
* Update to llvm-18
* Rebuild with musl
* Update ckb-c-stdlib
* Update compiler-rt-builtins-riscv
  • Loading branch information
mohanson authored Sep 11, 2024
1 parent fe6e580 commit 34210cb
Show file tree
Hide file tree
Showing 58 changed files with 844 additions and 8,998 deletions.
19 changes: 12 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
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 llvm 18
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 18
rm llvm.sh
- name: Build
run: make all
- name: Install tools
Expand All @@ -20,15 +25,15 @@ jobs:
run: make test
- name: Benchmark
run: make benchmark

macos:
runs-on: macos-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Install LLVM and Clang
run: brew install llvm@16
run: brew install llvm@18
- name: Build
run: export PATH="/usr/local/opt/llvm@16/bin:$PATH" && make all
run: export PATH="/opt/homebrew/opt/llvm/bin:$PATH" && make all
7 changes: 5 additions & 2 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@

[submodule "deps/ckb-c-stdlib"]
path = deps/ckb-c-stdlib
url = https://github.com/nervosnetwork/ckb-c-stdlib.git
[submodule "deps/compiler-rt-builtins-riscv"]
path = deps/compiler-rt-builtins-riscv
url = https://github.com/nervosnetwork/compiler-rt-builtins-riscv.git
url = https://github.com/nervosnetwork/compiler-rt-builtins-riscv
branch = update
[submodule "deps/musl"]
path = deps/musl
url = https://github.com/xxuejie/musl
56 changes: 26 additions & 30 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,59 +1,63 @@

CC := clang-16
LD := ld.lld-16
OBJCOPY := llvm-objcopy-16
AR := llvm-ar-16
RANLIB := llvm-ranlib-16
CC := clang-18
LD := ld.lld-18
AR := llvm-ar-18
OBJCOPY := llvm-objcopy-18
RANLIB := llvm-ranlib-18

UNAME := $(shell uname)
ifeq ($(UNAME), Darwin)
CC := clang
LD := ld.lld
AR := llvm-ar
OBJCOPY := llvm-objcopy
RANLIB := llvm-ranlib
endif

CFLAGS := --target=riscv64 -march=rv64imc_zba_zbb_zbc_zbs
CFLAGS += -g -Os \
-Wall -Werror -Wno-nonnull -Wno-unused-function \
-fno-builtin-printf -fno-builtin-memcmp \
-nostdinc -nostdlib\
-nostdinc -nostdlib \
-fdata-sections -ffunction-sections

CFLAGS += -I deps/ckb-c-stdlib/libc -I deps/ckb-c-stdlib
CFLAGS += -I deps/ckb-c-stdlib
CFLAGS += -I include -I include/c-stdlib
CFLAGS += -I deps/compiler-rt-builtins-riscv/compiler-rt/lib/builtins

CFLAGS += -Wextra -Wno-sign-compare -Wno-missing-field-initializers -Wundef -Wuninitialized\
-Wunused -Wno-unused-parameter -Wchar-subscripts -funsigned-char -Wno-unused-function \
-DCONFIG_VERSION=\"2021-03-27-CKB\"
CFLAGS += -Wextra -Wno-sign-compare -Wno-missing-field-initializers -Wundef -Wuninitialized \
-Wunused -Wno-unused-parameter -Wchar-subscripts -funsigned-char -Wno-unused-function \
-DCONFIG_VERSION=\"2021-03-27-CKB\"
CFLAGS += -Wno-incompatible-library-redeclaration -Wno-implicit-const-int-float-conversion -Wno-invalid-noreturn

CFLAGS += -DCKB_DECLARATION_ONLY
CFLAGS += -D__BYTE_ORDER=1234 -D__LITTLE_ENDIAN=1234 -D__ISO_C_VISIBLE=1999 -D__GNU_VISIBLE
CFLAGS += -DCKB_MALLOC_DECLARATION_ONLY -DCKB_PRINTF_DECLARATION_ONLY -DCONFIG_BIGNUM -DCONFIG_STACK_CHECK
CFLAGS += -DCKB_MALLOC_DECLARATION_ONLY -DCKB_PRINTF_DECLARATION_ONLY -DCONFIG_BIGNUM -DCONFIG_STACK_CHECK
CFLAGS += -isystem deps/musl/release/include
# uncomment to dump memory usage
# CFLAGS += -DMEMORY_USAGE

LDFLAGS := -static --gc-sections
LDFLAGS := -static --gc-sections -nostdlib
LDFLAGS += -Ldeps/compiler-rt-builtins-riscv/build -lcompiler-rt
LDFLAGS += --sysroot deps/musl/release -Ldeps/musl/release/lib -lc -lgcc
LDFLAGS += -wrap=gettimeofday
LDFLAGS += -wrap=fesetround
LDFLAGS += -wrap=localtime_r

OBJDIR=build

QJS_OBJS=$(OBJDIR)/qjs.o $(OBJDIR)/quickjs.o $(OBJDIR)/libregexp.o $(OBJDIR)/libunicode.o \
$(OBJDIR)/cutils.o $(OBJDIR)/mocked.o $(OBJDIR)/std_module.o $(OBJDIR)/ckb_module.o $(OBJDIR)/ckb_cell_fs.o \
$(OBJDIR)/libbf.o $(OBJDIR)/cmdopt.o

STD_OBJS=$(OBJDIR)/string_impl.o $(OBJDIR)/malloc_impl.o $(OBJDIR)/math_impl.o \
$(OBJDIR)/math_log_impl.o $(OBJDIR)/math_pow_impl.o $(OBJDIR)/printf_impl.o $(OBJDIR)/stdio_impl.o \
$(OBJDIR)/locale_impl.o


all: build/ckb-js-vm
all: deps/musl/release build/ckb-js-vm

deps/compiler-rt-builtins-riscv/build/libcompiler-rt.a:
cd deps/compiler-rt-builtins-riscv && make

build/ckb-js-vm: $(STD_OBJS) $(QJS_OBJS) $(OBJDIR)/impl.o deps/compiler-rt-builtins-riscv/build/libcompiler-rt.a
deps/musl/release:
cd deps/musl && \
CLANG=$(CC) ./ckb/build.sh

build/ckb-js-vm: $(QJS_OBJS) deps/compiler-rt-builtins-riscv/build/libcompiler-rt.a
$(LD) $(LDFLAGS) -o $@ $^
cp $@ $@.debug
$(OBJCOPY) --strip-debug --strip-all $@
Expand All @@ -63,18 +67,10 @@ $(OBJDIR)/%.o: quickjs/%.c
@echo build $<
@$(CC) $(CFLAGS) -c -o $@ $<

$(OBJDIR)/%.o: include/c-stdlib/src/%.c
@echo build $<
@$(CC) $(CFLAGS) -c -o $@ $<

$(OBJDIR)/%.o: include/%.c
@echo build $<
@$(CC) $(CFLAGS) -c -o $@ $<

$(OBJDIR)/impl.o: deps/ckb-c-stdlib/libc/src/impl.c
@echo build $<
@$(CC) $(filter-out -DCKB_DECLARATION_ONLY, $(CFLAGS)) -c -o $@ $<

test:
make -f tests/examples/Makefile
make -f tests/basic/Makefile
Expand All @@ -91,7 +87,7 @@ clean:
make -C deps/compiler-rt-builtins-riscv clean

install:
wget 'https://github.com/nervosnetwork/ckb-standalone-debugger/releases/download/v0.111.0/ckb-debugger-linux-x64.tar.gz'
wget 'https://github.com/nervosnetwork/ckb-standalone-debugger/releases/download/v0.118.0-rc2/ckb-debugger-linux-x64.tar.gz'
tar zxvf ckb-debugger-linux-x64.tar.gz
mv ckb-debugger ~/.cargo/bin/ckb-debugger
make -f tests/ckb_js_tests/Makefile install-lua
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ adapting [quickjs](https://bellard.org/quickjs/).


## Build
The clang version 16 is required.
The clang version 18 is required.

```shell
git submodule update --init
Expand Down
2 changes: 1 addition & 1 deletion deps/compiler-rt-builtins-riscv
1 change: 1 addition & 0 deletions deps/musl
Submodule musl added at f122fb
11 changes: 4 additions & 7 deletions include/Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@

STYLE := "{BasedOnStyle: Google, TabWidth: 4, IndentWidth: 4, UseTab: Never, SortIncludes: false, ColumnLimit: 120}"


fmt:
clang-format -i -style=$(STYLE) *.c *.h
clang-format -i -style=$(STYLE) c-stdlib/*.h
clang-format -i -style=$(STYLE) c-stdlib/src/*.c
clang-format -i -style=$(STYLE) ../quickjs/qjs.c ../quickjs/std_module.c ../quickjs/std_module.h ../quickjs/ckb_module.c ../quickjs/ckb_module.h

clang-format-18 -i -style=$(STYLE) *.c *.h
clang-format-18 -i -style=$(STYLE) c-stdlib/*.h
clang-format-18 -i -style=$(STYLE) c-stdlib/src/*.c
clang-format-18 -i -style=$(STYLE) ../quickjs/qjs.c ../quickjs/std_module.c ../quickjs/std_module.h ../quickjs/ckb_module.c ../quickjs/ckb_module.h
1 change: 0 additions & 1 deletion include/c-stdlib/README.md

This file was deleted.

14 changes: 0 additions & 14 deletions include/c-stdlib/my_assert.h

This file was deleted.

16 changes: 0 additions & 16 deletions include/c-stdlib/my_ctype.h

This file was deleted.

18 changes: 0 additions & 18 deletions include/c-stdlib/my_errno.h

This file was deleted.

39 changes: 0 additions & 39 deletions include/c-stdlib/my_features.h

This file was deleted.

Loading

0 comments on commit 34210cb

Please sign in to comment.