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

Feat/dmon #72

Merged
merged 9 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
18 changes: 9 additions & 9 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,21 +58,21 @@ jobs:
# run: |
# echo "😤 Some files failed the C linting checks!"

musl-test:
name: 🐧 Musl Linux test
linux-test:
name: 🐧 Linux x86 test
needs: [reuse, c-lint]
runs-on: "ubuntu-latest"
steps:
- uses: actions/checkout@v4
- name: install dependencies
run: |
sudo apt install -yq musl-tools musl-dev
- name: Build x86_64 with musl-system
sudo apt install -yq make gcc xxd
- name: Build x86_64 with Linux
run: |
make musl-linux
make linux-x86
- name: Run tests
run: |
make check
make check-ci

win-native-test:
name: 🪟 Windows native test
Expand All @@ -85,7 +85,7 @@ jobs:
make win-native
- name: Run tests
run: |
make check
make check-ci

osx-native-test:
name: 🍎 OSX native test
Expand All @@ -98,11 +98,11 @@ jobs:
make apple-osx
- name: Run tests
run: |
make check
make check-ci

semantic-release:
name: 🤖 Semantic release
needs: [musl-test, osx-native-test, win-native-test]
needs: [linux-test, osx-native-test, win-native-test]
runs-on: ubuntu-latest
outputs:
new_release_published: ${{ steps.semantic-release.outputs.new_release_published }}
Expand Down
25 changes: 23 additions & 2 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,32 +23,53 @@ _: ##

musl-linux: ## 🗿 Build a fully static cjit using musl-libc on Linux
$(MAKE) -f build/musl.mk
@rm -f .build_done*
date | tee .build_done_musl

linux-x86: ## 🐧 Build a dynamically linked cjit using libs found on Linux x86
$(MAKE) -f build/linux.mk
@rm -f .build_done*
date | tee .build_done_linux

win-wsl: ## 🪟 Build cjit.exe for WIN64 on an Ubuntu WSL VM using gcc-mingw-w64
$(MAKE) -f build/win-wsl.mk
@rm -f .build_done*
date | tee .build_done_win

win-native: ## 🪟 Build cjit.exe for WIN64 on Windows Server
cd ./lib/tinycc; bash configure --targetos=WIN32 --config-backtrace=no; make libtcc.a libtcc1.a
$(MAKE) -f build/win-native.mk
@rm -f .build_done*
date | tee .build_done_win

apple-osx: ## 🍎 Build cjit.command for Apple/OSX using clang static
$(MAKE) -f build/osx.mk
@rm -f .build_done*
date | tee .build_done_osx

_: ##
------: ## __ Debugging targets

debug-gdb: ## 🔬 Build using the address sanitizer to detect memory leaks
$(MAKE) -f build/linux.mk GDB=1
date | tee .build_done_linux

debug-asan: ## 🔬 Build using the address sanitizer to detect memory leaks
$(MAKE) -f build/linux.mk ASAN=1
date | tee .build_done_linux

_: ##
------: ## __ Testing targets

check: CJIT ?= ./cjit
check: ## 🧪 Run all tests using the currently built binary ./cjit
./test/bats/bin/bats test
@./test/bats/bin/bats test/cli.bats
@./test/bats/bin/bats test/windows.bats
@if [ -r .build_done_linux ]; then ./test/bats/bin/bats test/dmon.bats; fi


check-ci: ## 🧪 Run all tests using the currently built binary ./cjit
@./test/bats/bin/bats test/cli.bats
@./test/bats/bin/bats test/windows.bats

_: ##
clean: ## 🧹 Clean the source from all built objects
Expand Down
9 changes: 9 additions & 0 deletions LICENSES/BSD-2-Clause.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Copyright (c) <year> <owner>

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
6 changes: 6 additions & 0 deletions REUSE.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ precedence = "aggregate"
SPDX-FileCopyrightText = "2001-2004 Fabrice Bellard"
SPDX-License-Identifier = "LGPL-2.1-or-later"

[[annotations]]
path = "lib/dmon/**"
precedence = "aggregate"
SPDX-FileCopyrightText = " 2019, Sepehr Taghdisian"
SPDX-License-Identifier = "BSD-2-Clause"

[[annotations]]
path = ["docs/**", "**.md"]
precedence = "aggregate"
Expand Down
4 changes: 4 additions & 0 deletions build/deps.mk
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
-DVERSION=\"${VERSION}\" \
-DCURRENT_YEAR=\"${CURRENT_YEAR}\"

src/embed-dmon.c:
$(info Embedding dmon headers)
bash build/embed-dmon.sh

src/embed-musl-libc.c:
bash build/embed-musl-libc.sh
sed -i 's/unsigned char _lib_x86_64_linux_musl_libc_so/const unsigned char musl_libc/' src/embed-musl-libc.c
Expand Down
49 changes: 49 additions & 0 deletions build/embed-dmon.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/usr/bin/env bash

includes=lib/dmon
dst=src/embed-dmon.c

command -v xxd > /dev/null || {
>&2 echo "Error not found: xxd binary not installed"
exit 1
}

([ "$1" = "code" ]) && {
externs=`mktemp`
calls=`mktemp`
}

echo "// ${includes}" > $dst
ipath=`echo ${includes} | sed 's/\//_/g; s/\./_/g'`
for l in $(ls ${includes}); do
[ -z "$l" ] && continue
[ "${l:0:1}" = "#" ] && continue

xxd -i ${includes}/${l} >> $dst
hname=`echo $l | sed 's/\//_/g; s/\./_/g'`
([ "$1" = "code" ]) && {
# print on stderr something handy to paste in code
echo "extern char *${ipath}_${hname};" >> $externs
echo "extern unsigned int ${ipath}_${hname}_len;" >> $externs
echo "if(!write_to_file(tmpdir,\"${l}\",(char*)&${ipath}_${hname},${ipath}_${hname}_len)) goto endgame;" >> $calls
}
done
# must add const in linux or darwin
# sed inplace is not portable
if [[ "$OSTYPE" == "darwin"* ]]; then
sed -i'' -e 's/unsigned char/const char/' $dst
sed -i'' -e 's/unsigned int/const unsigned int/' $dst
else
sed -i -e 's/unsigned char/const char/' $dst
sed -i -e 's/unsigned int/const unsigned int/' $dst
fi
([ "$1" = "code" ]) && {
>&2 echo "Externs to declare:"
cat $externs
>&2 echo
>&2 echo "Calls:"
cat $calls
rm -f $externs $calls
}

exit 0
2 changes: 1 addition & 1 deletion build/init.mk
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ cflags := ${CFLAGS} ${cflags_includes}

SOURCES := src/io.o src/file.o src/cflag.o src/cjit.o \
src/embed-libtcc1.o src/embed-headers.o \
src/exec-headers.o src/repl.o
src/exec-headers.o src/repl.o src/embed-dmon.o

ldadd := lib/tinycc/libtcc.a

Expand Down
10 changes: 9 additions & 1 deletion build/linux.mk
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,25 @@ include build/init.mk

cc := gcc

cflags += -DLIBC_GNU -D_GNU_SOURCE -DKILO_SUPPORTED
cflags += -DLIBC_GNU -D_GNU_SOURCE -DKILO_SUPPORTED -DCJIT_BUILD_LINUX

SOURCES += src/kilo.o

ifdef ASAN
cflags := -Og -ggdb -DDEBUG=1 -fno-omit-frame-pointer -fsanitize=address
cflags += ${cflags_includes} ${cflags_gnu} -DKILO_SUPPORTED
cflags += -DCJIT_BUILD_LINUX
ldflags := -fsanitize=address -static-libasan
# tinycc_config += --extra-ldflags="${ldflags}"
endif

ifdef GDB
cflags := -Og -ggdb -DDEBUG=1 -fno-omit-frame-pointer
cflags += ${cflags_includes} ${cflags_gnu} -DKILO_SUPPORTED
cflags += -DCJIT_BUILD_LINUX
# tinycc_config += --extra-ldflags="${ldflags}"
endif

tinycc_config += --with-libgcc

ifeq ($(shell sestatus | awk -F': *' '/SELinux status:/ {print $2}'), enabled)
Expand Down
2 changes: 1 addition & 1 deletion build/musl.mk
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ include build/init.mk

cflags := -Wall -static -O2 ${cflags_stack_protect}
cflags += -Isrc -Ilib/tinycc -DLIBC_MUSL -nostdlib
cflags += -DKILO_SUPPORTED
cflags += -DKILO_SUPPORTED -DCJIT_BUILD_MUSL

ldadd := lib/tinycc/libtcc.a /usr/lib/x86_64-linux-musl/crt1.o /usr/lib/x86_64-linux-musl/libc.a

Expand Down
12 changes: 9 additions & 3 deletions build/osx.mk
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
include build/init.mk

cc := clang
cflags += -DCJIT_BUILD_OSX

all: deps cjit.command

Expand All @@ -14,7 +15,7 @@ cjit.command: ${SOURCES}
-DVERSION=\"${VERSION}\" \
-DCURRENT_YEAR=\"${CURRENT_YEAR}\"

deps: lib/tinycc/libtcc.a src/embed-libtcc1.c src/embed-headers.c
deps: lib/tinycc/libtcc.a src/embed-libtcc1.c src/embed-headers.c src/embed-dmon.c

## Custom deps targets for osx due to different sed

Expand All @@ -32,5 +33,10 @@ src/embed-libtcc1.c:
src/embed-headers.c:
$(info Embedding tinycc headers)
bash build/embed-headers.sh win
sed -i'' -e 's/unsigned char/const char/' src/embed-headers.c
sed -i'' -e 's/unsigned int/const unsigned int/' src/embed-headers.c

src/embed-dmon.c:
$(info Embedding dmon headers)
bash build/embed-dmon.sh

# sed -i'' -e 's/unsigned char/const char/' src/embed-headers.c
# sed -i'' -e 's/unsigned int/const unsigned int/' src/embed-headers.c
6 changes: 5 additions & 1 deletion build/win-native.mk
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ SHELL := C:\Program Files\Git\bin\bash.exe
# redefine compilation flags
cc := gcc
cflags := -O2 -fomit-frame-pointer -Isrc -Ilib/tinycc
cflags += -DLIBC_MINGW32
cflags += -DLIBC_MINGW32 -DCJIT_BUILD_WIN
ldflags := -static-libgcc
ldadd := lib/tinycc/libtcc.a -lshlwapi
SOURCES += src/win-compat.o
Expand All @@ -42,3 +42,7 @@ src/embed-headers.c:
bash build/embed-headers.sh win
sed -i 's/unsigned char/const char/' src/embed-headers.c
sed -i 's/unsigned int/const unsigned int/' src/embed-headers.c

src/embed-dmon.c:
$(info Embedding dmon headers)
bash build/embed-dmon.sh
3 changes: 2 additions & 1 deletion build/win-wsl.mk
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ include build/init.mk

cc := x86_64-w64-mingw32-gcc
ar := x86_64-w64-mingw32-ar
cflags += -DLIBC_MINGW32
cflags += -DLIBC_MINGW32 -DCJIT_BUILD_WIN

ldadd += -lrpcrt4 -lshlwapi

Expand Down Expand Up @@ -36,6 +36,7 @@ deps:
@bash build/embed-headers.sh win
@sed -i 's/unsigned char/const char/' src/embed-headers.c
@sed -i 's/unsigned int/const unsigned int/' src/embed-headers.c
@bash build/embed-dmon.sh

.c.o:
$(cc) \
Expand Down
Loading
Loading