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
|
"use strict";
|
|
@@ -540,6 +540,24 @@ const resolveEmarCommand = async (env, emsdkRoot) => {
|
|
|
540
540
|
}
|
|
541
541
|
return "emar";
|
|
542
542
|
};
|
|
543
|
+
const resolveWasmOptCommand = async (env, emsdkRoot) => {
|
|
544
|
+
var _a;
|
|
545
|
+
if (env.WASM_OPT) {
|
|
546
|
+
return env.WASM_OPT;
|
|
547
|
+
}
|
|
548
|
+
const binaryenRoot = (_a = env.BINARYEN_ROOT) != null ? _a : env.BINARYEN;
|
|
549
|
+
if (binaryenRoot) {
|
|
550
|
+
const candidate = path.join(binaryenRoot, "bin", "wasm-opt");
|
|
551
|
+
if (await pathExists(candidate)) {
|
|
552
|
+
return candidate;
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
const fallback = path.join(emsdkRoot, "upstream", "bin", "wasm-opt");
|
|
556
|
+
if (await pathExists(fallback)) {
|
|
557
|
+
return fallback;
|
|
558
|
+
}
|
|
559
|
+
return "wasm-opt";
|
|
560
|
+
};
|
|
543
561
|
const createConsoleLogger = (prefix) => {
|
|
544
562
|
return {
|
|
545
563
|
debug: (msg) => console.debug(`[${prefix}]: ${msg}`),
|
|
@@ -556,6 +574,7 @@ const DEFAULT_IMPORT_INCLUDE_DIR = "include";
|
|
|
556
574
|
const DEFAULT_IMPORT_LIB_DIR = "lib";
|
|
557
575
|
const DEFAULT_WASM_BUILD_DIR = path.join(os.tmpdir(), "emsdk-env");
|
|
558
576
|
const DEFAULT_EMSDK_TARGET_VERSION = "latest";
|
|
577
|
+
const DEFAULT_WASM_OPT_ARGS = ["-Oz"];
|
|
559
578
|
let buildSequence = 0;
|
|
560
579
|
const padNumber = (value, length = 2) => String(value).padStart(length, "0");
|
|
561
580
|
const formatTimestamp = (date) => {
|
|
@@ -586,6 +605,17 @@ const mergeDefines = (common, target) => ({
|
|
|
586
605
|
...common != null ? common : {},
|
|
587
606
|
...target != null ? target : {}
|
|
588
607
|
});
|
|
608
|
+
const resolveWasmOptEnabled = (common, target) => {
|
|
609
|
+
var _a, _b;
|
|
610
|
+
return (_b = (_a = target == null ? void 0 : target.enable) != null ? _a : common == null ? void 0 : common.enable) != null ? _b : false;
|
|
611
|
+
};
|
|
612
|
+
const resolveWasmOptArgs = (common, target, env) => {
|
|
613
|
+
var _a, _b;
|
|
614
|
+
const commonArgs = (_a = common == null ? void 0 : common.args) != null ? _a : DEFAULT_WASM_OPT_ARGS;
|
|
615
|
+
const targetArgs = (_b = target == null ? void 0 : target.args) != null ? _b : [];
|
|
616
|
+
const mergedArgs = [...commonArgs, ...targetArgs];
|
|
617
|
+
return expandArray(mergedArgs, env, "wasmOpt.args");
|
|
618
|
+
};
|
|
589
619
|
const resolvePath = (rootDir, value) => path.isAbsolute(value) ? value : path.resolve(rootDir, value);
|
|
590
620
|
const expandPlaceholders = (value, env, label) => value.replace(/\{([A-Z0-9_]+)\}/g, (_match, key) => {
|
|
591
621
|
const replacement = env[key];
|
|
@@ -887,6 +917,15 @@ const buildWasm = async (options) => {
|
|
|
887
917
|
if (emarCommand) {
|
|
888
918
|
logger.debug(`Detected emarCommand: '${emarCommand}'`);
|
|
889
919
|
}
|
|
920
|
+
let wasmOptCommand;
|
|
921
|
+
const getWasmOptCommand = async () => {
|
|
922
|
+
if (wasmOptCommand) {
|
|
923
|
+
return wasmOptCommand;
|
|
924
|
+
}
|
|
925
|
+
wasmOptCommand = await resolveWasmOptCommand(envWithDirs, emsdkRoot);
|
|
926
|
+
logger.debug(`Detected wasmOptCommand: '${wasmOptCommand}'`);
|
|
927
|
+
return wasmOptCommand;
|
|
928
|
+
};
|
|
890
929
|
const outFiles = {};
|
|
891
930
|
const buildTargets = async (expectedType) => {
|
|
892
931
|
var _a2;
|
|
@@ -906,12 +945,18 @@ const buildWasm = async (options) => {
|
|
|
906
945
|
`exports is not supported for archive target: ${targetName}`
|
|
907
946
|
);
|
|
908
947
|
}
|
|
948
|
+
if (target.wasmOpt !== void 0) {
|
|
949
|
+
throw new Error(
|
|
950
|
+
`wasmOpt is not supported for archive target: ${targetName}`
|
|
951
|
+
);
|
|
952
|
+
}
|
|
909
953
|
}
|
|
910
954
|
const mergedLinkOptions = targetType === "archive" ? [] : [
|
|
911
955
|
...ensureArray(common.linkOptions),
|
|
912
956
|
...ensureArray(target.linkOptions)
|
|
913
957
|
];
|
|
914
958
|
const mergedExports = targetType === "archive" ? [] : [...ensureArray(common.exports), ...ensureArray(target.exports)];
|
|
959
|
+
const wasmOptEnabled = targetType === "archive" ? false : resolveWasmOptEnabled(common.wasmOpt, target.wasmOpt);
|
|
915
960
|
const baseCompileOptions = [
|
|
916
961
|
...ensureArray(common.options),
|
|
917
962
|
...ensureArray(target.options)
|
|
@@ -972,6 +1017,7 @@ const buildWasm = async (options) => {
|
|
|
972
1017
|
const resolvedLinkOptions = targetType === "archive" ? [] : expandArray(mergedLinkOptions, targetEnv, "linkOptions");
|
|
973
1018
|
const resolvedExports = targetType === "archive" ? [] : expandArray(mergedExports, targetEnv, "exports");
|
|
974
1019
|
const exportArgs = buildExportFlags(resolvedExports);
|
|
1020
|
+
const resolvedWasmOptArgs = wasmOptEnabled ? resolveWasmOptArgs(common.wasmOpt, target.wasmOpt, targetEnv) : [];
|
|
975
1021
|
const baseCompileArgs = buildCompileArgs(
|
|
976
1022
|
baseCompileOptions,
|
|
977
1023
|
baseIncludeDirs,
|
|
@@ -1105,6 +1151,27 @@ const buildWasm = async (options) => {
|
|
|
1105
1151
|
buildEnv,
|
|
1106
1152
|
emsdkOptions.signal
|
|
1107
1153
|
);
|
|
1154
|
+
if (wasmOptEnabled) {
|
|
1155
|
+
const tempOutFile = `${resolvedOutFile}.opt`;
|
|
1156
|
+
const wasmOptArgs = [
|
|
1157
|
+
resolvedOutFile,
|
|
1158
|
+
"-o",
|
|
1159
|
+
tempOutFile,
|
|
1160
|
+
...resolvedWasmOptArgs
|
|
1161
|
+
];
|
|
1162
|
+
const wasmOptCommand2 = await getWasmOptCommand();
|
|
1163
|
+
logger.info(`Optimizing target: ${targetName}.wasm`);
|
|
1164
|
+
logger.debug(`wasm-opt ${wasmOptArgs.join(" ")}`);
|
|
1165
|
+
await runCommandWithEnv(
|
|
1166
|
+
wasmOptCommand2,
|
|
1167
|
+
wasmOptArgs,
|
|
1168
|
+
rootDir,
|
|
1169
|
+
buildEnv,
|
|
1170
|
+
emsdkOptions.signal
|
|
1171
|
+
);
|
|
1172
|
+
await promises.rm(resolvedOutFile, { force: true });
|
|
1173
|
+
await promises.rename(tempOutFile, resolvedOutFile);
|
|
1174
|
+
}
|
|
1108
1175
|
}
|
|
1109
1176
|
outFiles[targetName] = resolvedOutFile;
|
|
1110
1177
|
}
|
|
@@ -1125,4 +1192,4 @@ const buildWasm = async (options) => {
|
|
|
1125
1192
|
exports.buildWasm = buildWasm;
|
|
1126
1193
|
exports.createConsoleLogger = createConsoleLogger;
|
|
1127
1194
|
exports.prepareEmsdk = prepareEmsdk;
|
|
1128
|
-
//# sourceMappingURL=build-
|
|
1195
|
+
//# sourceMappingURL=build-CjKDHGn4.cjs.map
|