Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wasm binary? #365

Open
andykais opened this issue May 24, 2021 · 3 comments
Open

wasm binary? #365

andykais opened this issue May 24, 2021 · 3 comments

Comments

@andykais
Copy link

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');
@aral
Copy link

aral commented 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: WebAssembly/WASI#414

@andykais
Copy link
Author

andykais commented Jan 3, 2023

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

@augustobmoura
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants