emsdk-env 0.2.0 → 0.3.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-qp0IEBnb.js → build-CYHeaOdc.js} +146 -39
- package/dist/{build-qp0IEBnb.js.map → build-CYHeaOdc.js.map} +1 -1
- package/dist/{build-oenTJc-4.cjs → build-DdEthYh8.cjs} +146 -39
- package/dist/{build-oenTJc-4.cjs.map → build-DdEthYh8.cjs.map} +1 -1
- package/dist/index.cjs +3 -3
- package/dist/index.d.ts +169 -32
- package/dist/index.mjs +3 -3
- package/dist/vite.cjs +3 -3
- package/dist/vite.cjs.map +1 -1
- package/dist/vite.d.ts +146 -21
- package/dist/vite.mjs +3 -3
- 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.3.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: 4a03739b8c88111950fa216a7c10c7bfd65ea239
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
"use strict";
|
|
@@ -531,7 +531,7 @@ const createBuildId = () => {
|
|
|
531
531
|
const seq = String(buildSequence).padStart(4, "0");
|
|
532
532
|
return `${timestamp}_${seq}_${process.pid}`;
|
|
533
533
|
};
|
|
534
|
-
const ensureArray = (value) => value ?
|
|
534
|
+
const ensureArray = (value) => value != null ? value : [];
|
|
535
535
|
const normalizePrepareOptions = (options) => {
|
|
536
536
|
const { targetVersion, ...rest } = options != null ? options : {};
|
|
537
537
|
return {
|
|
@@ -571,9 +571,15 @@ const resolveOutFile = (outFile, env, outDir) => {
|
|
|
571
571
|
const expanded = expandPlaceholders(outFile, env, "outFile");
|
|
572
572
|
return resolvePath(outDir, expanded);
|
|
573
573
|
};
|
|
574
|
-
const
|
|
575
|
-
const expanded = expandArray(patterns, env,
|
|
576
|
-
|
|
574
|
+
const resolveSourcesFromPatterns = async (patterns, env, srcDir, label) => {
|
|
575
|
+
const expanded = expandArray(patterns, env, label);
|
|
576
|
+
const resolvedPatterns = expanded.map((value) => resolvePath(srcDir, value));
|
|
577
|
+
const results = await Promise.all(
|
|
578
|
+
resolvedPatterns.map((pattern) => glob.glob(pattern, { nodir: true }))
|
|
579
|
+
);
|
|
580
|
+
const sources = results.flat();
|
|
581
|
+
sources.sort();
|
|
582
|
+
return sources;
|
|
577
583
|
};
|
|
578
584
|
const buildDefineFlags = (defines) => Object.entries(defines).map(([key, value]) => `-D${key}=${String(value)}`);
|
|
579
585
|
const buildExportFlags = (exports$1) => {
|
|
@@ -595,17 +601,37 @@ const resolveTargetOutFile = (targetName, targetOutFile, env, outDir) => {
|
|
|
595
601
|
};
|
|
596
602
|
const resolveTargetSources = async (targetSources, env, srcDir) => {
|
|
597
603
|
const patterns = targetSources && targetSources.length > 0 ? targetSources : [path.join(srcDir, "**", "*.c"), path.join(srcDir, "**", "*.cpp")];
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
604
|
+
return resolveSourcesFromPatterns(patterns, env, srcDir, "sources");
|
|
605
|
+
};
|
|
606
|
+
const toSafeObjectName = (rootDir, sourcePath, groupIndex) => {
|
|
607
|
+
const baseName = path.relative(rootDir, sourcePath).replace(/[\\/]/g, "_").replace(/[^A-Za-z0-9._-]/g, "_");
|
|
608
|
+
if (groupIndex === void 0) {
|
|
609
|
+
return baseName;
|
|
610
|
+
}
|
|
611
|
+
return `${baseName}__g${groupIndex}`;
|
|
612
|
+
};
|
|
613
|
+
const dedupeSources = (sources) => {
|
|
614
|
+
const seen = /* @__PURE__ */ new Set();
|
|
615
|
+
const deduped = [];
|
|
616
|
+
for (const source of sources) {
|
|
617
|
+
if (seen.has(source)) {
|
|
618
|
+
continue;
|
|
619
|
+
}
|
|
620
|
+
seen.add(source);
|
|
621
|
+
deduped.push(source);
|
|
622
|
+
}
|
|
623
|
+
return deduped;
|
|
624
|
+
};
|
|
625
|
+
const buildCompileArgs = (options, includeDirs, defines, env, rootDir) => {
|
|
626
|
+
const resolvedOptions = expandArray(options, env, "options");
|
|
627
|
+
const includeArgs = resolveIncludeDirs(includeDirs, env, rootDir).map(
|
|
628
|
+
(dir) => `-I${dir}`
|
|
601
629
|
);
|
|
602
|
-
const
|
|
603
|
-
|
|
604
|
-
return sources;
|
|
630
|
+
const defineArgs = buildDefineFlags(resolveDefines(defines, env));
|
|
631
|
+
return { resolvedOptions, includeArgs, defineArgs };
|
|
605
632
|
};
|
|
606
|
-
const toSafeObjectName = (rootDir, sourcePath) => path.relative(rootDir, sourcePath).replace(/[\\/]/g, "_").replace(/[^A-Za-z0-9._-]/g, "_");
|
|
607
633
|
const buildWasm = async (options) => {
|
|
608
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
634
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
609
635
|
if (!options) {
|
|
610
636
|
throw new TypeError("options must be provided.");
|
|
611
637
|
}
|
|
@@ -663,10 +689,6 @@ const buildWasm = async (options) => {
|
|
|
663
689
|
const outFiles = {};
|
|
664
690
|
try {
|
|
665
691
|
for (const [targetName, target] of targets) {
|
|
666
|
-
const mergedOptions = [
|
|
667
|
-
...ensureArray(common.options),
|
|
668
|
-
...ensureArray(target.options)
|
|
669
|
-
];
|
|
670
692
|
const mergedLinkOptions = [
|
|
671
693
|
...ensureArray(common.linkOptions),
|
|
672
694
|
...ensureArray(target.linkOptions)
|
|
@@ -675,11 +697,16 @@ const buildWasm = async (options) => {
|
|
|
675
697
|
...ensureArray(common.exports),
|
|
676
698
|
...ensureArray(target.exports)
|
|
677
699
|
];
|
|
678
|
-
const
|
|
700
|
+
const baseCompileOptions = [
|
|
701
|
+
...ensureArray(common.options),
|
|
702
|
+
...ensureArray(target.options)
|
|
703
|
+
];
|
|
704
|
+
const baseIncludeDirs = [
|
|
679
705
|
...ensureArray(common.includeDirs),
|
|
680
706
|
...ensureArray(target.includeDirs)
|
|
681
707
|
];
|
|
682
|
-
const
|
|
708
|
+
const baseDefines = mergeDefines(common.defines, target.defines);
|
|
709
|
+
const sourceGroups = (_i = target.sourceGroups) != null ? _i : [];
|
|
683
710
|
const targetEnv = {
|
|
684
711
|
...envWithDirs,
|
|
685
712
|
TARGET_NAME: targetName
|
|
@@ -696,13 +723,35 @@ const buildWasm = async (options) => {
|
|
|
696
723
|
targetEnv,
|
|
697
724
|
srcDir
|
|
698
725
|
);
|
|
699
|
-
|
|
726
|
+
const groupSources = sourceGroups.map(() => []);
|
|
727
|
+
const groupSourceSet = /* @__PURE__ */ new Set();
|
|
728
|
+
for (let index = 0; index < sourceGroups.length; index += 1) {
|
|
729
|
+
const group = sourceGroups[index];
|
|
730
|
+
if (!group) {
|
|
731
|
+
continue;
|
|
732
|
+
}
|
|
733
|
+
const resolved = await resolveSourcesFromPatterns(
|
|
734
|
+
group.sources,
|
|
735
|
+
targetEnv,
|
|
736
|
+
srcDir,
|
|
737
|
+
`sourceGroups[${index}].sources`
|
|
738
|
+
);
|
|
739
|
+
const deduped = dedupeSources(resolved);
|
|
740
|
+
groupSources[index] = deduped;
|
|
741
|
+
for (const source of deduped) {
|
|
742
|
+
groupSourceSet.add(source);
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
const baseSources = sources.filter(
|
|
746
|
+
(source) => !groupSourceSet.has(source)
|
|
747
|
+
);
|
|
748
|
+
const groupedSources = groupSources.flat();
|
|
749
|
+
if (baseSources.length + groupedSources.length === 0) {
|
|
700
750
|
throw new Error(`No sources matched for target: ${targetName}`);
|
|
701
751
|
}
|
|
702
752
|
const targetBuildDir = path.resolve(buildRunDir, targetName);
|
|
703
753
|
await promises.rm(targetBuildDir, { recursive: true, force: true });
|
|
704
754
|
await ensureDirectory(targetBuildDir);
|
|
705
|
-
const resolvedOptions = expandArray(mergedOptions, targetEnv, "options");
|
|
706
755
|
const resolvedLinkOptions = expandArray(
|
|
707
756
|
mergedLinkOptions,
|
|
708
757
|
targetEnv,
|
|
@@ -710,31 +759,49 @@ const buildWasm = async (options) => {
|
|
|
710
759
|
);
|
|
711
760
|
const resolvedExports = expandArray(mergedExports, targetEnv, "exports");
|
|
712
761
|
const exportArgs = buildExportFlags(resolvedExports);
|
|
713
|
-
const
|
|
714
|
-
|
|
762
|
+
const baseCompileArgs = buildCompileArgs(
|
|
763
|
+
baseCompileOptions,
|
|
764
|
+
baseIncludeDirs,
|
|
765
|
+
baseDefines,
|
|
715
766
|
targetEnv,
|
|
716
767
|
rootDir
|
|
717
|
-
).map((dir) => `-I${dir}`);
|
|
718
|
-
const defineArgs = buildDefineFlags(
|
|
719
|
-
resolveDefines(mergedDefines, targetEnv)
|
|
720
768
|
);
|
|
769
|
+
const groupCompileArgs = sourceGroups.map((group) => {
|
|
770
|
+
var _a2;
|
|
771
|
+
const groupOptions = [
|
|
772
|
+
...baseCompileOptions,
|
|
773
|
+
...ensureArray(group == null ? void 0 : group.options)
|
|
774
|
+
];
|
|
775
|
+
const groupIncludeDirs = [
|
|
776
|
+
...baseIncludeDirs,
|
|
777
|
+
...ensureArray(group == null ? void 0 : group.includeDirs)
|
|
778
|
+
];
|
|
779
|
+
const groupDefines = mergeDefines(baseDefines, (_a2 = group == null ? void 0 : group.defines) != null ? _a2 : {});
|
|
780
|
+
return buildCompileArgs(
|
|
781
|
+
groupOptions,
|
|
782
|
+
groupIncludeDirs,
|
|
783
|
+
groupDefines,
|
|
784
|
+
targetEnv,
|
|
785
|
+
rootDir
|
|
786
|
+
);
|
|
787
|
+
});
|
|
721
788
|
logger.info(`Compiling target: ${targetName}`);
|
|
722
|
-
const compileSource = async (source) => {
|
|
723
|
-
const objectName = toSafeObjectName(rootDir, source);
|
|
789
|
+
const compileSource = async (source, args, groupIndex) => {
|
|
790
|
+
const objectName = toSafeObjectName(rootDir, source, groupIndex);
|
|
724
791
|
const outputObject = path.resolve(targetBuildDir, `${objectName}.o`);
|
|
725
|
-
const
|
|
792
|
+
const compileArgs = [
|
|
726
793
|
"-c",
|
|
727
794
|
source,
|
|
728
795
|
"-o",
|
|
729
796
|
outputObject,
|
|
730
|
-
...resolvedOptions,
|
|
731
|
-
...includeArgs,
|
|
732
|
-
...defineArgs
|
|
797
|
+
...args.resolvedOptions,
|
|
798
|
+
...args.includeArgs,
|
|
799
|
+
...args.defineArgs
|
|
733
800
|
];
|
|
734
|
-
logger.debug(`emcc ${
|
|
801
|
+
logger.debug(`emcc ${compileArgs.join(" ")}`);
|
|
735
802
|
await runCommandWithEnv(
|
|
736
803
|
emccCommand,
|
|
737
|
-
|
|
804
|
+
compileArgs,
|
|
738
805
|
rootDir,
|
|
739
806
|
buildEnv,
|
|
740
807
|
emsdkOptions.signal
|
|
@@ -743,12 +810,52 @@ const buildWasm = async (options) => {
|
|
|
743
810
|
};
|
|
744
811
|
const buildObjectsSequential = async () => {
|
|
745
812
|
const objectFiles2 = [];
|
|
746
|
-
for (const source of
|
|
747
|
-
objectFiles2.push(
|
|
813
|
+
for (const source of baseSources) {
|
|
814
|
+
objectFiles2.push(
|
|
815
|
+
await compileSource(source, baseCompileArgs, void 0)
|
|
816
|
+
);
|
|
817
|
+
}
|
|
818
|
+
for (let index = 0; index < groupSources.length; index += 1) {
|
|
819
|
+
const sourcesInGroup = groupSources[index];
|
|
820
|
+
if (!sourcesInGroup) {
|
|
821
|
+
continue;
|
|
822
|
+
}
|
|
823
|
+
const groupArgs = groupCompileArgs[index];
|
|
824
|
+
if (!groupArgs) {
|
|
825
|
+
continue;
|
|
826
|
+
}
|
|
827
|
+
for (const source of sourcesInGroup) {
|
|
828
|
+
objectFiles2.push(await compileSource(source, groupArgs, index));
|
|
829
|
+
}
|
|
748
830
|
}
|
|
749
831
|
return objectFiles2;
|
|
750
832
|
};
|
|
751
|
-
const
|
|
833
|
+
const compileJobs = [];
|
|
834
|
+
for (const source of baseSources) {
|
|
835
|
+
compileJobs.push({
|
|
836
|
+
source,
|
|
837
|
+
args: baseCompileArgs,
|
|
838
|
+
groupIndex: void 0
|
|
839
|
+
});
|
|
840
|
+
}
|
|
841
|
+
for (let index = 0; index < groupSources.length; index += 1) {
|
|
842
|
+
const sourcesInGroup = groupSources[index];
|
|
843
|
+
if (!sourcesInGroup) {
|
|
844
|
+
continue;
|
|
845
|
+
}
|
|
846
|
+
const groupArgs = groupCompileArgs[index];
|
|
847
|
+
if (!groupArgs) {
|
|
848
|
+
continue;
|
|
849
|
+
}
|
|
850
|
+
for (const source of sourcesInGroup) {
|
|
851
|
+
compileJobs.push({ source, args: groupArgs, groupIndex: index });
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
const objectFiles = parallel ? await Promise.all(
|
|
855
|
+
compileJobs.map(
|
|
856
|
+
(job) => compileSource(job.source, job.args, job.groupIndex)
|
|
857
|
+
)
|
|
858
|
+
) : await buildObjectsSequential();
|
|
752
859
|
logger.info(`Linking target: ${targetName}`);
|
|
753
860
|
const linkArgs = [
|
|
754
861
|
...objectFiles,
|
|
@@ -779,4 +886,4 @@ const buildWasm = async (options) => {
|
|
|
779
886
|
};
|
|
780
887
|
exports.buildWasm = buildWasm;
|
|
781
888
|
exports.prepareEmsdk = prepareEmsdk;
|
|
782
|
-
//# sourceMappingURL=build-
|
|
889
|
+
//# sourceMappingURL=build-DdEthYh8.cjs.map
|