diff --git a/.gitignore b/.gitignore index 2fb37cb48..232ea1145 100644 --- a/.gitignore +++ b/.gitignore @@ -9,4 +9,4 @@ xcuserdata/ .vscode Examples/*/Bundle Examples/*/package-lock.json -/Package.resolved +Package.resolved diff --git a/Examples/ActorOnWebWorker/index.html b/Examples/ActorOnWebWorker/index.html index 2797702e1..4a16f16a0 100644 --- a/Examples/ActorOnWebWorker/index.html +++ b/Examples/ActorOnWebWorker/index.html @@ -8,7 +8,7 @@
diff --git a/Examples/OffscrenCanvas/.gitignore b/Examples/OffscrenCanvas/.gitignore deleted file mode 100644 index 0023a5340..000000000 --- a/Examples/OffscrenCanvas/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -.DS_Store -/.build -/Packages -xcuserdata/ -DerivedData/ -.swiftpm/configuration/registries.json -.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata -.netrc diff --git a/Examples/OffscrenCanvas/index.html b/Examples/OffscrenCanvas/index.html index 1202807a0..dd101b765 100644 --- a/Examples/OffscrenCanvas/index.html +++ b/Examples/OffscrenCanvas/index.html @@ -70,7 +70,7 @@
diff --git a/Plugins/PackageToJS/Sources/PackageToJS.swift b/Plugins/PackageToJS/Sources/PackageToJS.swift
index cc0c02182..c766995d2 100644
--- a/Plugins/PackageToJS/Sources/PackageToJS.swift
+++ b/Plugins/PackageToJS/Sources/PackageToJS.swift
@@ -357,7 +357,7 @@ struct PackagingPlanner {
/// The directory for intermediate files
let intermediatesDir: BuildPath
/// The filename of the .wasm file
- let wasmFilename = "main.wasm"
+ let wasmFilename: String
/// The path to the .wasm product artifact
let wasmProductArtifact: BuildPath
/// The build configuration
@@ -374,6 +374,7 @@ struct PackagingPlanner {
selfPackageDir: BuildPath,
outputDir: BuildPath,
wasmProductArtifact: BuildPath,
+ wasmFilename: String,
configuration: String,
triple: String,
selfPath: BuildPath = BuildPath(absolute: #filePath),
@@ -384,6 +385,7 @@ struct PackagingPlanner {
self.selfPackageDir = selfPackageDir
self.outputDir = outputDir
self.intermediatesDir = intermediatesDir
+ self.wasmFilename = wasmFilename
self.selfPath = selfPath
self.wasmProductArtifact = wasmProductArtifact
self.configuration = configuration
diff --git a/Plugins/PackageToJS/Sources/PackageToJSPlugin.swift b/Plugins/PackageToJS/Sources/PackageToJSPlugin.swift
index 4bf6a1106..2844d52ec 100644
--- a/Plugins/PackageToJS/Sources/PackageToJSPlugin.swift
+++ b/Plugins/PackageToJS/Sources/PackageToJSPlugin.swift
@@ -119,7 +119,9 @@ struct PackageToJSPlugin: CommandPlugin {
)
let planner = PackagingPlanner(
options: buildOptions.packageOptions, context: context, selfPackage: selfPackage,
- outputDir: outputDir, wasmProductArtifact: productArtifact)
+ outputDir: outputDir, wasmProductArtifact: productArtifact,
+ wasmFilename: productArtifact.lastPathComponent
+ )
let rootTask = try planner.planBuild(
make: &make, buildOptions: buildOptions)
cleanIfBuildGraphChanged(root: rootTask, make: make, context: context)
@@ -193,7 +195,14 @@ struct PackageToJSPlugin: CommandPlugin {
)
let planner = PackagingPlanner(
options: testOptions.packageOptions, context: context, selfPackage: selfPackage,
- outputDir: outputDir, wasmProductArtifact: productArtifact)
+ outputDir: outputDir, wasmProductArtifact: productArtifact,
+ // If the product artifact doesn't have a .wasm extension, add it
+ // to deliver it with the correct MIME type when serving the test
+ // files for browser tests.
+ wasmFilename: productArtifact.lastPathComponent.hasSuffix(".wasm")
+ ? productArtifact.lastPathComponent
+ : productArtifact.lastPathComponent + ".wasm"
+ )
let (rootTask, binDir) = try planner.planTestBuild(
make: &make)
cleanIfBuildGraphChanged(root: rootTask, make: make, context: context)
@@ -486,7 +495,8 @@ extension PackagingPlanner {
context: PluginContext,
selfPackage: Package,
outputDir: URL,
- wasmProductArtifact: URL
+ wasmProductArtifact: URL,
+ wasmFilename: String
) {
let outputBaseName = outputDir.lastPathComponent
let (configuration, triple) = PackageToJS.deriveBuildConfiguration(wasmProductArtifact: wasmProductArtifact)
@@ -498,6 +508,7 @@ extension PackagingPlanner {
selfPackageDir: BuildPath(absolute: selfPackage.directoryURL.path),
outputDir: BuildPath(absolute: outputDir.path),
wasmProductArtifact: BuildPath(absolute: wasmProductArtifact.path),
+ wasmFilename: wasmFilename,
configuration: configuration,
triple: triple,
system: system
diff --git a/Plugins/PackageToJS/Templates/index.d.ts b/Plugins/PackageToJS/Templates/index.d.ts
index 4a1074c14..11d5908c2 100644
--- a/Plugins/PackageToJS/Templates/index.d.ts
+++ b/Plugins/PackageToJS/Templates/index.d.ts
@@ -1,29 +1,21 @@
-import type { Import, Export } from './instantiate.js'
+import type { Export, ModuleSource } from './instantiate.js'
export type Options = {
/**
- * The CLI arguments to pass to the WebAssembly module
+ * The WebAssembly module to instantiate
+ *
+ * If not provided, the module will be fetched from the default path.
*/
- args?: string[]
-/* #if USE_SHARED_MEMORY */
- /**
- * The WebAssembly memory to use (must be 'shared')
- */
- memory: WebAssembly.Memory
-/* #endif */
+ module?: ModuleSource
}
/**
- * Initialize the given WebAssembly module
+ * Instantiate and initialize the module
*
- * This is a convenience function that creates an instantiator and instantiates the module.
- * @param moduleSource - The WebAssembly module to instantiate
- * @param imports - The imports to add
- * @param options - The options
+ * This is a convenience function for browser environments.
+ * If you need a more flexible API, see `instantiate`.
*/
-export declare function init(
- moduleSource: WebAssembly.Module | ArrayBufferView | ArrayBuffer | Response | PromiseLike