Skip to content

Commit e29a713

Browse files
authored
Release amalgamated builds (#933)
Roll all the source files into a single jumbo file and release that along with quickjs.h in a zip file to make embedding for downstream users easy. Fixes: #688
1 parent 9a902ba commit e29a713

File tree

4 files changed

+83
-1
lines changed

4 files changed

+83
-1
lines changed

.github/workflows/ci.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,3 +566,28 @@ jobs:
566566
- name: test
567567
run: |
568568
make test
569+
570+
amalgam:
571+
strategy:
572+
matrix:
573+
# TODO(bnoordhuis) test on windows
574+
config:
575+
- { os: ubuntu-latest }
576+
- { os: macos-latest }
577+
runs-on: ${{ matrix.config.os }}
578+
steps:
579+
- uses: actions/checkout@v4
580+
- name: build
581+
run: |
582+
make
583+
- name: create amalgamation
584+
run: |
585+
build/qjs amalgam.js $RUNNER_TEMP/quickjs-amalgam.c
586+
- name: build amalgamation
587+
run: |
588+
cc -Wall -I. -o $RUNNER_TEMP/run-test262.o -c run-test262.c
589+
cc -Wall -I/ -DQJS_BUILD_LIBC -o $RUNNER_TEMP/quickjs-amalgam.o -c $RUNNER_TEMP/quickjs-amalgam.c
590+
cc -o $RUNNER_TEMP/run-test262 $RUNNER_TEMP/run-test262.o $RUNNER_TEMP/quickjs-amalgam.o -lm
591+
- name: test
592+
run: |
593+
make test RUN262=$RUNNER_TEMP/run-test262

.github/workflows/release.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,20 @@ jobs:
5050
cd build
5151
cmake -DCMAKE_OSX_ARCHITECTURES="x86_64;arm64" ..
5252
make -j$(getconf _NPROCESSORS_ONLN)
53+
(cd .. && build/qjs amalgam.js build/quickjs-amalgam.c)
54+
cp ../quickjs.h .
55+
zip -9 quickjs-amalgam.zip quickjs-amalgam.c quickjs.h
5356
mv qjs qjs-darwin
5457
mv qjsc qjsc-darwin
5558
- name: check
5659
run: |
5760
lipo -info build/qjs-darwin build/qjsc-darwin
61+
- name: upload amalgamation
62+
uses: actions/upload-artifact@v4
63+
with:
64+
name: quickjs-amalgam.zip
65+
path: build/quickjs-amalgam.zip
66+
compression-level: 0 # already compressed
5867
- name: upload
5968
uses: actions/upload-artifact@v4
6069
with:
@@ -124,7 +133,7 @@ jobs:
124133
- name: get assets
125134
uses: actions/download-artifact@v4
126135
with:
127-
pattern: qjs-*
136+
pattern: *
128137
path: build
129138
merge-multiple: true
130139
- run: ls -R build

amalgam.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import {loadFile, writeFile} from "qjs:std"
2+
3+
const cutils_c = loadFile("cutils.c")
4+
const cutils_h = loadFile("cutils.h")
5+
const libbf_c = loadFile("libbf.c")
6+
const libbf_h = loadFile("libbf.h")
7+
const libregexp_c = loadFile("libregexp.c")
8+
const libregexp_h = loadFile("libregexp.h")
9+
const libregexp_opcode_h = loadFile("libregexp-opcode.h")
10+
const libunicode_c = loadFile("libunicode.c")
11+
const libunicode_h = loadFile("libunicode.h")
12+
const libunicode_table_h = loadFile("libunicode-table.h")
13+
const list_h = loadFile("list.h")
14+
const quickjs_atom_h = loadFile("quickjs-atom.h")
15+
const quickjs_c = loadFile("quickjs.c")
16+
const quickjs_c_atomics_h = loadFile("quickjs-c-atomics.h")
17+
const quickjs_h = loadFile("quickjs.h")
18+
const quickjs_libc_c = loadFile("quickjs-libc.c")
19+
const quickjs_libc_h = loadFile("quickjs-libc.h")
20+
const quickjs_opcode_h = loadFile("quickjs-opcode.h")
21+
22+
let source = "#if defined(QJS_BUILD_LIBC) && defined(__linux__) && !defined(_GNU_SOURCE)\n"
23+
+ "#define _GNU_SOURCE\n"
24+
+ "#endif\n"
25+
+ quickjs_c_atomics_h
26+
+ cutils_h
27+
+ list_h
28+
+ libbf_h
29+
+ libunicode_h // exports lre_is_id_start, used by libregexp.h
30+
+ libregexp_h
31+
+ libunicode_table_h
32+
+ quickjs_h
33+
+ quickjs_c
34+
+ cutils_c
35+
+ libbf_c
36+
+ libregexp_c
37+
+ libunicode_c
38+
+ "#ifdef QJS_BUILD_LIBC\n"
39+
+ quickjs_libc_h
40+
+ quickjs_libc_c
41+
+ "#endif // QJS_BUILD_LIBC\n"
42+
source = source.replace(/#include "quickjs-atom.h"/g, quickjs_atom_h)
43+
source = source.replace(/#include "quickjs-opcode.h"/g, quickjs_opcode_h)
44+
source = source.replace(/#include "libregexp-opcode.h"/g, libregexp_opcode_h)
45+
source = source.replace(/#include "[^"]+"/g, "")
46+
writeFile(execArgv[2] ?? "quickjs-amalgam.c", source)

quickjs-libc.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,9 @@ extern char **environ;
9494
#include "list.h"
9595
#include "quickjs-libc.h"
9696

97+
#ifndef MAX_SAFE_INTEGER // already defined in amalgamation builds
9798
#define MAX_SAFE_INTEGER (((int64_t) 1 << 53) - 1)
99+
#endif
98100

99101
#ifndef QJS_NATIVE_MODULE_SUFFIX
100102
#ifdef _WIN32

0 commit comments

Comments
 (0)