Skip to content

Commit

Permalink
cmd/go: add GOWASM environment variable
Browse files Browse the repository at this point in the history
This change adds the environment variable GOWASM, which is a comma
separated list of experimental WebAssembly features that the compiled
WebAssembly binary is allowed to use. The default is to use no
experimental features. Initially there are no features avaiable.

More information about feature proposals can be found at
https://github.com/WebAssembly/proposals

Change-Id: I4c8dc534c99ecff8bb075dded0186ca8f8decaef
Reviewed-on: https://go-review.googlesource.com/c/go/+/168881
Run-TryBot: Richard Musiol <[email protected]>
TryBot-Result: Gobot Gobot <[email protected]>
Reviewed-by: Brad Fitzpatrick <[email protected]>
  • Loading branch information
neelance authored and Richard Musiol committed Mar 23, 2019
1 parent 2396101 commit b434bbf
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
11 changes: 11 additions & 0 deletions doc/install-source.html
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,17 @@ <h2 id="environment">Optional environment variables</h2>
</ul>
</li>


<li><code>$GOWASM</code> (for <code>wasm</code> only)
<p>
This variable is a comma separated list of <a href="https://github.com/WebAssembly/proposals">experimental WebAssembly features</a> that the compiled WebAssembly binary is allowed to use.
The default is to use no experimental features.
</p>
<ul>
<li>(no features yet)</li>
</ul>
</li>

</ul>

<p>
Expand Down
1 change: 1 addition & 0 deletions src/cmd/go/internal/cfg/cfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ var (
GOMIPS = objabi.GOMIPS
GOMIPS64 = objabi.GOMIPS64
GOPPC64 = fmt.Sprintf("%s%d", "power", objabi.GOPPC64)
GOWASM = objabi.GOWASM
)

// Update build context to use our computed GOROOT.
Expand Down
2 changes: 2 additions & 0 deletions src/cmd/go/internal/envcmd/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ func MkEnv() []cfg.EnvVar {
env = append(env, cfg.EnvVar{Name: "GOMIPS64", Value: cfg.GOMIPS64})
case "ppc64", "ppc64le":
env = append(env, cfg.EnvVar{Name: "GOPPC64", Value: cfg.GOPPC64})
case "wasm":
env = append(env, cfg.EnvVar{Name: "GOWASM", Value: cfg.GOWASM.String()})
}

cc := cfg.DefaultCC(cfg.Goos, cfg.Goarch)
Expand Down
24 changes: 24 additions & 0 deletions src/cmd/internal/objabi/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ var (
GOMIPS = gomips()
GOMIPS64 = gomips64()
GOPPC64 = goppc64()
GOWASM = gowasm()
GO_LDSO = defaultGO_LDSO
Version = version
)
Expand Down Expand Up @@ -76,6 +77,29 @@ func goppc64() int {
panic("unreachable")
}

type gowasmFeatures struct {
// no features yet
}

func (f *gowasmFeatures) String() string {
var flags []string
// no features yet
return strings.Join(flags, ",")
}

func gowasm() (f gowasmFeatures) {
for _, opt := range strings.Split(envOr("GOWASM", ""), ",") {
switch opt {
// no features yet
case "":
// ignore
default:
log.Fatalf("Invalid GOWASM value. No such feature: " + opt)
}
}
return
}

func Getgoextlinkenabled() string {
return envOr("GO_EXTLINK_ENABLED", defaultGO_EXTLINK_ENABLED)
}
Expand Down

0 comments on commit b434bbf

Please sign in to comment.