Skip to content

Commit

Permalink
feat: rewrite fs.lua in JavaScript(node) (#22)
Browse files Browse the repository at this point in the history
* feat: rewrite fs.lua in JavaScript(node)
  • Loading branch information
XuJiandong authored Dec 30, 2024
1 parent 0619065 commit 6120833
Show file tree
Hide file tree
Showing 9 changed files with 913 additions and 9 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ jobs:
chmod +x llvm.sh
sudo ./llvm.sh 18
rm llvm.sh
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22'
- name: Build
run: make all
- name: Install tools
Expand All @@ -25,7 +29,6 @@ jobs:
run: make test
- name: Benchmark
run: make benchmark

macos:
runs-on: macos-latest

Expand Down
10 changes: 5 additions & 5 deletions docs/fs.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ one entry file named `main.js`, and ckb-js-vm will load this file system from
any cell and execute `main.js` in it.

A file system is represented as a binary file in the format described below. We
may use the script [fs.lua](../tools/fs.lua) to create a file system from given
may use the script [fs-packer](../tools/fs-packer) to create a file system from given
files or unpack the file system into files.

## How to create a Simple File System
Expand All @@ -35,9 +35,9 @@ export function fib(n) {

If we want ckb-js-vm to execute this code smoothly, we must package them into a
file system first. To pack them within the current directory into `fib.fs`, you
may run
may run
```shell
find . -name *.js -type f | lua tools/fs.lua pack fib.fs
find . -name *.js -type f | node tools/fs-packer/dist/index.js pack fib.fs
```

```
Expand All @@ -46,7 +46,7 @@ packing file ./fib_module.js to fib_module.js
packing file ./main.js to main.js
```

Note that all file paths piped into the `fs.lua` must be in the relative path
Note that all file paths piped into the `fs-packer` must be in the relative path
format. The absolute path of a file in the current system is usually meaningless
in the Simple File System.

Expand Down Expand Up @@ -88,7 +88,7 @@ JavaScript files.

## Unpack Simple File System to Files

To unpack the files contained within a fs, you may run `lua tools/fs.lua unpack fib.fs .`.
To unpack the files contained within a fs, you may run `node tools/fs-packer/dist/index.js unpack fib.fs .`.

## Simple File System On-disk Representation

Expand Down
6 changes: 3 additions & 3 deletions tests/ckb_js_tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ module: spawn_caller
cargo run --bin module | ${CKB_DEBUGGER} --tx-file=- -s lock

build/bytecode/fs_modules.fs: test_data/fs_module/main.js test_data/fs_module/fib_module.js
cd test_data/fs_module && lua ../../../../tools/fs.lua pack ../../../../$@ main.js fib_module.js
cd test_data/fs_module && node ../../../../tools/fs-packer/dist/index.js pack ../../../../$@ main.js fib_module.js

fs_bytecode:
$(CKB_DEBUGGER) --read-file test_data/fs_module/main.js --bin $(BIN_PATH) -- -c | awk -f $(ROOT_DIR)/../../tools/compile.awk | xxd -r -p > ../../build/bytecode/main.bc
$(CKB_DEBUGGER) --read-file test_data/fs_module/fib_module.js --bin $(BIN_PATH) -- -c | awk -f $(ROOT_DIR)/../../tools/compile.awk | xxd -r -p > ../../build/bytecode/fib_module.bc
cd ../../build/bytecode && lua ../../tools/fs.lua pack ../../build/bytecode/fs_modules_bc.fs main.bc fib_module.bc
cd ../../build/bytecode && node ../../tools/fs-packer/dist/index.js pack ../../build/bytecode/fs_modules_bc.fs main.bc fib_module.bc
$(CKB_DEBUGGER) --max-cycles $(MAX_CYCLES) --read-file ../../build/bytecode/fs_modules_bc.fs --bin $(BIN_PATH) -- -f -r 2>&1 | fgrep 'Run result: 0'

file_system: build/bytecode/fs_modules.fs
Expand All @@ -39,7 +39,7 @@ syscall:
cargo run --bin syscall | $(CKB_DEBUGGER) --tx-file=- -s lock

fs_mount:
cd test_data/fs_module_mount && lua ../../../../tools/fs.lua pack ../../../../build/bytecode/fib_module.fs fib_module.js
cd test_data/fs_module_mount && node ../../../../tools/fs-packer/dist/index.js pack ../../../../build/bytecode/fib_module.fs fib_module.js
cargo run --bin module_mount | ${CKB_DEBUGGER} --tx-file=- -s lock

simple_udt:
Expand Down
3 changes: 3 additions & 0 deletions tools/fs-packer/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules/
test.pak
test-output
Loading

0 comments on commit 6120833

Please sign in to comment.