Make async wasm work
Some checks failed
Podman Rootless Demo / test-backend (push) Has been skipped
Podman Rootless Demo / test-frontend (push) Has been skipped
Podman Rootless Demo / build-backend (push) Has been skipped
Podman Rootless Demo / build-frontend (push) Failing after 7m53s
Podman Rootless Demo / deploy-prod (push) Has been skipped
Some checks failed
Podman Rootless Demo / test-backend (push) Has been skipped
Podman Rootless Demo / test-frontend (push) Has been skipped
Podman Rootless Demo / build-backend (push) Has been skipped
Podman Rootless Demo / build-frontend (push) Failing after 7m53s
Podman Rootless Demo / deploy-prod (push) Has been skipped
This commit is contained in:
parent
ba89ea6271
commit
ec8d90cb15
3 changed files with 14 additions and 14 deletions
|
|
@ -23,7 +23,7 @@ RUN echo 'git-fetch-with-cli = true' >> $CARGO_HOME/config.toml
|
||||||
# Copy WASM source and build
|
# Copy WASM source and build
|
||||||
COPY wasm/Cargo.toml wasm/Cargo.lock ./wasm/
|
COPY wasm/Cargo.toml wasm/Cargo.lock ./wasm/
|
||||||
COPY wasm/src ./wasm/src/
|
COPY wasm/src ./wasm/src/
|
||||||
RUN cd wasm && wasm-pack build --target web
|
RUN cd wasm && wasm-pack build --target bundler
|
||||||
|
|
||||||
# ---------- build ----------
|
# ---------- build ----------
|
||||||
FROM docker.io/node:20-slim AS builder
|
FROM docker.io/node:20-slim AS builder
|
||||||
|
|
|
||||||
|
|
@ -25,8 +25,8 @@ const nextConfig: NextConfig = {
|
||||||
// Enable WASM support
|
// Enable WASM support
|
||||||
config.experiments = {
|
config.experiments = {
|
||||||
...config.experiments,
|
...config.experiments,
|
||||||
asyncWebAssembly: false,
|
asyncWebAssembly: true,
|
||||||
syncWebAssembly: true,
|
syncWebAssembly: false,
|
||||||
layers: true,
|
layers: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -37,7 +37,7 @@ const nextConfig: NextConfig = {
|
||||||
...(config.module?.rules || []),
|
...(config.module?.rules || []),
|
||||||
{
|
{
|
||||||
test: /\.wasm$/,
|
test: /\.wasm$/,
|
||||||
type: 'webassembly/sync',
|
type: 'webassembly/async',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -54,33 +54,33 @@ export class PassportWASMLoader {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Dynamically import the WASM module - for sync WebAssembly
|
// Dynamically import the WASM bindings - they handle the WASM initialization
|
||||||
const wasm = await import('./wasm-pkg/sharenet_passport_wasm_bg');
|
const wasmModule = await import('./wasm-pkg/sharenet_passport_wasm');
|
||||||
const init = await import('./wasm-pkg/sharenet_passport_wasm');
|
|
||||||
|
|
||||||
// Initialize the WASM module
|
// Initialize the WASM module using the default export
|
||||||
await init.default();
|
// With bundler target, this automatically handles the WASM loading
|
||||||
|
await wasmModule.default();
|
||||||
|
|
||||||
// Create wrapper functions with proper typing
|
// Create wrapper functions with proper typing
|
||||||
const wasmModule: PassportWASM = {
|
const wasmWrapper: PassportWASM = {
|
||||||
parse_spf_file: async (data: Uint8Array, password: string): Promise<SPFPassport> => {
|
parse_spf_file: async (data: Uint8Array, password: string): Promise<SPFPassport> => {
|
||||||
const result = wasm.parse_spf_file(data, password);
|
const result = wasmModule.parse_spf_file(data, password);
|
||||||
// The WASM function returns a JsValue that we need to convert
|
// The WASM function returns a JsValue that we need to convert
|
||||||
// For now, we'll assume it returns the correct structure
|
// For now, we'll assume it returns the correct structure
|
||||||
return result as unknown as SPFPassport;
|
return result as unknown as SPFPassport;
|
||||||
},
|
},
|
||||||
|
|
||||||
get_profiles_from_passport: async (data: Uint8Array, password: string): Promise<UserProfile[]> => {
|
get_profiles_from_passport: async (data: Uint8Array, password: string): Promise<UserProfile[]> => {
|
||||||
const result = wasm.get_profiles_from_passport(data, password);
|
const result = wasmModule.get_profiles_from_passport(data, password);
|
||||||
return result as unknown as UserProfile[];
|
return result as unknown as UserProfile[];
|
||||||
},
|
},
|
||||||
|
|
||||||
validate_spf_signature: async (data: Uint8Array, signature: Uint8Array): Promise<boolean> => {
|
validate_spf_signature: async (data: Uint8Array, signature: Uint8Array): Promise<boolean> => {
|
||||||
return wasm.validate_spf_signature(data, signature);
|
return wasmModule.validate_spf_signature(data, signature);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
return wasmModule;
|
return wasmWrapper;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to load WASM module:', error);
|
console.error('Failed to load WASM module:', error);
|
||||||
throw new Error(`Failed to load WASM module: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
throw new Error(`Failed to load WASM module: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue