Skip to content
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

add ckb-c-stdlib as a submodule #12

Merged
merged 18 commits into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v4
with:
submodules: true
- uses: leafo/gh-actions-lua@v9
with:
luaVersion: "5.4"
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "include/ckb-c-stdlib"]
path = include/ckb-c-stdlib
url = https://github.com/contrun/ckb-c-stdlib.git
contrun marked this conversation as resolved.
Show resolved Hide resolved
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ CC := $(TARGET)-gcc
LD := $(TARGET)-gcc
OBJCOPY := $(TARGET)-objcopy

CFLAGS := -fPIC -O3 -fno-builtin -nostdinc -nostdlib -nostartfiles -fvisibility=hidden -fdata-sections -ffunction-sections -I lualib -I include/ckb-c-stdlib -I include/ckb-c-stdlib/libc -I include/ckb-c-stdlib/molecule -Wall -Werror -Wno-nonnull -Wno-nonnull-compare -Wno-unused-function -g
CFLAGS := -D__ISO_C_VISIBLE=1999 -fPIC -O3 -fno-builtin -nostdinc -nostdlib -nostartfiles -fvisibility=hidden -fdata-sections -ffunction-sections -I lualib -I lualib/c-stdlib -I include/ckb-c-stdlib -I include/ckb-c-stdlib/libc -I include/ckb-c-stdlib/molecule -Wall -Werror -Wno-nonnull -Wno-nonnull-compare -Wno-unused-function -Wno-error=maybe-uninitialized -g
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this macro "__ISO_C_VISIBLE=1999" used?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If __ISO_C_VISIBLE=1999 then LLONG_MAX is defined here https://github.com/nervosnetwork/ckb-c-stdlib/blob/efe1fe6b3cdda12e248e25664f5c04cbf7876265/libc/limits.h#L94 . Lua check the definition of LLONG_MAX https://github.com/nervosnetwork/ckb-lua/blob/b71d44288e8fb085074d3af056b359b8c6c22afa/lualib/luaconf.h#L502 to define a few things. This is somewhat dirty.


LDFLAGS := -nostdlib -nostartfiles -fno-builtin -Wl,-static -fdata-sections -ffunction-sections -Wl,--gc-sections

Expand All @@ -27,13 +27,13 @@ lualib/liblua.a:
make -C lualib liblua.a

build/dylibtest: tests/test_cases/dylibtest.c
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(shell $(CC) --print-search-dirs | sed -n '/install:/p' | sed 's/install:\s*//g')libgcc.a
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< lualib/liblua.a $(shell $(CC) --print-search-dirs | sed -n '/install:/p' | sed 's/install:\s*//g')libgcc.a

build/dylibexample: examples/dylib.c
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(shell $(CC) --print-search-dirs | sed -n '/install:/p' | sed 's/install:\s*//g')libgcc.a
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< lualib/liblua.a $(shell $(CC) --print-search-dirs | sed -n '/install:/p' | sed 's/install:\s*//g')libgcc.a

build/spawnexample: examples/spawn.c
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< $(shell $(CC) --print-search-dirs | sed -n '/install:/p' | sed 's/install:\s*//g')libgcc.a
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< lualib/liblua.a $(shell $(CC) --print-search-dirs | sed -n '/install:/p' | sed 's/install:\s*//g')libgcc.a

build/lua-loader.o: lua-loader/lua-loader.c
$(CC) -c $(CFLAGS) -o $@ $<
Expand Down
12 changes: 9 additions & 3 deletions examples/spawn.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,18 @@
int main() {
const char *argv[] = {"-e", "local m = arg[2] .. arg[3]; ckb.set_content(m)",
"hello", "world"};
int8_t exit_code = -1;
uint8_t content[80] = {};
uint64_t content_length = 80;
int8_t exit_code = -1;

spawn_args_t spgs = {
.memory_limit = 8,
.exit_code = &exit_code,
.content = content,
.content_length = &content_length,
};

int success =
ckb_spawn(8, 1, 3, 0, 4, argv, &exit_code, &content[0], &content_length);
int success = ckb_spawn(1, 3, 0, 4, argv, &spgs);
if (success != 0) {
return 1;
}
Expand Down
1 change: 1 addition & 0 deletions include/ckb-c-stdlib
Submodule ckb-c-stdlib added at dffd9e
53 changes: 0 additions & 53 deletions include/ckb-c-stdlib/.gitignore

This file was deleted.

17 changes: 0 additions & 17 deletions include/ckb-c-stdlib/.travis.yml

This file was deleted.

21 changes: 0 additions & 21 deletions include/ckb-c-stdlib/LICENSE

This file was deleted.

5 changes: 0 additions & 5 deletions include/ckb-c-stdlib/Makefile

This file was deleted.

11 changes: 0 additions & 11 deletions include/ckb-c-stdlib/README.md

This file was deleted.

Loading
Loading