With go you can inject variables using ldflags like this:
go build -o ./main.wasm -ldflags "-X main.Version=$(VERSION)" ./main.go
Attempting this with tinygo:
tinygo build -o ./main.wasm -target wasm -ldflags "-X main.Version=$(VERSION)" ./main.go
Gives:
tinygo:wasm-ld: error: unknown argument: -X
tinygo:wasm-ld: error: cannot open main.Version=1.0.0: No such file or directory
error: failed to link /var/folders/jc/3lr9ltt96k90h_mg_xq6pvbw0000gn/T/tinygo833831446/main: failed to link using built-in wasm-ld
Is there an equivalent way to achieve this in tinygo?
Right now, unfortunately not. However I think functionality like this would be useful in the long term (for example, to set a WiFi password at compile time when you're building firmware for a personal IoT-like device).
@aykevl I really need this feature for something. Any thoughts on implementation that we could work on?
Most helpful comment
Right now, unfortunately not. However I think functionality like this would be useful in the long term (for example, to set a WiFi password at compile time when you're building firmware for a personal IoT-like device).