[GH-ISSUE #365] wasm binary? #238

Open
opened 2026-02-25 22:32:56 +03:00 by kerem · 3 comments
Owner

Originally created by @andykais on GitHub (May 24, 2021).
Original GitHub issue: https://github.com/FiloSottile/mkcert/issues/365

Is there any chance of compiling this code to a wasm binary that can be imported into nodejs and deno projects? I want to use mkcert to generate localhost certificates for a local web app package, but it will require end users to install mkcert themselves, and run commands. If mkcert were usable as a wasm binary (literally just expose the command line interface as a function in js) then local web apps could ship with mkcert as a dependency and install the root CA and generate the localhost certs themselves as part of the initialization process.

An example of what initializing mkcert as a wasm module might look like:

const wasmCode = await Deno.readFile("mkcert.wasm");
const wasmModule = new WebAssembly.Module(wasmCode);
const wasmInstance = new WebAssembly.Instance(wasmModule);
const mkcert = wasmInstance.exports.main as CallableFunction;
await mkcert('-install');
await mkcert('localhost 127.0.0.1');
Originally created by @andykais on GitHub (May 24, 2021). Original GitHub issue: https://github.com/FiloSottile/mkcert/issues/365 Is there any chance of compiling this code to a wasm binary that can be imported into nodejs and deno projects? I want to use `mkcert` to generate localhost certificates for a local web app package, but it will require end users to install `mkcert` themselves, and run commands. If `mkcert` were usable as a wasm binary (literally just expose the command line interface as a function in js) then local web apps could ship with mkcert as a dependency and install the root CA and generate the localhost certs themselves as part of the initialization process. An example of what initializing mkcert as a wasm module might look like: ```ts const wasmCode = await Deno.readFile("mkcert.wasm"); const wasmModule = new WebAssembly.Module(wasmCode); const wasmInstance = new WebAssembly.Instance(wasmModule); const mkcert = wasmInstance.exports.main as CallableFunction; await mkcert('-install'); await mkcert('localhost 127.0.0.1'); ```
Author
Owner

@aral commented on GitHub (Dec 20, 2022):

I wonder if this would be possible to get working with the current state of WASI. Compiling to WASM, as I understand, is the easy part. Getting it to launch external processes (certutil) less so.

Update: until this is implemented, I don’t think there’s a way to make this work: https://github.com/WebAssembly/WASI/issues/414

<!-- gh-comment-id:1359372446 --> @aral commented on GitHub (Dec 20, 2022): I wonder if this would be possible to get working with the current state of WASI. Compiling to WASM, as I understand, is the easy part. Getting it to launch external processes (certutil) less so. Update: until this is implemented, I don’t think there’s a way to make this work: https://github.com/WebAssembly/WASI/issues/414
Author
Owner

@andykais commented on GitHub (Jan 3, 2023):

thanks for looking into this, it does look like we have to wait on upstream changes before this is possible

<!-- gh-comment-id:1369873564 --> @andykais commented on GitHub (Jan 3, 2023): thanks for looking into this, it does look like we have to wait on upstream changes before this is possible
Author
Owner

@augustobmoura commented on GitHub (Jun 14, 2023):

When trying to compile to WASM I'm getting the following errors:

# filippo.io/mkcert
./main.go:193:39: undefined: CertutilInstallHelp
./main.go:195:77: undefined: NSSBrowsers
./main.go:272:9: m.installPlatform undefined (type *mkcert has no field or method installPlatform)
./main.go:280:80: undefined: NSSBrowsers
./main.go:283:104: undefined: NSSBrowsers
./main.go:284:14: undefined: CertutilInstallHelp
./main.go:285:78: undefined: NSSBrowsers
./main.go:287:114: undefined: NSSBrowsers
./main.go:288:82: undefined: CertutilInstallHelp
./main.go:311:13: undefined: CertutilInstallHelp
./main.go:311:13: too many errors

Command run:

GOOS=js GOARCH=wasm go build -ldflags "-X main.Version=$(git describe --tags)" -o mkcert.wasm

Anyone knows what would be the problem? I'm not familiar with these type of Go compilation errors, the variables seems to be defined, but it throws undefined errors nonetheless, maybe a GOARCH=wasm limitation?

<!-- gh-comment-id:1591218126 --> @augustobmoura commented on GitHub (Jun 14, 2023): When trying to compile to WASM I'm getting the following errors: ``` # filippo.io/mkcert ./main.go:193:39: undefined: CertutilInstallHelp ./main.go:195:77: undefined: NSSBrowsers ./main.go:272:9: m.installPlatform undefined (type *mkcert has no field or method installPlatform) ./main.go:280:80: undefined: NSSBrowsers ./main.go:283:104: undefined: NSSBrowsers ./main.go:284:14: undefined: CertutilInstallHelp ./main.go:285:78: undefined: NSSBrowsers ./main.go:287:114: undefined: NSSBrowsers ./main.go:288:82: undefined: CertutilInstallHelp ./main.go:311:13: undefined: CertutilInstallHelp ./main.go:311:13: too many errors ``` Command run: ```bash GOOS=js GOARCH=wasm go build -ldflags "-X main.Version=$(git describe --tags)" -o mkcert.wasm ``` Anyone knows what would be the problem? I'm not familiar with these type of Go compilation errors, the variables seems to be defined, but it throws undefined errors nonetheless, maybe a `GOARCH=wasm` limitation?
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/mkcert#238
No description provided.