Skip to content

Commit

Permalink
Update spawn syscall
Browse files Browse the repository at this point in the history
  • Loading branch information
mohanson committed Dec 13, 2024
1 parent fe6e580 commit fdb266e
Show file tree
Hide file tree
Showing 21 changed files with 323 additions and 4,203 deletions.
21 changes: 14 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,17 @@ 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 coreutils
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
1 change: 0 additions & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

[submodule "deps/ckb-c-stdlib"]
path = deps/ckb-c-stdlib
url = https://github.com/nervosnetwork/ckb-c-stdlib.git
Expand Down
38 changes: 25 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,36 +1,37 @@

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
OBJCOPY := llvm-objcopy-18
AR := llvm-ar-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 \
CFLAGS += -g -Oz \
-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 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
# uncomment to dump memory usage
# CFLAGS += -DMEMORY_USAGE

Expand Down Expand Up @@ -90,8 +91,19 @@ clean:
cd tests/ckb_js_tests && make clean
make -C deps/compiler-rt-builtins-riscv clean

STYLE := "{BasedOnStyle: Google, TabWidth: 4, IndentWidth: 4, UseTab: Never, SortIncludes: false, ColumnLimit: 120}"
fmt:
clang-format-18 -i -style=$(STYLE) \
quickjs/ckb_module.c \
quickjs/ckb_module.h \
quickjs/mocked.c \
quickjs/mocked.h \
quickjs/qjs.c \
quickjs/std_module.c \
quickjs/std_module.h

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.119.0/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
9 changes: 4 additions & 5 deletions docs/intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ machines are ported to CKB, JavaScript can also be run on CKB.
implementation by Fabrice Bellard. This project aims to port it to CKB, enabling
JavaScript capabilities in CKB programming.

## Basic
## Basic
The project is finally compiled into a single binary: ckb-js-vm which can be
found in `build` folder after executing:
```
Expand Down Expand Up @@ -69,7 +69,7 @@ folder.
When `-c` is provided, it can compile a JavaScript source file into JavaScript bytecode with
output as hexadecimal. Below is a recipe about how to compile JavaScript source file:
```shell
ckb-debugger --read-file hello.js --bin build/ckb-js-vm -- -c | awk '/Run result: 0/{exit} {print}' | xxd -r -p > hello.bc
ckb-debugger --read-file hello.js --bin build/ckb-js-vm -- -c | awk -f $(ROOT_DIR)/../../tools/compile.awk | xxd -r -p > hello.bc
```
It reads `hello.js` and then compiles the JavaScript source file into bytecode in hex
formatting. Then, using the power of `awk` and `xxd`, it can be converted into
Expand All @@ -88,7 +88,7 @@ args: <ckb-js-vm args, 2 bytes> <code_hash to JavaScript code cell, 32 bytes> <h
```

The tailing bytes are JavaScript code arguments which can be used by JavaScript.
Note: 2 bytes ckb-js-vm args are reserved for further use.
Note: 2 bytes ckb-js-vm args are reserved for further use.

## Performance and Memory Usage
The JavaScript code implementation for a ["hello,
Expand All @@ -103,7 +103,7 @@ The memory usage of the [SimpleUDT](../tests/ckb_js_tests/test_data/simple_udt.j
is about 139K(130K in heap and 9K in stack).


## Integration
## Integration

There are four approaches to integrating ckb-js-vm:

Expand Down Expand Up @@ -133,4 +133,3 @@ usable memory of 4M. This leaves only 3M bytes for the host script. It's
important to note that in certain critical scenarios, the peak memory usage can
exceed the mentioned limits. Dynamic libraries also face security concerns, as
detailed in [security.md](./security.md).

7 changes: 2 additions & 5 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 *.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

Loading

0 comments on commit fdb266e

Please sign in to comment.