Skip to content

Commit 823614d

Browse files
committed
feat: Add DuckDB Support
Replace rollup.js with esbuild Signed-off-by: Gordon Smith <GordonJSmith@gmail.com>
1 parent cd488e4 commit 823614d

File tree

16 files changed

+1022
-511
lines changed

16 files changed

+1022
-511
lines changed

.vscode/launch.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,14 @@
8787
],
8888
},
8989
{
90-
"name": "cli rollup wasm",
91-
"program": "${workspaceFolder}/output-node/test-wasm.js",
90+
"name": "esbuild",
91+
"type": "node",
92+
"program": "${workspaceFolder}/esbuild.mjs",
9293
"request": "launch",
9394
"args": [],
9495
"skipFiles": [
9596
"<node_internals>/**"
96-
],
97-
"type": "node"
97+
]
9898
},
9999
{
100100
"name": "CLI",

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
This repository contains a collection of useful c++ libraries compiled to WASM for (re)use in Node JS, Web Browsers and JavaScript Libraries:
99
- [base91](https://base91.sourceforge.net/) - v0.6.0
10+
- [duckdb](https://github.com/duckdb/duckdb-wasm) - v1.28.1-dev106.0
1011
- [expat](https://libexpat.github.io/) - v2.6.2
1112
- [graphviz](https://www.graphviz.org/) - v11.0.0
1213
- [zstd](https://github.com/facebook/zstd) - v1.5.5
@@ -19,6 +20,7 @@ Built with:
1920

2021
* [Homepage](https://hpcc-systems.github.io/hpcc-js-wasm/)
2122
* [Base91](https://hpcc-systems.github.io/hpcc-js-wasm/classes/base91.Base91.html)
23+
* [DuckDB](https://hpcc-systems.github.io/hpcc-js-wasm/classes/duckdb.DuckDB.html)
2224
* [Expat](https://hpcc-systems.github.io/hpcc-js-wasm/classes/expat.Expat.html)
2325
* [Graphviz](https://hpcc-systems.github.io/hpcc-js-wasm/classes/graphviz.Graphviz.html)
2426
* [Zstd](https://hpcc-systems.github.io/hpcc-js-wasm/classes/zstd.Zstd.html)

docker/ubuntu-dev.dockerfile

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,20 @@ RUN apt-get install -y nodejs
2323
# Set the working directory
2424
WORKDIR /usr/src-ts/app
2525

26-
COPY ./*.* .
27-
RUN npm ci
28-
2926
COPY ./scripts ./scripts
27+
RUN ./scripts/cpp-install-emsdk.sh
28+
3029
COPY ./vcpkg-overlays ./vcpkg-overlays
31-
RUN npm run install-build-deps
30+
COPY ./vcpkg-configuration.json ./vcpkg-configuration.json
31+
COPY ./vcpkg.json ./vcpkg.json
32+
RUN ./scripts/cpp-install-vcpkg.sh
33+
34+
COPY ./package*.json .
35+
RUN npm ci
3236

37+
COPY ./src-asm ./src-asm
3338
COPY ./src-cpp ./src-cpp
3439
COPY ./src-ts ./src-ts
3540
COPY ./utils ./utils
36-
RUN npm run build
3741

3842
CMD ["npm", "run", "test-node"]

docs/.vitepress/config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export default {
3535
text: 'WASM API',
3636
items: [
3737
{ text: 'Base91', link: '/classes/base91.Base91' },
38+
{ text: 'DuckDB', link: '/classes/duckdb.DuckDB' },
3839
{ text: 'Expat', link: '/classes/expat.Expat' },
3940
{ text: 'Graphviz', link: '/classes/graphviz.Graphviz' },
4041
{ text: 'Zstd', link: '/classes/zstd.Zstd' },

docs/index.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ features:
2626
- title: Base 91
2727
details: Similar to Base 64 but uses more characters resulting in smaller strings.
2828
link: /classes/base91.Base91
29+
- title: DuckDB
30+
details: DuckDB - a fast in-process analytical database.
31+
link: /classes/duckdb.DuckDB
2932
- title: Expat
3033
details: A popular stream-oriented XML parser library.
3134
link: /classes/expat.Expat

esbuild.mjs

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
import * as process from "process";
2+
import * as esbuild from "esbuild";
3+
import { umdWrapper } from "esbuild-plugin-umd-wrapper";
4+
import yargs from "yargs";
5+
import { hideBin } from "yargs/helpers";
6+
7+
const myYargs = yargs(hideBin(process.argv));
8+
myYargs
9+
.usage("Usage: esbuild [options]")
10+
.demandCommand(0, 0)
11+
.example("sfx-wasm --watch", "Bundle and watch for changes")
12+
.option("d", {
13+
alias: "debug",
14+
describe: "Debug build",
15+
boolean: true
16+
})
17+
.option("w", {
18+
alias: "watch",
19+
describe: "Watch for changes",
20+
boolean: true
21+
})
22+
.help("h")
23+
.alias("h", "help")
24+
.epilog("https://github.com/hpcc-systems/hpcc-js-wasm")
25+
;
26+
const argv = await myYargs.argv;
27+
28+
function build(config) {
29+
return esbuild.build({
30+
...config,
31+
sourcemap: true
32+
});
33+
}
34+
35+
async function watch(config) {
36+
const ctx = await esbuild.context({
37+
...config,
38+
sourcemap: "external",
39+
plugins: [...config.plugins ?? {}, {
40+
name: "rebuild-notify",
41+
setup(build) {
42+
build.onEnd(result => {
43+
console.log(`Built ${config.outfile}`);
44+
});
45+
},
46+
}]
47+
});
48+
await ctx.watch();
49+
}
50+
51+
function browserTpl(input, umdOutput, esOutput, globalName = undefined, external = []) {
52+
const entryPoints = [input + ".js"];
53+
const promises = [];
54+
promises.push((argv.watch ? watch : build)({
55+
entryPoints,
56+
outfile: esOutput + ".js",
57+
platform: "browser",
58+
format: "esm",
59+
bundle: true,
60+
minify: !argv.debug,
61+
external
62+
}));
63+
if (globalName) {
64+
promises.push((argv.watch ? watch : build)({
65+
entryPoints,
66+
outfile: umdOutput + ".js",
67+
platform: "browser",
68+
format: "umd",
69+
globalName,
70+
bundle: true,
71+
minify: !argv.debug,
72+
external,
73+
plugins: [umdWrapper()]
74+
}));
75+
}
76+
return Promise.all(promises);
77+
}
78+
79+
function nodeEsm(input, esOutput, external = [], extension = ".js") {
80+
const entryPoints = [input + ".js"];
81+
return (argv.watch ? watch : build)({
82+
entryPoints,
83+
outfile: esOutput + extension,
84+
platform: "node",
85+
format: "esm",
86+
bundle: true,
87+
minify: !argv.debug,
88+
external
89+
});
90+
}
91+
92+
function nodeCjs(input, esOutput, external = []) {
93+
const entryPoints = [input + ".js"];
94+
return (argv.watch ? watch : build)({
95+
entryPoints,
96+
outfile: esOutput + ".cjs",
97+
platform: "node",
98+
format: "cjs",
99+
bundle: true,
100+
minify: !argv.debug,
101+
external
102+
});
103+
}
104+
105+
function nodeTpl(input, esOutput, external = []) {
106+
return Promise.all([
107+
nodeEsm(input, esOutput, external),
108+
nodeCjs(input, esOutput, external)
109+
]);
110+
}
111+
112+
function bothTpl(input, umdOutput, esOutput, globalName = undefined, external = []) {
113+
return Promise.all([
114+
browserTpl(input, umdOutput, esOutput, globalName, external),
115+
nodeTpl(input, esOutput, external)
116+
]);
117+
}
118+
119+
await Promise.all([
120+
bothTpl("lib-esm/base91", "dist/base91.umd", "dist/base91", "hpccjs_wasm_base91"),
121+
bothTpl("lib-esm/duckdb", "dist/duckdb.umd", "dist/duckdb", "hpccjs_wasm_duckdb"),
122+
bothTpl("lib-esm/graphviz", "dist/graphviz.umd", "dist/graphviz", "hpccjs_wasm_graphviz"),
123+
bothTpl("lib-esm/expat", "dist/expat.umd", "dist/expat", "hpccjs_wasm_expat"),
124+
bothTpl("lib-esm/zstd", "dist/zstd.umd", "dist/zstd", "hpccjs_wasm_zstd")
125+
]);
126+
await bothTpl("lib-esm/index", "dist/index.umd", "dist/index", "hpccjs_wasm", ["./base91.js", "./duckdb.js", "./expat.js", "./graphviz.js", "./zstd.js"]);
127+
128+
await browserTpl("lib-esm/__tests__/index-browser", "dist-test/index.umd", "dist-test/index", "hpccjs_wasm_test");
129+
await browserTpl("lib-esm/__tests__/worker-browser", "dist-test/worker.umd", "dist-test/worker", "hpccjs_wasm_test_worker");
130+
await nodeTpl("lib-esm/__tests__/index-node", "dist-test/index.node");
131+
await nodeTpl("lib-esm/__tests__/worker-node", "dist-test/worker.node");
132+
133+
await nodeEsm("lib-esm/__bin__/dot-wasm", "bin/dot-wasm", ["@hpcc-js/wasm/graphviz"], ".js");

0 commit comments

Comments
 (0)