emsdk-env 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{build-B0LjpT0A.js → build-Btgi1orl.js} +70 -3
- package/dist/{build-B0LjpT0A.js.map → build-Btgi1orl.js.map} +1 -1
- package/dist/{build-C7VNCGou.cjs → build-CjKDHGn4.cjs} +70 -3
- package/dist/{build-C7VNCGou.cjs.map → build-CjKDHGn4.cjs.map} +1 -1
- package/dist/index.cjs +3 -3
- package/dist/index.d.ts +24 -2
- package/dist/index.mjs +3 -3
- package/dist/vite.cjs +5 -5
- package/dist/vite.cjs.map +1 -1
- package/dist/vite.d.ts +24 -2
- package/dist/vite.mjs +5 -5
- package/dist/vite.mjs.map +1 -1
- package/package.json +7 -7
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
* name: emsdk-env
|
|
3
|
-
* version: 0.
|
|
3
|
+
* version: 0.7.0
|
|
4
4
|
* description: Emscripten environment builder
|
|
5
5
|
* author: Kouji Matsui (@kekyo@mi.kekyo.net)
|
|
6
6
|
* license: MIT
|
|
7
7
|
* repository.url: https://github.com/kekyo/emsdk-env
|
|
8
|
-
* git.commit.hash:
|
|
8
|
+
* git.commit.hash: ddec7e7cc6c59a23b5c87cbd7f99f44e4da3e4b7
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
import { mkdir, access, constants, mkdtemp, rename, rm, readFile } from "fs/promises";
|
|
@@ -517,6 +517,24 @@ const resolveEmarCommand = async (env, emsdkRoot) => {
|
|
|
517
517
|
}
|
|
518
518
|
return "emar";
|
|
519
519
|
};
|
|
520
|
+
const resolveWasmOptCommand = async (env, emsdkRoot) => {
|
|
521
|
+
var _a;
|
|
522
|
+
if (env.WASM_OPT) {
|
|
523
|
+
return env.WASM_OPT;
|
|
524
|
+
}
|
|
525
|
+
const binaryenRoot = (_a = env.BINARYEN_ROOT) != null ? _a : env.BINARYEN;
|
|
526
|
+
if (binaryenRoot) {
|
|
527
|
+
const candidate = join(binaryenRoot, "bin", "wasm-opt");
|
|
528
|
+
if (await pathExists(candidate)) {
|
|
529
|
+
return candidate;
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
const fallback = join(emsdkRoot, "upstream", "bin", "wasm-opt");
|
|
533
|
+
if (await pathExists(fallback)) {
|
|
534
|
+
return fallback;
|
|
535
|
+
}
|
|
536
|
+
return "wasm-opt";
|
|
537
|
+
};
|
|
520
538
|
const createConsoleLogger = (prefix) => {
|
|
521
539
|
return {
|
|
522
540
|
debug: (msg) => console.debug(`[${prefix}]: ${msg}`),
|
|
@@ -533,6 +551,7 @@ const DEFAULT_IMPORT_INCLUDE_DIR = "include";
|
|
|
533
551
|
const DEFAULT_IMPORT_LIB_DIR = "lib";
|
|
534
552
|
const DEFAULT_WASM_BUILD_DIR = join(tmpdir(), "emsdk-env");
|
|
535
553
|
const DEFAULT_EMSDK_TARGET_VERSION = "latest";
|
|
554
|
+
const DEFAULT_WASM_OPT_ARGS = ["-Oz"];
|
|
536
555
|
let buildSequence = 0;
|
|
537
556
|
const padNumber = (value, length = 2) => String(value).padStart(length, "0");
|
|
538
557
|
const formatTimestamp = (date) => {
|
|
@@ -563,6 +582,17 @@ const mergeDefines = (common, target) => ({
|
|
|
563
582
|
...common != null ? common : {},
|
|
564
583
|
...target != null ? target : {}
|
|
565
584
|
});
|
|
585
|
+
const resolveWasmOptEnabled = (common, target) => {
|
|
586
|
+
var _a, _b;
|
|
587
|
+
return (_b = (_a = target == null ? void 0 : target.enable) != null ? _a : common == null ? void 0 : common.enable) != null ? _b : false;
|
|
588
|
+
};
|
|
589
|
+
const resolveWasmOptArgs = (common, target, env) => {
|
|
590
|
+
var _a, _b;
|
|
591
|
+
const commonArgs = (_a = common == null ? void 0 : common.args) != null ? _a : DEFAULT_WASM_OPT_ARGS;
|
|
592
|
+
const targetArgs = (_b = target == null ? void 0 : target.args) != null ? _b : [];
|
|
593
|
+
const mergedArgs = [...commonArgs, ...targetArgs];
|
|
594
|
+
return expandArray(mergedArgs, env, "wasmOpt.args");
|
|
595
|
+
};
|
|
566
596
|
const resolvePath = (rootDir, value) => isAbsolute(value) ? value : resolve(rootDir, value);
|
|
567
597
|
const expandPlaceholders = (value, env, label) => value.replace(/\{([A-Z0-9_]+)\}/g, (_match, key) => {
|
|
568
598
|
const replacement = env[key];
|
|
@@ -864,6 +894,15 @@ const buildWasm = async (options) => {
|
|
|
864
894
|
if (emarCommand) {
|
|
865
895
|
logger.debug(`Detected emarCommand: '${emarCommand}'`);
|
|
866
896
|
}
|
|
897
|
+
let wasmOptCommand;
|
|
898
|
+
const getWasmOptCommand = async () => {
|
|
899
|
+
if (wasmOptCommand) {
|
|
900
|
+
return wasmOptCommand;
|
|
901
|
+
}
|
|
902
|
+
wasmOptCommand = await resolveWasmOptCommand(envWithDirs, emsdkRoot);
|
|
903
|
+
logger.debug(`Detected wasmOptCommand: '${wasmOptCommand}'`);
|
|
904
|
+
return wasmOptCommand;
|
|
905
|
+
};
|
|
867
906
|
const outFiles = {};
|
|
868
907
|
const buildTargets = async (expectedType) => {
|
|
869
908
|
var _a2;
|
|
@@ -883,12 +922,18 @@ const buildWasm = async (options) => {
|
|
|
883
922
|
`exports is not supported for archive target: ${targetName}`
|
|
884
923
|
);
|
|
885
924
|
}
|
|
925
|
+
if (target.wasmOpt !== void 0) {
|
|
926
|
+
throw new Error(
|
|
927
|
+
`wasmOpt is not supported for archive target: ${targetName}`
|
|
928
|
+
);
|
|
929
|
+
}
|
|
886
930
|
}
|
|
887
931
|
const mergedLinkOptions = targetType === "archive" ? [] : [
|
|
888
932
|
...ensureArray(common.linkOptions),
|
|
889
933
|
...ensureArray(target.linkOptions)
|
|
890
934
|
];
|
|
891
935
|
const mergedExports = targetType === "archive" ? [] : [...ensureArray(common.exports), ...ensureArray(target.exports)];
|
|
936
|
+
const wasmOptEnabled = targetType === "archive" ? false : resolveWasmOptEnabled(common.wasmOpt, target.wasmOpt);
|
|
892
937
|
const baseCompileOptions = [
|
|
893
938
|
...ensureArray(common.options),
|
|
894
939
|
...ensureArray(target.options)
|
|
@@ -949,6 +994,7 @@ const buildWasm = async (options) => {
|
|
|
949
994
|
const resolvedLinkOptions = targetType === "archive" ? [] : expandArray(mergedLinkOptions, targetEnv, "linkOptions");
|
|
950
995
|
const resolvedExports = targetType === "archive" ? [] : expandArray(mergedExports, targetEnv, "exports");
|
|
951
996
|
const exportArgs = buildExportFlags(resolvedExports);
|
|
997
|
+
const resolvedWasmOptArgs = wasmOptEnabled ? resolveWasmOptArgs(common.wasmOpt, target.wasmOpt, targetEnv) : [];
|
|
952
998
|
const baseCompileArgs = buildCompileArgs(
|
|
953
999
|
baseCompileOptions,
|
|
954
1000
|
baseIncludeDirs,
|
|
@@ -1082,6 +1128,27 @@ const buildWasm = async (options) => {
|
|
|
1082
1128
|
buildEnv,
|
|
1083
1129
|
emsdkOptions.signal
|
|
1084
1130
|
);
|
|
1131
|
+
if (wasmOptEnabled) {
|
|
1132
|
+
const tempOutFile = `${resolvedOutFile}.opt`;
|
|
1133
|
+
const wasmOptArgs = [
|
|
1134
|
+
resolvedOutFile,
|
|
1135
|
+
"-o",
|
|
1136
|
+
tempOutFile,
|
|
1137
|
+
...resolvedWasmOptArgs
|
|
1138
|
+
];
|
|
1139
|
+
const wasmOptCommand2 = await getWasmOptCommand();
|
|
1140
|
+
logger.info(`Optimizing target: ${targetName}.wasm`);
|
|
1141
|
+
logger.debug(`wasm-opt ${wasmOptArgs.join(" ")}`);
|
|
1142
|
+
await runCommandWithEnv(
|
|
1143
|
+
wasmOptCommand2,
|
|
1144
|
+
wasmOptArgs,
|
|
1145
|
+
rootDir,
|
|
1146
|
+
buildEnv,
|
|
1147
|
+
emsdkOptions.signal
|
|
1148
|
+
);
|
|
1149
|
+
await rm(resolvedOutFile, { force: true });
|
|
1150
|
+
await rename(tempOutFile, resolvedOutFile);
|
|
1151
|
+
}
|
|
1085
1152
|
}
|
|
1086
1153
|
outFiles[targetName] = resolvedOutFile;
|
|
1087
1154
|
}
|
|
@@ -1104,4 +1171,4 @@ export {
|
|
|
1104
1171
|
createConsoleLogger as c,
|
|
1105
1172
|
prepareEmsdk as p
|
|
1106
1173
|
};
|
|
1107
|
-
//# sourceMappingURL=build-
|
|
1174
|
+
//# sourceMappingURL=build-Btgi1orl.js.map
|