From ef3cd555fa5c8e9b79333d34172ba415effefa8b Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Thu, 27 Feb 2025 10:26:53 +0100 Subject: [PATCH 1/6] Add script to create amalgamated build Fixes: https://github.com/quickjs-ng/quickjs/issues/688 --- amalgam.js | 46 ++++++++++++++++++++++++++++++++++++++++++++++ quickjs-libc.c | 2 ++ 2 files changed, 48 insertions(+) create mode 100644 amalgam.js diff --git a/amalgam.js b/amalgam.js new file mode 100644 index 000000000..d84b5c8e9 --- /dev/null +++ b/amalgam.js @@ -0,0 +1,46 @@ +import {loadFile, writeFile} from "qjs:std" + +const cutils_c = loadFile("cutils.c") +const cutils_h = loadFile("cutils.h") +const libbf_c = loadFile("libbf.c") +const libbf_h = loadFile("libbf.h") +const libregexp_c = loadFile("libregexp.c") +const libregexp_h = loadFile("libregexp.h") +const libregexp_opcode_h = loadFile("libregexp-opcode.h") +const libunicode_c = loadFile("libunicode.c") +const libunicode_h = loadFile("libunicode.h") +const libunicode_table_h = loadFile("libunicode-table.h") +const list_h = loadFile("list.h") +const quickjs_atom_h = loadFile("quickjs-atom.h") +const quickjs_c = loadFile("quickjs.c") +const quickjs_c_atomics_h = loadFile("quickjs-c-atomics.h") +const quickjs_h = loadFile("quickjs.h") +const quickjs_libc_c = loadFile("quickjs-libc.c") +const quickjs_libc_h = loadFile("quickjs-libc.h") +const quickjs_opcode_h = loadFile("quickjs-opcode.h") + +let source = "#if defined(CONFIG_QUICKJS_LIBC) && defined(__linux__) && !defined(_GNU_SOURCE)\n" + + "#define _GNU_SOURCE\n" + + "#endif\n" + + quickjs_c_atomics_h + + cutils_h + + list_h + + libbf_h + + libunicode_h // exports lre_is_id_start, used by libregexp.h + + libregexp_h + + libunicode_table_h + + quickjs_h + + quickjs_c + + cutils_c + + libbf_c + + libregexp_c + + libunicode_c + + "#ifdef CONFIG_QUICKJS_LIBC\n" + + quickjs_libc_h + + quickjs_libc_c + + "#endif // CONFIG_QUICKJS_LIBC\n" +source = source.replace(/#include "quickjs-atom.h"/g, quickjs_atom_h) +source = source.replace(/#include "quickjs-opcode.h"/g, quickjs_opcode_h) +source = source.replace(/#include "libregexp-opcode.h"/g, libregexp_opcode_h) +source = source.replace(/#include "[^"]+"/g, "") +writeFile("quickjs-amalgam.c", source) diff --git a/quickjs-libc.c b/quickjs-libc.c index 67d2597f0..832f4723a 100644 --- a/quickjs-libc.c +++ b/quickjs-libc.c @@ -94,7 +94,9 @@ extern char **environ; #include "list.h" #include "quickjs-libc.h" +#ifndef MAX_SAFE_INTEGER // already defined in amalgamation builds #define MAX_SAFE_INTEGER (((int64_t) 1 << 53) - 1) +#endif #ifndef QJS_NATIVE_MODULE_SUFFIX #ifdef _WIN32 From 44034c4f1cf3278f20b95841e7a0542dec0ac378 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Thu, 27 Feb 2025 15:53:12 +0100 Subject: [PATCH 2/6] squash! QJS_BUILD_LIBC --- amalgam.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/amalgam.js b/amalgam.js index d84b5c8e9..0d8eecbc8 100644 --- a/amalgam.js +++ b/amalgam.js @@ -19,7 +19,7 @@ const quickjs_libc_c = loadFile("quickjs-libc.c") const quickjs_libc_h = loadFile("quickjs-libc.h") const quickjs_opcode_h = loadFile("quickjs-opcode.h") -let source = "#if defined(CONFIG_QUICKJS_LIBC) && defined(__linux__) && !defined(_GNU_SOURCE)\n" +let source = "#if defined(QJS_BUILD_LIBC) && defined(__linux__) && !defined(_GNU_SOURCE)\n" + "#define _GNU_SOURCE\n" + "#endif\n" + quickjs_c_atomics_h @@ -35,10 +35,10 @@ let source = "#if defined(CONFIG_QUICKJS_LIBC) && defined(__linux__) && !defined + libbf_c + libregexp_c + libunicode_c - + "#ifdef CONFIG_QUICKJS_LIBC\n" + + "#ifdef QJS_BUILD_LIBC\n" + quickjs_libc_h + quickjs_libc_c - + "#endif // CONFIG_QUICKJS_LIBC\n" + + "#endif // QJS_BUILD_LIBC\n" source = source.replace(/#include "quickjs-atom.h"/g, quickjs_atom_h) source = source.replace(/#include "quickjs-opcode.h"/g, quickjs_opcode_h) source = source.replace(/#include "libregexp-opcode.h"/g, libregexp_opcode_h) From 1d3a35804ffe6dcc23ba31232f305ebb6dc69a6c Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Thu, 27 Feb 2025 16:17:15 +0100 Subject: [PATCH 3/6] squash! test amalgamation build on ci --- .github/workflows/ci.yml | 26 ++++++++++++++++++++++++++ amalgam.js | 2 +- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 499685e38..70189a6cd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -566,3 +566,29 @@ jobs: - name: test run: | make test + + amalgam: + strategy: + matrix: + # TODO(bnoordhuis) test on windows + config: + - { os: ubuntu-latest } + - { os: macos-latest } + runs-on: ${{ matrix.config.os }} + steps: + - uses: actions/checkout@v4 + - name: build + run: | + make + - name: copy files + run: | + cp quickjs.h run-test262.c $RUNNER_TEMP + - name: create amalgamation + run: | + build/qjs amalgam.js $RUNNER_TEMP/quickjs-amalgam.c + - name: build amalgamation + run: | + cd $RUNNER_TEMP && cc -Wall -o run-test262 run-test262.c quickjs-amalgam.c + - name: test + run: | + make test RUN262=$RUNNER_TEMP/run-test262 diff --git a/amalgam.js b/amalgam.js index 0d8eecbc8..bc082dced 100644 --- a/amalgam.js +++ b/amalgam.js @@ -43,4 +43,4 @@ source = source.replace(/#include "quickjs-atom.h"/g, quickjs_atom_h) source = source.replace(/#include "quickjs-opcode.h"/g, quickjs_opcode_h) source = source.replace(/#include "libregexp-opcode.h"/g, libregexp_opcode_h) source = source.replace(/#include "[^"]+"/g, "") -writeFile("quickjs-amalgam.c", source) +writeFile(execArgv[2] ?? "quickjs-amalgam.c", source) From 95b37116da9df1065aa548c9db41519bbcfdb7f5 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Thu, 27 Feb 2025 23:01:05 +0100 Subject: [PATCH 4/6] squash! tweak ci --- .github/workflows/ci.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 70189a6cd..cedcd1fbc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -580,15 +580,14 @@ jobs: - name: build run: | make - - name: copy files - run: | - cp quickjs.h run-test262.c $RUNNER_TEMP - name: create amalgamation run: | build/qjs amalgam.js $RUNNER_TEMP/quickjs-amalgam.c - name: build amalgamation run: | - cd $RUNNER_TEMP && cc -Wall -o run-test262 run-test262.c quickjs-amalgam.c + cc -Wall -I. -o $RUNNER_TEMP/run-test262.o -c run-test262.c + cc -Wall -I/ -o $RUNNER_TEMP/quickjs-amalgam.o -c $RUNNER_TEMP/quickjs-amalgam.c + cc -o $RUNNER_TEMP/run-test262 $RUNNER_TEMP/run-test262.o $RUNNER_TEMP/quickjs-amalgam.o - name: test run: | make test RUN262=$RUNNER_TEMP/run-test262 From e1194607e905c7688c2090858d8e94f96b712c0d Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Thu, 27 Feb 2025 23:28:27 +0100 Subject: [PATCH 5/6] squash! more tweaks --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cedcd1fbc..0c11e626e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -586,8 +586,8 @@ jobs: - name: build amalgamation run: | cc -Wall -I. -o $RUNNER_TEMP/run-test262.o -c run-test262.c - cc -Wall -I/ -o $RUNNER_TEMP/quickjs-amalgam.o -c $RUNNER_TEMP/quickjs-amalgam.c - cc -o $RUNNER_TEMP/run-test262 $RUNNER_TEMP/run-test262.o $RUNNER_TEMP/quickjs-amalgam.o + cc -Wall -I/ -DQJS_BUILD_LIBC -o $RUNNER_TEMP/quickjs-amalgam.o -c $RUNNER_TEMP/quickjs-amalgam.c + cc -o $RUNNER_TEMP/run-test262 $RUNNER_TEMP/run-test262.o $RUNNER_TEMP/quickjs-amalgam.o -lm - name: test run: | make test RUN262=$RUNNER_TEMP/run-test262 From 57a482390aef0d94bd7f3f9ba4cea5bec29eb9ef Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Fri, 28 Feb 2025 20:37:58 +0100 Subject: [PATCH 6/6] squash! add amalgamation to release ci, maybe --- .github/workflows/release.yml | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 4028c1d44..8c60216f1 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -50,11 +50,20 @@ jobs: cd build cmake -DCMAKE_OSX_ARCHITECTURES="x86_64;arm64" .. make -j$(getconf _NPROCESSORS_ONLN) + (cd .. && build/qjs amalgam.js build/quickjs-amalgam.c) + cp ../quickjs.h . + zip -9 quickjs-amalgam.zip quickjs-amalgam.c quickjs.h mv qjs qjs-darwin mv qjsc qjsc-darwin - name: check run: | lipo -info build/qjs-darwin build/qjsc-darwin + - name: upload amalgamation + uses: actions/upload-artifact@v4 + with: + name: quickjs-amalgam.zip + path: build/quickjs-amalgam.zip + compression-level: 0 # already compressed - name: upload uses: actions/upload-artifact@v4 with: @@ -124,7 +133,7 @@ jobs: - name: get assets uses: actions/download-artifact@v4 with: - pattern: qjs-* + pattern: * path: build merge-multiple: true - run: ls -R build