1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
|
From: Yadd <yadd@debian.org>
Date: Mon, 1 Dec 2025 21:24:25 +0100
Subject: use binaries from Debian packages
Forwarded: not-needed
Last-Update: 2023-09-14
---
inwasm/src/cli.ts | 2 +-
inwasm/src/config.ts | 16 ++++------------
inwasm/src/runners/clang_c.ts | 12 +++++++-----
inwasm/src/runners/emscripten_c.ts | 17 ++++++++---------
inwasm/tsconfig.json | 4 +++-
testproject/custom/build.sh | 6 +-----
6 files changed, 24 insertions(+), 33 deletions(-)
diff --git a/inwasm/src/cli.ts b/inwasm/src/cli.ts
index a044fc9..dec2b5b 100644
--- a/inwasm/src/cli.ts
+++ b/inwasm/src/cli.ts
@@ -649,7 +649,7 @@ async function main(): Promise<number> {
return 1;
}
// minimal globbing support to work around window shell limitations
- const files = args.length === 1 && hasMagic(args, { magicalBraces: true })
+ const files = args.length === 1 && hasMagic(args[0])
? globSync(args[0])
: args;
const startTime = Date.now();
diff --git a/inwasm/src/config.ts b/inwasm/src/config.ts
index 16642af..2a13560 100644
--- a/inwasm/src/config.ts
+++ b/inwasm/src/config.ts
@@ -93,7 +93,7 @@ function getProjectRoot(): string {
let folder = process.env.PWD || process.cwd();
let found = '';
while (folder !== path.dirname(folder)) {
- if (fs.existsSync(path.join(folder, 'package.json')) && fs.existsSync(path.join(folder, 'node_modules'))) {
+ if (fs.existsSync(path.join(folder, 'package.json'))) {
found = folder;
break;
};
@@ -184,18 +184,10 @@ function getConfig(): IConfig {
}
export const CONFIG = getConfig();
-
-function getWabtPath(): string {
- const inApp = path.join(APP_ROOT, 'node_modules', 'wabt', 'bin');
- if (fs.existsSync(inApp)) {
- return inApp;
- }
- return path.join(PROJECT_ROOT, 'node_modules', 'wabt', 'bin');
-}
-export const WABT_PATH = getWabtPath();
+export const WABT_PATH = '/usr/bin';
// shell to be executed
-export const SHELL = process.platform === 'win32' ? 'cmd.exe' : execSync('which bash', {encoding: 'utf-8'}).trim();
+export const SHELL = '/bin/bash';
// simply assume any OS != windows being POSIX compatible
export const isPosix = process.platform !== 'win32';
@@ -214,7 +206,7 @@ interface IWabtToolPath {
// wabt tool path abstraction
function getWabtTool(): IWabtToolPath {
- const p = (name: string) => `"${process.execPath}" "${path.join(getWabtPath(), name)}"`;
+ const p = (name: string) => `/usr/bin/${name}`;
return {
'wasm2c': p('wasm2c'),
'wasm-decompile': p('wasm-decompile'),
diff --git a/inwasm/src/runners/clang_c.ts b/inwasm/src/runners/clang_c.ts
index de4685f..2e0b2be 100644
--- a/inwasm/src/runners/clang_c.ts
+++ b/inwasm/src/runners/clang_c.ts
@@ -1,7 +1,8 @@
import * as fs from 'fs';
import * as path from 'path';
-import { emscriptenRun, getClangBinPath } from '../sdks/emscripten';
+//import { emscriptenRun, getClangBinPath } from '../sdks/emscripten';
import { IMemorySettings, IWasmDefinition } from '..';
+import { spawnSync } from 'child_process';
/**
@@ -31,7 +32,7 @@ export default function(def: IWasmDefinition, buildDir: string, filename: string
// TODO: apply compile options properly
const opt = `-O3`;
const defines = Object.entries(def.compile?.defines || {})
- .map(el => `-D${el[0]}=${el[1]}`).join(' ');
+ .map(el => `-D${el[0]}=${el[1]}`);
let switches: string[] = [];
// memory settings
@@ -56,8 +57,9 @@ export default function(def: IWasmDefinition, buildDir: string, filename: string
.filter(el => typeof el[1] === 'function' || el[1] instanceof WebAssembly.Global)
.map(el => `--export=${el[0]}`)
.join(',');
- const clang = path.join(getClangBinPath(), 'clang');
- const call = `${clang} --target=wasm32-unknown-unknown --no-standard-libraries -Wl,${ff} -Wl,--no-entry -Wl,--lto-O3 ${opt} ${switches.join(' ')} -flto ${defines} -o ${target} ${src}`;
- emscriptenRun(call);
+ const clang = '/usr/bin/clang';
+ console.log(`${clang} --target=wasm32-unknown-unknown --no-standard-libraries -Wl,${ff} -Wl,--no-entry -Wl,--lto-O3 ${opt} ${switches.join(' ')} -flto ${defines} -o ${target} ${src}`);
+ const res = spawnSync( clang, ['--target=wasm32-unknown-unknown', '--no-standard-libraries', `-Wl,${ff}`, '-Wl,--no-entry', '-Wl,--lto-O3', opt, ...switches, '-flto', ...defines, '-o', target, src] );
+ if (res.stderr) console.log(res.stderr.toString());
return fs.readFileSync(target);
}
diff --git a/inwasm/src/runners/emscripten_c.ts b/inwasm/src/runners/emscripten_c.ts
index 216492a..02fdac0 100644
--- a/inwasm/src/runners/emscripten_c.ts
+++ b/inwasm/src/runners/emscripten_c.ts
@@ -1,9 +1,8 @@
import * as fs from 'fs';
import * as path from 'path';
-import { emscriptenRun, getEmscriptenPath } from '../sdks/emscripten';
+//import { emscriptenRun, getEmscriptenPath } from '../sdks/emscripten';
import { IMemorySettings, IWasmDefinition } from '..';
-import { isPosix } from '../config';
-
+import { spawnSync } from 'child_process';
export default function(def: IWasmDefinition, buildDir: string, filename: string, memorySettings: IMemorySettings): Uint8Array {
// TODO: copy additional files
@@ -14,7 +13,7 @@ export default function(def: IWasmDefinition, buildDir: string, filename: string
// TODO: apply compile options properly
const opt = `-O3`;
const defines = Object.entries(def.compile?.defines || {})
- .map(el => `-D${el[0]}=${el[1]}`).join(' ');
+ .map(el => `-D${el[0]}=${el[1]}`);
const _funcs = Object.entries(def.exports)
.filter(el => typeof el[1] === 'function')
.map(el => `_${el[0]}`)
@@ -45,10 +44,10 @@ export default function(def: IWasmDefinition, buildDir: string, filename: string
// FIXME:
switches.push(...['-s ERROR_ON_UNDEFINED_SYMBOLS=0', '-s WARN_ON_UNDEFINED_SYMBOLS=0']);
- const funcs = `-s EXPORTED_FUNCTIONS=${_funcs}`;
- // FIXME: for unknown reason windows shell cannot find emcc, thus give path explicitly
- const bin = isPosix ? 'emcc' : path.join(getEmscriptenPath(), 'upstream', 'emscripten', 'emcc.bat');
- const call = `${bin} ${opt} ${defines} ${funcs} ${switches.join(' ')} --no-entry ${src} -o ${target}`;
- emscriptenRun(call);
+ const funcs = ['-s', `EXPORTED_FUNCTIONS=${_funcs}`];
+ const bin = '/usr/bin/emcc';
+ console.log(`${bin} ${opt} ${defines} ${funcs.join(' ')} ${switches.join(' ')} --no-entry ${src} -o ${target}`);
+ const res = spawnSync( bin, [ opt, ...defines, ...funcs, ...switches, '--no-entry', src, '-o', target ] );
+ if (res.stderr) console.log(res.stderr.toString());
return fs.readFileSync(target);
}
diff --git a/inwasm/tsconfig.json b/inwasm/tsconfig.json
index ed1ed6c..97810b2 100644
--- a/inwasm/tsconfig.json
+++ b/inwasm/tsconfig.json
@@ -5,13 +5,15 @@
"rootDir": "src",
"outDir": "lib",
"sourceMap": true,
+ "esModuleInterop": true,
"declaration": true,
"noImplicitAny": true,
"strict": true,
"removeComments": false
},
"exclude": [
+ "**/*.test-d.ts",
"node_modules",
"lib"
]
-}
\ No newline at end of file
+}
diff --git a/testproject/custom/build.sh b/testproject/custom/build.sh
index 2efaa38..9eef03a 100755
--- a/testproject/custom/build.sh
+++ b/testproject/custom/build.sh
@@ -1,8 +1,4 @@
#!/usr/bin/env bash
# some custom build steps (just calling wat2wasm for simplicity)
-if [ -d "../node_modules/inwasm/node_modules/wabt/bin/" ]; then
- ../node_modules/inwasm/node_modules/wabt/bin/wat2wasm module.wat
-else
- ../node_modules/wabt/bin/wat2wasm module.wat
-fi
+wat2wasm module.wat
|