emsdk-env 0.2.0 → 0.4.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/README.md +21 -4
- package/dist/__vite-browser-external-2Ng8QIWW.js +15 -0
- package/dist/__vite-browser-external-2Ng8QIWW.js.map +1 -0
- package/dist/__vite-browser-external-DES75WN9.cjs +15 -0
- package/dist/__vite-browser-external-DES75WN9.cjs.map +1 -0
- package/dist/{build-oenTJc-4.cjs → build-DwIdyC2W.cjs} +403 -80
- package/dist/build-DwIdyC2W.cjs.map +1 -0
- package/dist/{build-qp0IEBnb.js → build-oSzNI6Av.js} +405 -82
- package/dist/build-oSzNI6Av.js.map +1 -0
- package/dist/index.cjs +3 -3
- package/dist/index.d.ts +197 -33
- package/dist/index.mjs +3 -3
- package/dist/vite.cjs +32 -8
- package/dist/vite.cjs.map +1 -1
- package/dist/vite.d.ts +183 -27
- package/dist/vite.mjs +32 -8
- package/dist/vite.mjs.map +1 -1
- package/package.json +7 -7
- package/dist/build-oenTJc-4.cjs.map +0 -1
- package/dist/build-qp0IEBnb.js.map +0 -1
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/*!
|
|
2
2
|
* name: emsdk-env
|
|
3
|
-
* version: 0.
|
|
3
|
+
* version: 0.4.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: cd0d8e53bf52b98940dd50343a9d3a39200306bd
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
"use strict";
|
|
@@ -502,6 +502,22 @@ const resolveEmccCommand = async (env, emsdkRoot) => {
|
|
|
502
502
|
}
|
|
503
503
|
return "emcc";
|
|
504
504
|
};
|
|
505
|
+
const resolveEmarCommand = async (env, emsdkRoot) => {
|
|
506
|
+
if (env.EMAR) {
|
|
507
|
+
return env.EMAR;
|
|
508
|
+
}
|
|
509
|
+
if (env.EMSCRIPTEN) {
|
|
510
|
+
const candidate = path.join(env.EMSCRIPTEN, "emar");
|
|
511
|
+
if (await pathExists(candidate)) {
|
|
512
|
+
return candidate;
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
const fallback = path.join(emsdkRoot, "upstream", "emscripten", "emar");
|
|
516
|
+
if (await pathExists(fallback)) {
|
|
517
|
+
return fallback;
|
|
518
|
+
}
|
|
519
|
+
return "emar";
|
|
520
|
+
};
|
|
505
521
|
const createConsoleLogger = (prefix) => {
|
|
506
522
|
return {
|
|
507
523
|
debug: (msg) => console.debug(`[${prefix}]: ${msg}`),
|
|
@@ -511,7 +527,11 @@ const createConsoleLogger = (prefix) => {
|
|
|
511
527
|
};
|
|
512
528
|
};
|
|
513
529
|
const DEFAULT_WASM_SRC_DIR = "wasm";
|
|
530
|
+
const DEFAULT_WASM_INCLUDE_DIR = "include";
|
|
514
531
|
const DEFAULT_WASM_OUT_DIR = path.join("src", "wasm");
|
|
532
|
+
const DEFAULT_WASM_LIB_DIR = "lib";
|
|
533
|
+
const DEFAULT_IMPORT_INCLUDE_DIR = "include";
|
|
534
|
+
const DEFAULT_IMPORT_LIB_DIR = "lib";
|
|
515
535
|
const DEFAULT_WASM_BUILD_DIR = path.join(os.tmpdir(), "emsdk-env");
|
|
516
536
|
const DEFAULT_EMSDK_TARGET_VERSION = "latest";
|
|
517
537
|
let buildSequence = 0;
|
|
@@ -531,7 +551,8 @@ const createBuildId = () => {
|
|
|
531
551
|
const seq = String(buildSequence).padStart(4, "0");
|
|
532
552
|
return `${timestamp}_${seq}_${process.pid}`;
|
|
533
553
|
};
|
|
534
|
-
const ensureArray = (value) => value ?
|
|
554
|
+
const ensureArray = (value) => value != null ? value : [];
|
|
555
|
+
const resolveTargetType = (value) => value != null ? value : "wasm";
|
|
535
556
|
const normalizePrepareOptions = (options) => {
|
|
536
557
|
const { targetVersion, ...rest } = options != null ? options : {};
|
|
537
558
|
return {
|
|
@@ -571,9 +592,15 @@ const resolveOutFile = (outFile, env, outDir) => {
|
|
|
571
592
|
const expanded = expandPlaceholders(outFile, env, "outFile");
|
|
572
593
|
return resolvePath(outDir, expanded);
|
|
573
594
|
};
|
|
574
|
-
const
|
|
575
|
-
const expanded = expandArray(patterns, env,
|
|
576
|
-
|
|
595
|
+
const resolveSourcesFromPatterns = async (patterns, env, srcDir, label) => {
|
|
596
|
+
const expanded = expandArray(patterns, env, label);
|
|
597
|
+
const resolvedPatterns = expanded.map((value) => resolvePath(srcDir, value));
|
|
598
|
+
const results = await Promise.all(
|
|
599
|
+
resolvedPatterns.map((pattern) => glob.glob(pattern, { nodir: true }))
|
|
600
|
+
);
|
|
601
|
+
const sources = results.flat();
|
|
602
|
+
sources.sort();
|
|
603
|
+
return sources;
|
|
577
604
|
};
|
|
578
605
|
const buildDefineFlags = (defines) => Object.entries(defines).map(([key, value]) => `-D${key}=${String(value)}`);
|
|
579
606
|
const buildExportFlags = (exports$1) => {
|
|
@@ -587,33 +614,165 @@ const createEnvForBuild = (baseEnv, overrides) => ({
|
|
|
587
614
|
...baseEnv,
|
|
588
615
|
...overrides
|
|
589
616
|
});
|
|
590
|
-
const resolveTargetOutFile = (targetName, targetOutFile, env,
|
|
617
|
+
const resolveTargetOutFile = (targetName, targetOutFile, env, baseDir, extension) => {
|
|
591
618
|
if (targetOutFile) {
|
|
592
|
-
return resolveOutFile(targetOutFile, env,
|
|
619
|
+
return resolveOutFile(targetOutFile, env, baseDir);
|
|
593
620
|
}
|
|
594
|
-
return path.resolve(
|
|
621
|
+
return path.resolve(baseDir, `${targetName}.${extension}`);
|
|
595
622
|
};
|
|
596
623
|
const resolveTargetSources = async (targetSources, env, srcDir) => {
|
|
597
624
|
const patterns = targetSources && targetSources.length > 0 ? targetSources : [path.join(srcDir, "**", "*.c"), path.join(srcDir, "**", "*.cpp")];
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
625
|
+
return resolveSourcesFromPatterns(patterns, env, srcDir, "sources");
|
|
626
|
+
};
|
|
627
|
+
const toSafeObjectName = (rootDir, sourcePath, groupIndex) => {
|
|
628
|
+
const baseName = path.relative(rootDir, sourcePath).replace(/[\\/]/g, "_").replace(/[^A-Za-z0-9._-]/g, "_");
|
|
629
|
+
if (groupIndex === void 0) {
|
|
630
|
+
return baseName;
|
|
631
|
+
}
|
|
632
|
+
return `${baseName}__g${groupIndex}`;
|
|
633
|
+
};
|
|
634
|
+
const dedupeSources = (sources) => {
|
|
635
|
+
const seen = /* @__PURE__ */ new Set();
|
|
636
|
+
const deduped = [];
|
|
637
|
+
for (const source of sources) {
|
|
638
|
+
if (seen.has(source)) {
|
|
639
|
+
continue;
|
|
640
|
+
}
|
|
641
|
+
seen.add(source);
|
|
642
|
+
deduped.push(source);
|
|
643
|
+
}
|
|
644
|
+
return deduped;
|
|
645
|
+
};
|
|
646
|
+
const dedupeValues = (values) => {
|
|
647
|
+
const seen = /* @__PURE__ */ new Set();
|
|
648
|
+
const deduped = [];
|
|
649
|
+
for (const value of values) {
|
|
650
|
+
if (seen.has(value)) {
|
|
651
|
+
continue;
|
|
652
|
+
}
|
|
653
|
+
seen.add(value);
|
|
654
|
+
deduped.push(value);
|
|
655
|
+
}
|
|
656
|
+
return deduped;
|
|
657
|
+
};
|
|
658
|
+
const isRecord = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
659
|
+
const resolvePackageJsonPath = async (startPath, packageName) => {
|
|
660
|
+
let current = path.dirname(startPath);
|
|
661
|
+
for (; ; ) {
|
|
662
|
+
const candidate = path.join(current, "package.json");
|
|
663
|
+
if (await pathExists(candidate)) {
|
|
664
|
+
return candidate;
|
|
665
|
+
}
|
|
666
|
+
const parent = path.dirname(current);
|
|
667
|
+
if (parent === current) {
|
|
668
|
+
throw new Error(`package.json not found for import: ${packageName}`);
|
|
669
|
+
}
|
|
670
|
+
current = parent;
|
|
671
|
+
}
|
|
672
|
+
};
|
|
673
|
+
const loadPackageJson = async (packageJsonPath, packageName) => {
|
|
674
|
+
try {
|
|
675
|
+
const raw = await promises.readFile(packageJsonPath, "utf8");
|
|
676
|
+
const parsed = JSON.parse(raw);
|
|
677
|
+
if (!isRecord(parsed)) {
|
|
678
|
+
throw new Error("package.json must be an object.");
|
|
679
|
+
}
|
|
680
|
+
return parsed;
|
|
681
|
+
} catch (error) {
|
|
682
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
683
|
+
throw new Error(
|
|
684
|
+
`Failed to read package.json for import ${packageName}: ${message}`
|
|
685
|
+
);
|
|
686
|
+
}
|
|
687
|
+
};
|
|
688
|
+
const resolveImportPaths = async (resolver, packageName) => {
|
|
689
|
+
let resolvedEntry;
|
|
690
|
+
try {
|
|
691
|
+
resolvedEntry = resolver.resolve(packageName);
|
|
692
|
+
} catch (error) {
|
|
693
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
694
|
+
throw new Error(`Failed to resolve import ${packageName}: ${message}`);
|
|
695
|
+
}
|
|
696
|
+
const packageJsonPath = await resolvePackageJsonPath(
|
|
697
|
+
resolvedEntry,
|
|
698
|
+
packageName
|
|
601
699
|
);
|
|
602
|
-
const
|
|
603
|
-
|
|
604
|
-
|
|
700
|
+
const packageRoot = path.dirname(packageJsonPath);
|
|
701
|
+
const packageJson = await loadPackageJson(packageJsonPath, packageName);
|
|
702
|
+
const emsdkConfigRaw = packageJson["emsdk-env"];
|
|
703
|
+
if (emsdkConfigRaw !== void 0 && !isRecord(emsdkConfigRaw)) {
|
|
704
|
+
throw new Error(
|
|
705
|
+
`Invalid emsdk-env config for import ${packageName}: expected an object.`
|
|
706
|
+
);
|
|
707
|
+
}
|
|
708
|
+
const includeRaw = isRecord(emsdkConfigRaw) ? emsdkConfigRaw.include : void 0;
|
|
709
|
+
if (includeRaw !== void 0 && typeof includeRaw !== "string") {
|
|
710
|
+
throw new Error(
|
|
711
|
+
`Invalid emsdk-env include for import ${packageName}: expected a string.`
|
|
712
|
+
);
|
|
713
|
+
}
|
|
714
|
+
const libRaw = isRecord(emsdkConfigRaw) ? emsdkConfigRaw.lib : void 0;
|
|
715
|
+
if (libRaw !== void 0 && typeof libRaw !== "string") {
|
|
716
|
+
throw new Error(
|
|
717
|
+
`Invalid emsdk-env lib for import ${packageName}: expected a string.`
|
|
718
|
+
);
|
|
719
|
+
}
|
|
720
|
+
const includeRel = includeRaw != null ? includeRaw : DEFAULT_IMPORT_INCLUDE_DIR;
|
|
721
|
+
const libRel = libRaw != null ? libRaw : DEFAULT_IMPORT_LIB_DIR;
|
|
722
|
+
const includeDir = path.resolve(packageRoot, includeRel);
|
|
723
|
+
const libDir = path.resolve(packageRoot, libRel);
|
|
724
|
+
const includeExists = await pathExists(includeDir);
|
|
725
|
+
const libExists = await pathExists(libDir);
|
|
726
|
+
if (!includeExists && !libExists) {
|
|
727
|
+
throw new Error(
|
|
728
|
+
`Import ${packageName} does not provide include or lib directories.`
|
|
729
|
+
);
|
|
730
|
+
}
|
|
731
|
+
return {
|
|
732
|
+
includeDir: includeExists ? includeDir : void 0,
|
|
733
|
+
libDir: libExists ? libDir : void 0
|
|
734
|
+
};
|
|
735
|
+
};
|
|
736
|
+
const resolveImportDirectories = async (rootDir, imports) => {
|
|
737
|
+
if (imports.length === 0) {
|
|
738
|
+
return { includeDirs: [], libDirs: [] };
|
|
739
|
+
}
|
|
740
|
+
const moduleApi = await Promise.resolve().then(() => require("./__vite-browser-external-DES75WN9.cjs"));
|
|
741
|
+
const resolver = moduleApi.createRequire(path.resolve(rootDir, "package.json"));
|
|
742
|
+
const includeDirs = [];
|
|
743
|
+
const libDirs = [];
|
|
744
|
+
for (const packageName of imports) {
|
|
745
|
+
const resolved = await resolveImportPaths(resolver, packageName);
|
|
746
|
+
if (resolved.includeDir) {
|
|
747
|
+
includeDirs.push(resolved.includeDir);
|
|
748
|
+
}
|
|
749
|
+
if (resolved.libDir) {
|
|
750
|
+
libDirs.push(resolved.libDir);
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
return {
|
|
754
|
+
includeDirs: dedupeValues(includeDirs),
|
|
755
|
+
libDirs: dedupeValues(libDirs)
|
|
756
|
+
};
|
|
757
|
+
};
|
|
758
|
+
const buildCompileArgs = (options, includeDirs, defines, env, rootDir) => {
|
|
759
|
+
const resolvedOptions = expandArray(options, env, "options");
|
|
760
|
+
const includeArgs = resolveIncludeDirs(includeDirs, env, rootDir).map(
|
|
761
|
+
(dir) => `-I${dir}`
|
|
762
|
+
);
|
|
763
|
+
const defineArgs = buildDefineFlags(resolveDefines(defines, env));
|
|
764
|
+
return { resolvedOptions, includeArgs, defineArgs };
|
|
605
765
|
};
|
|
606
|
-
const toSafeObjectName = (rootDir, sourcePath) => path.relative(rootDir, sourcePath).replace(/[\\/]/g, "_").replace(/[^A-Za-z0-9._-]/g, "_");
|
|
607
766
|
const buildWasm = async (options) => {
|
|
608
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
767
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
609
768
|
if (!options) {
|
|
610
769
|
throw new TypeError("options must be provided.");
|
|
611
770
|
}
|
|
612
771
|
if (!options.rule || !options.rule.targets) {
|
|
613
772
|
throw new TypeError("rule targets must be provided.");
|
|
614
773
|
}
|
|
615
|
-
const
|
|
616
|
-
if (
|
|
774
|
+
const targetEntries = Object.entries(options.rule.targets);
|
|
775
|
+
if (targetEntries.length === 0) {
|
|
617
776
|
throw new TypeError("rule targets must not be empty.");
|
|
618
777
|
}
|
|
619
778
|
const logger = (_a = options.logger) != null ? _a : createConsoleLogger("emsdk-env");
|
|
@@ -630,56 +789,118 @@ const buildWasm = async (options) => {
|
|
|
630
789
|
baseEnv,
|
|
631
790
|
"srcDir"
|
|
632
791
|
);
|
|
792
|
+
const rawIncludeDir = expandPlaceholders(
|
|
793
|
+
(_d = options.includeDir) != null ? _d : DEFAULT_WASM_INCLUDE_DIR,
|
|
794
|
+
baseEnv,
|
|
795
|
+
"includeDir"
|
|
796
|
+
);
|
|
633
797
|
const rawOutDir = expandPlaceholders(
|
|
634
|
-
(
|
|
798
|
+
(_e = options.outDir) != null ? _e : DEFAULT_WASM_OUT_DIR,
|
|
635
799
|
baseEnv,
|
|
636
800
|
"outDir"
|
|
637
801
|
);
|
|
802
|
+
const rawLibDir = expandPlaceholders(
|
|
803
|
+
(_f = options.libDir) != null ? _f : DEFAULT_WASM_LIB_DIR,
|
|
804
|
+
baseEnv,
|
|
805
|
+
"libDir"
|
|
806
|
+
);
|
|
638
807
|
const rawBuildDir = expandPlaceholders(
|
|
639
|
-
(
|
|
808
|
+
(_g = options.buildDir) != null ? _g : DEFAULT_WASM_BUILD_DIR,
|
|
640
809
|
baseEnv,
|
|
641
810
|
"buildDir"
|
|
642
811
|
);
|
|
643
812
|
const srcDir = resolvePath(rootDir, rawSrcDir);
|
|
813
|
+
const includeDir = resolvePath(rootDir, rawIncludeDir);
|
|
644
814
|
const outDir = resolvePath(rootDir, rawOutDir);
|
|
815
|
+
const libDir = resolvePath(rootDir, rawLibDir);
|
|
645
816
|
const buildDir = resolvePath(rootDir, rawBuildDir);
|
|
646
817
|
const buildId = createBuildId();
|
|
647
818
|
const buildRunDir = path.resolve(buildDir, buildId);
|
|
648
|
-
const cleanupBuildDir = (
|
|
649
|
-
const parallel = (
|
|
819
|
+
const cleanupBuildDir = (_h = options.cleanupBuildDir) != null ? _h : true;
|
|
820
|
+
const parallel = (_i = options.parallel) != null ? _i : true;
|
|
650
821
|
const envWithDirs = {
|
|
651
822
|
...emsdkEnv,
|
|
652
823
|
ROOT: rootDir,
|
|
653
824
|
SRC_DIR: srcDir,
|
|
825
|
+
INCLUDE_DIR: includeDir,
|
|
654
826
|
OUT_DIR: outDir,
|
|
827
|
+
LIB_DIR: libDir,
|
|
655
828
|
BUILD_DIR: buildDir
|
|
656
829
|
};
|
|
657
830
|
const emccCommand = await resolveEmccCommand(envWithDirs, emsdkRoot);
|
|
658
|
-
const common = (
|
|
831
|
+
const common = (_j = options.rule.common) != null ? _j : {};
|
|
832
|
+
const commonIncludeDirs = common.includeDirs === void 0 ? [includeDir] : common.includeDirs;
|
|
833
|
+
const importDirectories = await resolveImportDirectories(
|
|
834
|
+
rootDir,
|
|
835
|
+
ensureArray(options.imports)
|
|
836
|
+
);
|
|
837
|
+
const importIncludeDirs = importDirectories.includeDirs;
|
|
838
|
+
const importLibDirs = importDirectories.libDirs;
|
|
839
|
+
const linkLibDirs = dedupeValues([libDir, ...importLibDirs]);
|
|
840
|
+
logger.debug(`Detected rootDir: '${rootDir}'`);
|
|
841
|
+
logger.debug(`Detected srcDir: '${srcDir}'`);
|
|
842
|
+
logger.debug(`Detected outDir: '${outDir}'`);
|
|
843
|
+
logger.debug(`Detected libDir: '${libDir}'`);
|
|
844
|
+
logger.debug(`Detected buildDir: '${buildDir}'`);
|
|
845
|
+
logger.debug(`Detected buildId: '${buildId}'`);
|
|
846
|
+
logger.debug(`Detected buildRunDir: '${buildRunDir}'`);
|
|
847
|
+
logger.debug(`Detected cleanupBuildDir: ${cleanupBuildDir}`);
|
|
848
|
+
logger.debug(`Detected parallel: ${parallel}`);
|
|
849
|
+
logger.debug(`Detected emccCommand: '${emccCommand}'`);
|
|
850
|
+
logger.debug(
|
|
851
|
+
`Detected importIncludeDirs: [${importIncludeDirs.map((p) => `'${p}'`).join(",")}]`
|
|
852
|
+
);
|
|
853
|
+
logger.debug(
|
|
854
|
+
`Detected importLibDirs: [${importLibDirs.map((p) => `'${p}'`).join(",")}]`
|
|
855
|
+
);
|
|
659
856
|
await ensureDirectory(outDir);
|
|
857
|
+
await ensureDirectory(libDir);
|
|
660
858
|
await ensureDirectory(buildDir);
|
|
661
859
|
await promises.rm(buildRunDir, { recursive: true, force: true });
|
|
662
860
|
await ensureDirectory(buildRunDir);
|
|
861
|
+
const hasArchiveTargets = targetEntries.some(
|
|
862
|
+
([, target]) => resolveTargetType(target.type) === "archive"
|
|
863
|
+
);
|
|
864
|
+
const emarCommand = hasArchiveTargets ? await resolveEmarCommand(envWithDirs, emsdkRoot) : void 0;
|
|
865
|
+
if (emarCommand) {
|
|
866
|
+
logger.debug(`Detected emarCommand: '${emarCommand}'`);
|
|
867
|
+
}
|
|
663
868
|
const outFiles = {};
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
869
|
+
const buildTargets = async (expectedType) => {
|
|
870
|
+
var _a2;
|
|
871
|
+
for (const [targetName, target] of targetEntries) {
|
|
872
|
+
const targetType = resolveTargetType(target.type);
|
|
873
|
+
if (targetType !== expectedType) {
|
|
874
|
+
continue;
|
|
875
|
+
}
|
|
876
|
+
if (targetType === "archive") {
|
|
877
|
+
if (target.linkOptions !== void 0) {
|
|
878
|
+
throw new Error(
|
|
879
|
+
`linkOptions is not supported for archive target: ${targetName}`
|
|
880
|
+
);
|
|
881
|
+
}
|
|
882
|
+
if (target.exports !== void 0) {
|
|
883
|
+
throw new Error(
|
|
884
|
+
`exports is not supported for archive target: ${targetName}`
|
|
885
|
+
);
|
|
886
|
+
}
|
|
887
|
+
}
|
|
888
|
+
const mergedLinkOptions = targetType === "archive" ? [] : [
|
|
671
889
|
...ensureArray(common.linkOptions),
|
|
672
890
|
...ensureArray(target.linkOptions)
|
|
673
891
|
];
|
|
674
|
-
const mergedExports = [
|
|
675
|
-
|
|
676
|
-
...ensureArray(
|
|
892
|
+
const mergedExports = targetType === "archive" ? [] : [...ensureArray(common.exports), ...ensureArray(target.exports)];
|
|
893
|
+
const baseCompileOptions = [
|
|
894
|
+
...ensureArray(common.options),
|
|
895
|
+
...ensureArray(target.options)
|
|
677
896
|
];
|
|
678
|
-
const
|
|
679
|
-
...ensureArray(
|
|
680
|
-
...ensureArray(target.includeDirs)
|
|
897
|
+
const baseIncludeDirs = [
|
|
898
|
+
...ensureArray(commonIncludeDirs),
|
|
899
|
+
...ensureArray(target.includeDirs),
|
|
900
|
+
...importIncludeDirs
|
|
681
901
|
];
|
|
682
|
-
const
|
|
902
|
+
const baseDefines = mergeDefines(common.defines, target.defines);
|
|
903
|
+
const sourceGroups = (_a2 = target.sourceGroups) != null ? _a2 : [];
|
|
683
904
|
const targetEnv = {
|
|
684
905
|
...envWithDirs,
|
|
685
906
|
TARGET_NAME: targetName
|
|
@@ -689,52 +910,90 @@ const buildWasm = async (options) => {
|
|
|
689
910
|
targetName,
|
|
690
911
|
target.outFile,
|
|
691
912
|
targetEnv,
|
|
692
|
-
outDir
|
|
913
|
+
targetType === "archive" ? libDir : outDir,
|
|
914
|
+
targetType === "archive" ? "a" : "wasm"
|
|
693
915
|
);
|
|
694
916
|
const sources = await resolveTargetSources(
|
|
695
917
|
target.sources,
|
|
696
918
|
targetEnv,
|
|
697
919
|
srcDir
|
|
698
920
|
);
|
|
699
|
-
|
|
921
|
+
const groupSources = sourceGroups.map(() => []);
|
|
922
|
+
const groupSourceSet = /* @__PURE__ */ new Set();
|
|
923
|
+
for (let index = 0; index < sourceGroups.length; index += 1) {
|
|
924
|
+
const group = sourceGroups[index];
|
|
925
|
+
if (!group) {
|
|
926
|
+
continue;
|
|
927
|
+
}
|
|
928
|
+
const resolved = await resolveSourcesFromPatterns(
|
|
929
|
+
group.sources,
|
|
930
|
+
targetEnv,
|
|
931
|
+
srcDir,
|
|
932
|
+
`sourceGroups[${index}].sources`
|
|
933
|
+
);
|
|
934
|
+
const deduped = dedupeSources(resolved);
|
|
935
|
+
groupSources[index] = deduped;
|
|
936
|
+
for (const source of deduped) {
|
|
937
|
+
groupSourceSet.add(source);
|
|
938
|
+
}
|
|
939
|
+
}
|
|
940
|
+
const baseSources = sources.filter(
|
|
941
|
+
(source) => !groupSourceSet.has(source)
|
|
942
|
+
);
|
|
943
|
+
const groupedSources = groupSources.flat();
|
|
944
|
+
if (baseSources.length + groupedSources.length === 0) {
|
|
700
945
|
throw new Error(`No sources matched for target: ${targetName}`);
|
|
701
946
|
}
|
|
702
947
|
const targetBuildDir = path.resolve(buildRunDir, targetName);
|
|
703
948
|
await promises.rm(targetBuildDir, { recursive: true, force: true });
|
|
704
949
|
await ensureDirectory(targetBuildDir);
|
|
705
|
-
const
|
|
706
|
-
const
|
|
707
|
-
mergedLinkOptions,
|
|
708
|
-
targetEnv,
|
|
709
|
-
"linkOptions"
|
|
710
|
-
);
|
|
711
|
-
const resolvedExports = expandArray(mergedExports, targetEnv, "exports");
|
|
950
|
+
const resolvedLinkOptions = targetType === "archive" ? [] : expandArray(mergedLinkOptions, targetEnv, "linkOptions");
|
|
951
|
+
const resolvedExports = targetType === "archive" ? [] : expandArray(mergedExports, targetEnv, "exports");
|
|
712
952
|
const exportArgs = buildExportFlags(resolvedExports);
|
|
713
|
-
const
|
|
714
|
-
|
|
953
|
+
const baseCompileArgs = buildCompileArgs(
|
|
954
|
+
baseCompileOptions,
|
|
955
|
+
baseIncludeDirs,
|
|
956
|
+
baseDefines,
|
|
715
957
|
targetEnv,
|
|
716
958
|
rootDir
|
|
717
|
-
).map((dir) => `-I${dir}`);
|
|
718
|
-
const defineArgs = buildDefineFlags(
|
|
719
|
-
resolveDefines(mergedDefines, targetEnv)
|
|
720
959
|
);
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
const
|
|
960
|
+
const groupCompileArgs = sourceGroups.map((group) => {
|
|
961
|
+
var _a3;
|
|
962
|
+
const groupOptions = [
|
|
963
|
+
...baseCompileOptions,
|
|
964
|
+
...ensureArray(group == null ? void 0 : group.options)
|
|
965
|
+
];
|
|
966
|
+
const groupIncludeDirs = [
|
|
967
|
+
...baseIncludeDirs,
|
|
968
|
+
...ensureArray(group == null ? void 0 : group.includeDirs)
|
|
969
|
+
];
|
|
970
|
+
const groupDefines = mergeDefines(baseDefines, (_a3 = group == null ? void 0 : group.defines) != null ? _a3 : {});
|
|
971
|
+
return buildCompileArgs(
|
|
972
|
+
groupOptions,
|
|
973
|
+
groupIncludeDirs,
|
|
974
|
+
groupDefines,
|
|
975
|
+
targetEnv,
|
|
976
|
+
rootDir
|
|
977
|
+
);
|
|
978
|
+
});
|
|
979
|
+
const compileSource = async (source, args, groupIndex) => {
|
|
980
|
+
const objectName = toSafeObjectName(rootDir, source, groupIndex);
|
|
724
981
|
const outputObject = path.resolve(targetBuildDir, `${objectName}.o`);
|
|
725
|
-
const
|
|
982
|
+
const compileArgs = [
|
|
726
983
|
"-c",
|
|
727
984
|
source,
|
|
728
985
|
"-o",
|
|
729
986
|
outputObject,
|
|
730
|
-
...resolvedOptions,
|
|
731
|
-
...includeArgs,
|
|
732
|
-
...defineArgs
|
|
987
|
+
...args.resolvedOptions,
|
|
988
|
+
...args.includeArgs,
|
|
989
|
+
...args.defineArgs
|
|
733
990
|
];
|
|
734
|
-
|
|
991
|
+
const sourcePath = path.relative(rootDir, source);
|
|
992
|
+
logger.info(`Compiling source: ${sourcePath} --> $tmp/${objectName}.o`);
|
|
993
|
+
logger.debug(`emcc ${compileArgs.join(" ")}`);
|
|
735
994
|
await runCommandWithEnv(
|
|
736
995
|
emccCommand,
|
|
737
|
-
|
|
996
|
+
compileArgs,
|
|
738
997
|
rootDir,
|
|
739
998
|
buildEnv,
|
|
740
999
|
emsdkOptions.signal
|
|
@@ -743,30 +1002,94 @@ const buildWasm = async (options) => {
|
|
|
743
1002
|
};
|
|
744
1003
|
const buildObjectsSequential = async () => {
|
|
745
1004
|
const objectFiles2 = [];
|
|
746
|
-
for (const source of
|
|
747
|
-
objectFiles2.push(
|
|
1005
|
+
for (const source of baseSources) {
|
|
1006
|
+
objectFiles2.push(
|
|
1007
|
+
await compileSource(source, baseCompileArgs, void 0)
|
|
1008
|
+
);
|
|
1009
|
+
}
|
|
1010
|
+
for (let index = 0; index < groupSources.length; index += 1) {
|
|
1011
|
+
const sourcesInGroup = groupSources[index];
|
|
1012
|
+
if (!sourcesInGroup) {
|
|
1013
|
+
continue;
|
|
1014
|
+
}
|
|
1015
|
+
const groupArgs = groupCompileArgs[index];
|
|
1016
|
+
if (!groupArgs) {
|
|
1017
|
+
continue;
|
|
1018
|
+
}
|
|
1019
|
+
for (const source of sourcesInGroup) {
|
|
1020
|
+
objectFiles2.push(await compileSource(source, groupArgs, index));
|
|
1021
|
+
}
|
|
748
1022
|
}
|
|
749
1023
|
return objectFiles2;
|
|
750
1024
|
};
|
|
751
|
-
const
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
await runCommandWithEnv(
|
|
762
|
-
emccCommand,
|
|
763
|
-
linkArgs,
|
|
764
|
-
rootDir,
|
|
765
|
-
buildEnv,
|
|
766
|
-
emsdkOptions.signal
|
|
1025
|
+
const compileJobs = [];
|
|
1026
|
+
for (const source of baseSources) {
|
|
1027
|
+
compileJobs.push({
|
|
1028
|
+
source,
|
|
1029
|
+
args: baseCompileArgs,
|
|
1030
|
+
groupIndex: void 0
|
|
1031
|
+
});
|
|
1032
|
+
}
|
|
1033
|
+
logger.info(
|
|
1034
|
+
parallel ? `Building target: '${targetName}' [${compileJobs.length} files, in parallel]` : `Building target: '${targetName}' [${compileJobs.length} files]`
|
|
767
1035
|
);
|
|
1036
|
+
for (let index = 0; index < groupSources.length; index += 1) {
|
|
1037
|
+
const sourcesInGroup = groupSources[index];
|
|
1038
|
+
if (!sourcesInGroup) {
|
|
1039
|
+
continue;
|
|
1040
|
+
}
|
|
1041
|
+
const groupArgs = groupCompileArgs[index];
|
|
1042
|
+
if (!groupArgs) {
|
|
1043
|
+
continue;
|
|
1044
|
+
}
|
|
1045
|
+
for (const source of sourcesInGroup) {
|
|
1046
|
+
compileJobs.push({ source, args: groupArgs, groupIndex: index });
|
|
1047
|
+
}
|
|
1048
|
+
}
|
|
1049
|
+
const objectFiles = parallel ? await Promise.all(
|
|
1050
|
+
compileJobs.map(
|
|
1051
|
+
(job) => compileSource(job.source, job.args, job.groupIndex)
|
|
1052
|
+
)
|
|
1053
|
+
) : await buildObjectsSequential();
|
|
1054
|
+
if (targetType === "archive") {
|
|
1055
|
+
if (!emarCommand) {
|
|
1056
|
+
throw new Error("emar command is required for archive targets.");
|
|
1057
|
+
}
|
|
1058
|
+
logger.info(`Archiving target: ${targetName}.a`);
|
|
1059
|
+
const archiveArgs = ["rcs", resolvedOutFile, ...objectFiles];
|
|
1060
|
+
logger.debug(`emar ${archiveArgs.join(" ")}`);
|
|
1061
|
+
await runCommandWithEnv(
|
|
1062
|
+
emarCommand,
|
|
1063
|
+
archiveArgs,
|
|
1064
|
+
rootDir,
|
|
1065
|
+
buildEnv,
|
|
1066
|
+
emsdkOptions.signal
|
|
1067
|
+
);
|
|
1068
|
+
} else {
|
|
1069
|
+
logger.info(`Linking target: ${targetName}.wasm`);
|
|
1070
|
+
const linkArgs = [
|
|
1071
|
+
...objectFiles,
|
|
1072
|
+
"-o",
|
|
1073
|
+
resolvedOutFile,
|
|
1074
|
+
...linkLibDirs.map((dir) => `-L${dir}`),
|
|
1075
|
+
...resolvedLinkOptions,
|
|
1076
|
+
...exportArgs
|
|
1077
|
+
];
|
|
1078
|
+
logger.debug(`emcc ${linkArgs.join(" ")}`);
|
|
1079
|
+
await runCommandWithEnv(
|
|
1080
|
+
emccCommand,
|
|
1081
|
+
linkArgs,
|
|
1082
|
+
rootDir,
|
|
1083
|
+
buildEnv,
|
|
1084
|
+
emsdkOptions.signal
|
|
1085
|
+
);
|
|
1086
|
+
}
|
|
768
1087
|
outFiles[targetName] = resolvedOutFile;
|
|
769
1088
|
}
|
|
1089
|
+
};
|
|
1090
|
+
try {
|
|
1091
|
+
await buildTargets("archive");
|
|
1092
|
+
await buildTargets("wasm");
|
|
770
1093
|
} finally {
|
|
771
1094
|
if (cleanupBuildDir) {
|
|
772
1095
|
await promises.rm(buildRunDir, { recursive: true, force: true });
|
|
@@ -779,4 +1102,4 @@ const buildWasm = async (options) => {
|
|
|
779
1102
|
};
|
|
780
1103
|
exports.buildWasm = buildWasm;
|
|
781
1104
|
exports.prepareEmsdk = prepareEmsdk;
|
|
782
|
-
//# sourceMappingURL=build-
|
|
1105
|
+
//# sourceMappingURL=build-DwIdyC2W.cjs.map
|