From be33dbe89f995a1567e9502d587a61c91c4c656f Mon Sep 17 00:00:00 2001 From: William Bell Date: Sat, 14 Jun 2025 01:56:12 +0100 Subject: [PATCH] improve cross plateform binary portability --- .github/workflows/release.yml | 45 +++++++++++++++++++++++++++++++++++ .gitignore | 2 +- CMakeLists.txt | 2 -- Makefile | 4 ++-- conanfile.py | 2 -- src/main.c | 18 ++++++++++---- src/parser/string/string.c | 1 - src/translator/translator.c | 5 ++-- src/translator/translator.h | 3 ++- 9 files changed, 67 insertions(+), 15 deletions(-) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..e16f757 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,45 @@ +name: Build and Release + +on: + push: + tags: + - '*' # Trigger on any tag push + +jobs: + build_and_release: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Setup Python (needed for Conan) + uses: actions/setup-python@v4 + with: + python-version: '3.x' + + - name: Install Conan + run: | + python -m pip install --upgrade pip + pip install conan + + - name: Configure Conan + run: | + conan profile new default --detect --force + conan profile update settings.compiler.libcxx=libstdc++11 default + + - name: Install dependencies and build with Conan + run: | + conan install . --build=missing + conan build . + + - name: Create GitHub Release + id: create_release + uses: ncipollo/release-action@v1 + with: + tag: ${{ github.ref_name }} + name: Release ${{ github.ref_name }} + body: | + Automated release based on tag ${{ github.ref_name }} + draft: false + prerelease: false \ No newline at end of file diff --git a/.gitignore b/.gitignore index 08b5cec..dadf3de 100644 --- a/.gitignore +++ b/.gitignore @@ -60,4 +60,4 @@ build *.yy.c *.yy.h -out.car \ No newline at end of file +out.arbin \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index ba72e60..70315dc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -42,7 +42,6 @@ set_target_properties(argon PROPERTIES # Step 6: Conan libraries find_package(BDWgc REQUIRED) -find_package(cJSON REQUIRED) find_package(gmp REQUIRED) target_compile_options(argon PRIVATE -O3 -Wall -Wextra -Wno-unused-function -s) @@ -50,7 +49,6 @@ target_link_options(argon PRIVATE -static) target_link_libraries(argon PRIVATE BDWgc::BDWgc - cjson::cjson gmp::gmp m ) diff --git a/Makefile b/Makefile index f3742fa..b03b0df 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ LEXER_C = src/lexer/lex.yy.c LEXER_H = src/lexer/lex.yy.h CFILES = $(shell find src -name '*.c') -CFLAGS = -lm -lcjson -lgc -lgmp -Wall -Wextra -Wno-unused-function +CFLAGS = $(ARCHFLAGS) -lm -lgc -lgmp -Wall -Wextra -Wno-unused-function BINARY = bin/argon all: $(BINARY) @@ -13,7 +13,7 @@ $(LEXER_C) $(LEXER_H): $(LEXER_SRC) $(BINARY): $(CFILES) $(LEXER_C) $(LEXER_H) mkdir -p bin - gcc -static -O3 -o $(BINARY) $(CFILES) $(CFLAGS) -s + gcc -O3 -o $(BINARY) $(CFILES) $(CFLAGS) -s debug: $(CFILES) $(LEXER_C) $(LEXER_H) mkdir -p bin diff --git a/conanfile.py b/conanfile.py index 106ed2c..5b463c9 100644 --- a/conanfile.py +++ b/conanfile.py @@ -11,13 +11,11 @@ class ArgonConan(ConanFile): # Remove tool_requires, no flex from Conan requires = [ "gmp/6.3.0", - "cjson/1.7.16", "bdwgc/8.2.8" ] default_options = { "gmp/*:shared": False, - "cjson/*:shared": False, "bdwgc/*:shared": False } diff --git a/src/main.c b/src/main.c index 5056342..8b22b1c 100644 --- a/src/main.c +++ b/src/main.c @@ -5,9 +5,11 @@ #include "parser/parser.h" #include "translator/translator.h" +#include #include #include #include +#include #include #include @@ -44,11 +46,19 @@ int main(int argc, char *argv[]) { darray_free(&ast, free_parsed); - file = fopen("out.car", "wb"); + file = fopen("out.arbin", "wb"); - fwrite(&translated.registerCount, sizeof(size_t), 1, file); - fwrite(&translated.constants.size, sizeof(size_t), 1, file); - fwrite(&translated.bytecode.size, sizeof(size_t), 1, file); + uint64_t regCount = (uint64_t)translated.registerCount; + uint64_t constantsSize = (uint64_t)translated.constants.size; + uint64_t bytecodeSize = (uint64_t)translated.bytecode.size; + + regCount = htole64(regCount); + constantsSize = htole64(constantsSize); + bytecodeSize = htole64(bytecodeSize); + + fwrite(®Count, sizeof(uint64_t), 1, file); + fwrite(&constantsSize, sizeof(uint64_t), 1, file); + fwrite(&bytecodeSize, sizeof(uint64_t), 1, file); fwrite(translated.constants.data, 1, translated.constants.size, file); fwrite(translated.bytecode.data, translated.bytecode.element_size, translated.bytecode.size, file); diff --git a/src/parser/string/string.c b/src/parser/string/string.c index 3119480..61f882b 100644 --- a/src/parser/string/string.c +++ b/src/parser/string/string.c @@ -2,7 +2,6 @@ #include "../../lexer/token.h" #include "../../memory.h" -#include #include #include #include diff --git a/src/translator/translator.c b/src/translator/translator.c index 90904e3..219d0ee 100644 --- a/src/translator/translator.c +++ b/src/translator/translator.c @@ -46,12 +46,13 @@ size_t arena_push(ConstantArena *arena, const void *data, size_t length) { Translated init_translator() { Translated translated; translated.registerCount = 0; - darray_init(&translated.bytecode, sizeof(size_t)); + darray_init(&translated.bytecode, sizeof(uint64_t)); arena_init(&translated.constants); return translated; } -size_t push_instruction_code(Translated * translator, size_t code) { +size_t push_instruction_code(Translated * translator, uint64_t code) { + code = htole64(code); size_t offset = translator->bytecode.size; darray_push(&translator->bytecode, &code); return offset; diff --git a/src/translator/translator.h b/src/translator/translator.h index 5ddd767..e52e36d 100644 --- a/src/translator/translator.h +++ b/src/translator/translator.h @@ -3,6 +3,7 @@ #include "../dynamic_array/darray.h" #include +#include #include "../dynamic_array/darray.h" #include "../parser/parser.h" #include "../memory.h" @@ -26,7 +27,7 @@ void * arena_get(ConstantArena *arena, size_t offset); size_t arena_push(ConstantArena *arena, const void *data, size_t length); -size_t push_instruction_code(Translated * translator, size_t code); +size_t push_instruction_code(Translated * translator, uint64_t code); void set_registers(Translated * translator, size_t count);