emsdk-env 0.7.0 → 0.8.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-Btgi1orl.js → build-DzrgEC4A.js} +137 -17
- package/dist/{build-Btgi1orl.js.map → build-DzrgEC4A.js.map} +1 -1
- package/dist/{build-CjKDHGn4.cjs → build-ya4uDvN7.cjs} +136 -16
- package/dist/{build-CjKDHGn4.cjs.map → build-ya4uDvN7.cjs.map} +1 -1
- package/dist/index.cjs +3 -3
- package/dist/index.d.ts +22 -8
- package/dist/index.mjs +3 -3
- package/dist/vite.cjs +5 -5
- package/dist/vite.cjs.map +1 -1
- package/dist/vite.d.ts +22 -8
- 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.8.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: 8c3f97866a85cc6c99383eff3526c04077032eac
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
"use strict";
|
|
@@ -601,20 +601,100 @@ const normalizePrepareOptions = (options) => {
|
|
|
601
601
|
...rest
|
|
602
602
|
};
|
|
603
603
|
};
|
|
604
|
+
const parseKeyValueInput = (values) => {
|
|
605
|
+
const parsed = {};
|
|
606
|
+
for (const entry of values) {
|
|
607
|
+
const index = entry.indexOf("=");
|
|
608
|
+
if (index === -1) {
|
|
609
|
+
parsed[entry] = void 0;
|
|
610
|
+
continue;
|
|
611
|
+
}
|
|
612
|
+
const key = entry.slice(0, index);
|
|
613
|
+
const value = entry.slice(index + 1);
|
|
614
|
+
parsed[key] = value;
|
|
615
|
+
}
|
|
616
|
+
return parsed;
|
|
617
|
+
};
|
|
618
|
+
const isKeyValueMap = (value) => value instanceof Map;
|
|
619
|
+
const normalizeKeyValueInput = (input) => {
|
|
620
|
+
if (!input) {
|
|
621
|
+
return {};
|
|
622
|
+
}
|
|
623
|
+
if (Array.isArray(input)) {
|
|
624
|
+
return parseKeyValueInput(input);
|
|
625
|
+
}
|
|
626
|
+
if (isKeyValueMap(input)) {
|
|
627
|
+
return Object.fromEntries(input);
|
|
628
|
+
}
|
|
629
|
+
return { ...input };
|
|
630
|
+
};
|
|
604
631
|
const mergeDefines = (common, target) => ({
|
|
605
|
-
...common
|
|
606
|
-
...target
|
|
632
|
+
...normalizeKeyValueInput(common),
|
|
633
|
+
...normalizeKeyValueInput(target)
|
|
607
634
|
});
|
|
635
|
+
const mergeLinkDirectives = (common, target) => mergeDefines(common, target);
|
|
608
636
|
const resolveWasmOptEnabled = (common, target) => {
|
|
609
637
|
var _a, _b;
|
|
610
638
|
return (_b = (_a = target == null ? void 0 : target.enable) != null ? _a : common == null ? void 0 : common.enable) != null ? _b : false;
|
|
611
639
|
};
|
|
612
640
|
const resolveWasmOptArgs = (common, target, env) => {
|
|
613
641
|
var _a, _b;
|
|
614
|
-
const commonArgs = (_a = common == null ? void 0 : common.
|
|
615
|
-
const targetArgs = (_b = target == null ? void 0 : target.
|
|
642
|
+
const commonArgs = (_a = common == null ? void 0 : common.options) != null ? _a : DEFAULT_WASM_OPT_ARGS;
|
|
643
|
+
const targetArgs = (_b = target == null ? void 0 : target.options) != null ? _b : [];
|
|
616
644
|
const mergedArgs = [...commonArgs, ...targetArgs];
|
|
617
|
-
return expandArray(mergedArgs, env, "wasmOpt.
|
|
645
|
+
return expandArray(mergedArgs, env, "wasmOpt.options");
|
|
646
|
+
};
|
|
647
|
+
const stripOuterQuotes = (value) => {
|
|
648
|
+
const trimmed = value.trim();
|
|
649
|
+
if (trimmed.startsWith('"') && trimmed.endsWith('"') || trimmed.startsWith("'") && trimmed.endsWith("'")) {
|
|
650
|
+
return trimmed.slice(1, -1);
|
|
651
|
+
}
|
|
652
|
+
return trimmed;
|
|
653
|
+
};
|
|
654
|
+
const extractWasmBinaryFile = (value) => {
|
|
655
|
+
if (value.startsWith("WASM_BINARY_FILE=")) {
|
|
656
|
+
return value.slice("WASM_BINARY_FILE=".length);
|
|
657
|
+
}
|
|
658
|
+
const match = value.match(/^(?:-s|--settings)(?:=)?WASM_BINARY_FILE=(.+)$/);
|
|
659
|
+
if (match) {
|
|
660
|
+
return match[1];
|
|
661
|
+
}
|
|
662
|
+
return void 0;
|
|
663
|
+
};
|
|
664
|
+
const resolveWasmBinaryFileFromLinkOptions = (linkOptions) => {
|
|
665
|
+
for (let index = 0; index < linkOptions.length; index += 1) {
|
|
666
|
+
const option = linkOptions[index];
|
|
667
|
+
if (!option) {
|
|
668
|
+
continue;
|
|
669
|
+
}
|
|
670
|
+
if (option === "-s" || option === "--settings") {
|
|
671
|
+
const next = linkOptions[index + 1];
|
|
672
|
+
if (!next) {
|
|
673
|
+
continue;
|
|
674
|
+
}
|
|
675
|
+
const extracted2 = extractWasmBinaryFile(next);
|
|
676
|
+
if (extracted2) {
|
|
677
|
+
return stripOuterQuotes(extracted2);
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
const extracted = extractWasmBinaryFile(option);
|
|
681
|
+
if (extracted) {
|
|
682
|
+
return stripOuterQuotes(extracted);
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
return void 0;
|
|
686
|
+
};
|
|
687
|
+
const resolveWasmOptInputFile = (resolvedOutFile, resolvedLinkOptions) => {
|
|
688
|
+
const wasmBinaryFile = resolveWasmBinaryFileFromLinkOptions(resolvedLinkOptions);
|
|
689
|
+
if (wasmBinaryFile) {
|
|
690
|
+
return path.isAbsolute(wasmBinaryFile) ? wasmBinaryFile : path.resolve(path.dirname(resolvedOutFile), wasmBinaryFile);
|
|
691
|
+
}
|
|
692
|
+
const parsed = path.parse(resolvedOutFile);
|
|
693
|
+
if (parsed.ext.toLowerCase() === ".wasm") {
|
|
694
|
+
return resolvedOutFile;
|
|
695
|
+
}
|
|
696
|
+
const baseName = parsed.name.toLowerCase().endsWith(".wasm") ? parsed.name : `${parsed.name}.wasm`;
|
|
697
|
+
return path.join(parsed.dir, baseName);
|
|
618
698
|
};
|
|
619
699
|
const resolvePath = (rootDir, value) => path.isAbsolute(value) ? value : path.resolve(rootDir, value);
|
|
620
700
|
const expandPlaceholders = (value, env, label) => value.replace(/\{([A-Z0-9_]+)\}/g, (_match, key) => {
|
|
@@ -636,6 +716,17 @@ const resolveDefines = (defines, env) => {
|
|
|
636
716
|
}
|
|
637
717
|
return resolved;
|
|
638
718
|
};
|
|
719
|
+
const resolveLinkDirectives = (directives, env) => {
|
|
720
|
+
const resolved = {};
|
|
721
|
+
for (const [key, value] of Object.entries(directives)) {
|
|
722
|
+
if (typeof value === "string") {
|
|
723
|
+
resolved[key] = expandPlaceholders(value, env, `linkDirectives.${key}`);
|
|
724
|
+
} else {
|
|
725
|
+
resolved[key] = value;
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
return resolved;
|
|
729
|
+
};
|
|
639
730
|
const resolveIncludeDirs = (includeDirs, env, rootDir) => {
|
|
640
731
|
const expanded = expandArray(includeDirs, env, "includeDirs");
|
|
641
732
|
return expanded.map((value) => resolvePath(rootDir, value));
|
|
@@ -654,7 +745,17 @@ const resolveSourcesFromPatterns = async (patterns, env, srcDir, label) => {
|
|
|
654
745
|
sources.sort();
|
|
655
746
|
return sources;
|
|
656
747
|
};
|
|
657
|
-
const buildDefineFlags = (defines) => Object.entries(defines).
|
|
748
|
+
const buildDefineFlags = (defines) => Object.entries(defines).flatMap(
|
|
749
|
+
([key, value]) => value === null || value === void 0 ? [`-D${key}`] : [`-D${key}=${String(value)}`]
|
|
750
|
+
);
|
|
751
|
+
const buildLinkDirectiveFlags = (directives) => {
|
|
752
|
+
if (Object.keys(directives).length === 0) {
|
|
753
|
+
return [];
|
|
754
|
+
}
|
|
755
|
+
return Object.entries(directives).flatMap(
|
|
756
|
+
([key, value]) => value === null || value === void 0 ? ["-s", key] : ["-s", `${key}=${String(value)}`]
|
|
757
|
+
);
|
|
758
|
+
};
|
|
658
759
|
const buildExportFlags = (exports$1) => {
|
|
659
760
|
if (exports$1.length === 0) {
|
|
660
761
|
return [];
|
|
@@ -940,6 +1041,11 @@ const buildWasm = async (options) => {
|
|
|
940
1041
|
`linkOptions is not supported for archive target: ${targetName}`
|
|
941
1042
|
);
|
|
942
1043
|
}
|
|
1044
|
+
if (target.linkDirectives !== void 0) {
|
|
1045
|
+
throw new Error(
|
|
1046
|
+
`linkDirectives is not supported for archive target: ${targetName}`
|
|
1047
|
+
);
|
|
1048
|
+
}
|
|
943
1049
|
if (target.exports !== void 0) {
|
|
944
1050
|
throw new Error(
|
|
945
1051
|
`exports is not supported for archive target: ${targetName}`
|
|
@@ -955,6 +1061,7 @@ const buildWasm = async (options) => {
|
|
|
955
1061
|
...ensureArray(common.linkOptions),
|
|
956
1062
|
...ensureArray(target.linkOptions)
|
|
957
1063
|
];
|
|
1064
|
+
const mergedLinkDirectives = targetType === "archive" ? {} : mergeLinkDirectives(common.linkDirectives, target.linkDirectives);
|
|
958
1065
|
const mergedExports = targetType === "archive" ? [] : [...ensureArray(common.exports), ...ensureArray(target.exports)];
|
|
959
1066
|
const wasmOptEnabled = targetType === "archive" ? false : resolveWasmOptEnabled(common.wasmOpt, target.wasmOpt);
|
|
960
1067
|
const baseCompileOptions = [
|
|
@@ -1014,7 +1121,12 @@ const buildWasm = async (options) => {
|
|
|
1014
1121
|
const targetBuildDir = path.resolve(buildRunDir, targetName);
|
|
1015
1122
|
await promises.rm(targetBuildDir, { recursive: true, force: true });
|
|
1016
1123
|
await ensureDirectory(targetBuildDir);
|
|
1017
|
-
const
|
|
1124
|
+
const resolvedLinkDirectives = targetType === "archive" ? {} : resolveLinkDirectives(mergedLinkDirectives, targetEnv);
|
|
1125
|
+
const linkDirectiveArgs = buildLinkDirectiveFlags(resolvedLinkDirectives);
|
|
1126
|
+
const resolvedLinkOptions = targetType === "archive" ? [] : [
|
|
1127
|
+
...linkDirectiveArgs,
|
|
1128
|
+
...expandArray(mergedLinkOptions, targetEnv, "linkOptions")
|
|
1129
|
+
];
|
|
1018
1130
|
const resolvedExports = targetType === "archive" ? [] : expandArray(mergedExports, targetEnv, "exports");
|
|
1019
1131
|
const exportArgs = buildExportFlags(resolvedExports);
|
|
1020
1132
|
const resolvedWasmOptArgs = wasmOptEnabled ? resolveWasmOptArgs(common.wasmOpt, target.wasmOpt, targetEnv) : [];
|
|
@@ -1026,7 +1138,6 @@ const buildWasm = async (options) => {
|
|
|
1026
1138
|
rootDir
|
|
1027
1139
|
);
|
|
1028
1140
|
const groupCompileArgs = sourceGroups.map((group) => {
|
|
1029
|
-
var _a3;
|
|
1030
1141
|
const groupOptions = [
|
|
1031
1142
|
...baseCompileOptions,
|
|
1032
1143
|
...ensureArray(group == null ? void 0 : group.options)
|
|
@@ -1035,7 +1146,7 @@ const buildWasm = async (options) => {
|
|
|
1035
1146
|
...baseIncludeDirs,
|
|
1036
1147
|
...ensureArray(group == null ? void 0 : group.includeDirs)
|
|
1037
1148
|
];
|
|
1038
|
-
const groupDefines = mergeDefines(baseDefines,
|
|
1149
|
+
const groupDefines = mergeDefines(baseDefines, group == null ? void 0 : group.defines);
|
|
1039
1150
|
return buildCompileArgs(
|
|
1040
1151
|
groupOptions,
|
|
1041
1152
|
groupIncludeDirs,
|
|
@@ -1152,9 +1263,18 @@ const buildWasm = async (options) => {
|
|
|
1152
1263
|
emsdkOptions.signal
|
|
1153
1264
|
);
|
|
1154
1265
|
if (wasmOptEnabled) {
|
|
1155
|
-
const
|
|
1156
|
-
const wasmOptArgs = [
|
|
1266
|
+
const wasmOptInput = resolveWasmOptInputFile(
|
|
1157
1267
|
resolvedOutFile,
|
|
1268
|
+
resolvedLinkOptions
|
|
1269
|
+
);
|
|
1270
|
+
if (!await pathExists(wasmOptInput)) {
|
|
1271
|
+
throw new Error(
|
|
1272
|
+
`wasm-opt enabled but wasm binary not found: ${wasmOptInput}`
|
|
1273
|
+
);
|
|
1274
|
+
}
|
|
1275
|
+
const tempOutFile = `${wasmOptInput}.opt`;
|
|
1276
|
+
const wasmOptArgs = [
|
|
1277
|
+
wasmOptInput,
|
|
1158
1278
|
"-o",
|
|
1159
1279
|
tempOutFile,
|
|
1160
1280
|
...resolvedWasmOptArgs
|
|
@@ -1169,8 +1289,8 @@ const buildWasm = async (options) => {
|
|
|
1169
1289
|
buildEnv,
|
|
1170
1290
|
emsdkOptions.signal
|
|
1171
1291
|
);
|
|
1172
|
-
await promises.rm(
|
|
1173
|
-
await promises.rename(tempOutFile,
|
|
1292
|
+
await promises.rm(wasmOptInput, { force: true });
|
|
1293
|
+
await promises.rename(tempOutFile, wasmOptInput);
|
|
1174
1294
|
}
|
|
1175
1295
|
}
|
|
1176
1296
|
outFiles[targetName] = resolvedOutFile;
|
|
@@ -1192,4 +1312,4 @@ const buildWasm = async (options) => {
|
|
|
1192
1312
|
exports.buildWasm = buildWasm;
|
|
1193
1313
|
exports.createConsoleLogger = createConsoleLogger;
|
|
1194
1314
|
exports.prepareEmsdk = prepareEmsdk;
|
|
1195
|
-
//# sourceMappingURL=build-
|
|
1315
|
+
//# sourceMappingURL=build-ya4uDvN7.cjs.map
|