@@ -614,54 +614,13 @@ struct PackagingPlanner {
614614 packageInputs. append ( packageJsonTask)
615615
616616 if !skeletons. isEmpty {
617- let bridge = try loadBridgeJS ( )
618- let skeletonFiles = skeletons. map { BuildPath ( absolute: $0. source. path) }
619- let bridgeJs = outputDir. appending ( path: " bridge-js.js " )
620- let bridgeDts = outputDir. appending ( path: " bridge-js.d.ts " )
621- let bridgeModules = outputDir. appending ( path: " bridge-js-modules " )
622617 packageInputs. append (
623- make. addTask (
624- inputFiles: skeletonFiles + [ selfPath, wasmImportsPath] ,
625- inputTasks: [ outputDirTask, wasmImportsTask] ,
626- output: bridgeJs
627- ) { _, scope in
628- let features = try Self . loadWasmFeatures ( at: scope. resolve ( path: wasmImportsPath) )
629- let output = try bridge. link. link ( sharedMemory: features. sharedMemory)
630- try system. writeFile (
631- atPath: scope. resolve ( path: bridgeJs) . path,
632- content: Data ( output. outputJs. utf8)
633- )
634- try system. writeFile (
635- atPath: scope. resolve ( path: bridgeDts) . path,
636- content: Data ( output. outputDts. utf8)
637- )
638- }
639- )
640- let bridgeModulesStamp = intermediatesDir. appending ( path: " bridge-js-modules.stamp " )
641- packageInputs. append (
642- make. addTask (
643- inputFiles: skeletonFiles + bridge. modules. map ( \. source) + [ selfPath] ,
644- inputTasks: [ outputDirTask, intermediatesDirTask] ,
645- output: bridgeModulesStamp
646- ) { _, scope in
647- let modulesDirectory = scope. resolve ( path: bridgeModules)
648- try system. removeItemIfExists ( atPath: modulesDirectory. path)
649- if !bridge. modules. isEmpty {
650- try system. createDirectory ( atPath: modulesDirectory. path)
651- }
652- for module in bridge. modules {
653- let destination = scope. resolve ( path: outputDir. appending ( path: module. relativeOutputPath) )
654- try system. createDirectory ( atPath: destination. deletingLastPathComponent ( ) . path)
655- try system. syncFile (
656- from: scope. resolve ( path: module. source) . path,
657- to: destination. path
658- )
659- }
660- try system. writeFile (
661- atPath: scope. resolve ( path: bridgeModulesStamp) . path,
662- content: Data ( )
663- )
664- }
618+ contentsOf: try planBridgeJS (
619+ make: & make,
620+ outputDirTask: outputDirTask,
621+ intermediatesDirTask: intermediatesDirTask,
622+ wasmImportsTask: wasmImportsTask
623+ )
665624 )
666625 }
667626
@@ -736,11 +695,15 @@ struct PackagingPlanner {
736695 )
737696 }
738697
739- /// Plan the shared npm install for a directory that hosts several per-runner test
740- /// bundles as subdirectories. Node resolves `node_modules` by walking up the directory
741- /// tree, so a single install here serves every runner underneath, avoiding one install
742- /// per test target.
743- func planSharedNodeModules( make: inout MiniMake ) throws -> MiniMake . TaskKey {
698+ /// Plan the artifacts that several per-runner test bundles packaged as subdirectories
699+ /// share.
700+ ///
701+ /// Node resolves `node_modules` by walking up the directory tree, so a single install
702+ /// here serves every runner underneath, avoiding one install per test target. The glue
703+ /// generated here describes every test target rather than the one target a runner links
704+ /// in, so that test preludes - which are loaded for every runner and import it by a
705+ /// fixed path - see the whole package's API.
706+ func planSharedTestArtifacts( make: inout MiniMake ) throws -> MiniMake . TaskKey {
744707 let outputDirTask = make. addTask (
745708 inputFiles: [ selfPath] ,
746709 output: outputDir,
@@ -765,13 +728,87 @@ struct PackagingPlanner {
765728 inputFiles: [ ] ,
766729 inputTasks: [ ]
767730 )
768- return planNpmInstall (
769- make: & make,
770- intermediatesDirTask: intermediatesDirTask,
771- packageJsonTask: packageJsonTask
731+ var tasks = [
732+ planNpmInstall (
733+ make: & make,
734+ intermediatesDirTask: intermediatesDirTask,
735+ packageJsonTask: packageJsonTask
736+ )
737+ ]
738+ if !skeletons. isEmpty {
739+ tasks. append (
740+ contentsOf: try planBridgeJS (
741+ make: & make,
742+ outputDirTask: outputDirTask,
743+ intermediatesDirTask: intermediatesDirTask,
744+ wasmImportsTask: wasmImportsTask
745+ )
746+ )
747+ }
748+ return make. addTask (
749+ inputTasks: tasks,
750+ output: BuildPath ( phony: " shared-test-artifacts " ) ,
751+ attributes: [ . phony, . silent]
772752 )
773753 }
774754
755+ /// Plan the tasks generating the BridgeJS glue and syncing the JavaScript modules it
756+ /// imports into the output directory
757+ private func planBridgeJS(
758+ make: inout MiniMake ,
759+ outputDirTask: MiniMake . TaskKey ,
760+ intermediatesDirTask: MiniMake . TaskKey ,
761+ wasmImportsTask: MiniMake . TaskKey
762+ ) throws -> [ MiniMake . TaskKey ] {
763+ let bridge = try loadBridgeJS ( )
764+ let skeletonFiles = skeletons. map { BuildPath ( absolute: $0. source. path) }
765+ let wasmImportsPath = self . wasmImportsPath
766+ let bridgeJs = outputDir. appending ( path: " bridge-js.js " )
767+ let bridgeDts = outputDir. appending ( path: " bridge-js.d.ts " )
768+ let bridgeModules = outputDir. appending ( path: " bridge-js-modules " )
769+ let bridgeJsTask = make. addTask (
770+ inputFiles: skeletonFiles + [ selfPath, wasmImportsPath] ,
771+ inputTasks: [ outputDirTask, wasmImportsTask] ,
772+ output: bridgeJs
773+ ) { _, scope in
774+ let features = try Self . loadWasmFeatures ( at: scope. resolve ( path: wasmImportsPath) )
775+ let output = try bridge. link. link ( sharedMemory: features. sharedMemory)
776+ try system. writeFile (
777+ atPath: scope. resolve ( path: bridgeJs) . path,
778+ content: Data ( output. outputJs. utf8)
779+ )
780+ try system. writeFile (
781+ atPath: scope. resolve ( path: bridgeDts) . path,
782+ content: Data ( output. outputDts. utf8)
783+ )
784+ }
785+ let bridgeModulesStamp = intermediatesDir. appending ( path: " bridge-js-modules.stamp " )
786+ let bridgeModulesTask = make. addTask (
787+ inputFiles: skeletonFiles + bridge. modules. map ( \. source) + [ selfPath] ,
788+ inputTasks: [ outputDirTask, intermediatesDirTask] ,
789+ output: bridgeModulesStamp
790+ ) { _, scope in
791+ let modulesDirectory = scope. resolve ( path: bridgeModules)
792+ try system. removeItemIfExists ( atPath: modulesDirectory. path)
793+ if !bridge. modules. isEmpty {
794+ try system. createDirectory ( atPath: modulesDirectory. path)
795+ }
796+ for module in bridge. modules {
797+ let destination = scope. resolve ( path: outputDir. appending ( path: module. relativeOutputPath) )
798+ try system. createDirectory ( atPath: destination. deletingLastPathComponent ( ) . path)
799+ try system. syncFile (
800+ from: scope. resolve ( path: module. source) . path,
801+ to: destination. path
802+ )
803+ }
804+ try system. writeFile (
805+ atPath: scope. resolve ( path: bridgeModulesStamp) . path,
806+ content: Data ( )
807+ )
808+ }
809+ return [ bridgeJsTask, bridgeModulesTask]
810+ }
811+
775812 /// Plan the task parsing the imports of the product .wasm file
776813 ///
777814 /// NOTE: The imports are parsed from the product artifact instead of the final .wasm
0 commit comments