aboutsummaryrefslogtreecommitdiffhomepage
path: root/compileopts
diff options
context:
space:
mode:
authorAyke <[email protected]>2024-10-05 00:33:47 +0200
committerGitHub <[email protected]>2024-10-04 15:33:47 -0700
commit9da8b5c786880e47f6f96b82be7c410af6f9011b (patch)
tree47bf837bbda8f5e174447b165f8bb4ad8d7f523e /compileopts
parent407889864f1749fee46312fa191bf53ff59137ce (diff)
downloadtinygo-9da8b5c786880e47f6f96b82be7c410af6f9011b.tar.gz
tinygo-9da8b5c786880e47f6f96b82be7c410af6f9011b.zip
wasm: add `//go:wasmexport` support (#4451)
This adds support for the `//go:wasmexport` pragma as proposed here: https://github.com/golang/go/issues/65199 It is currently implemented only for wasip1 and wasm-unknown, but it is certainly possible to extend it to other targets like GOOS=js and wasip2.
Diffstat (limited to 'compileopts')
-rw-r--r--compileopts/config.go11
-rw-r--r--compileopts/options.go10
-rw-r--r--compileopts/target.go1
3 files changed, 22 insertions, 0 deletions
diff --git a/compileopts/config.go b/compileopts/config.go
index cc1f4d61c..44d3b005c 100644
--- a/compileopts/config.go
+++ b/compileopts/config.go
@@ -33,6 +33,17 @@ func (c *Config) CPU() string {
return c.Target.CPU
}
+// The current build mode (like the `-buildmode` command line flag).
+func (c *Config) BuildMode() string {
+ if c.Options.BuildMode != "" {
+ return c.Options.BuildMode
+ }
+ if c.Target.BuildMode != "" {
+ return c.Target.BuildMode
+ }
+ return "default"
+}
+
// Features returns a list of features this CPU supports. For example, for a
// RISC-V processor, that could be "+a,+c,+m". For many targets, an empty list
// will be returned.
diff --git a/compileopts/options.go b/compileopts/options.go
index 980097200..b83f6f63b 100644
--- a/compileopts/options.go
+++ b/compileopts/options.go
@@ -8,6 +8,7 @@ import (
)
var (
+ validBuildModeOptions = []string{"default", "c-shared"}
validGCOptions = []string{"none", "leaking", "conservative", "custom", "precise"}
validSchedulerOptions = []string{"none", "tasks", "asyncify"}
validSerialOptions = []string{"none", "uart", "usb", "rtt"}
@@ -26,6 +27,7 @@ type Options struct {
GOMIPS string // environment variable (only used with GOARCH=mips and GOARCH=mipsle)
Directory string // working dir, leave it unset to use the current working dir
Target string
+ BuildMode string // -buildmode flag
Opt string
GC string
PanicStrategy string
@@ -61,6 +63,14 @@ type Options struct {
// Verify performs a validation on the given options, raising an error if options are not valid.
func (o *Options) Verify() error {
+ if o.BuildMode != "" {
+ valid := isInArray(validBuildModeOptions, o.BuildMode)
+ if !valid {
+ return fmt.Errorf(`invalid buildmode option '%s': valid values are %s`,
+ o.BuildMode,
+ strings.Join(validBuildModeOptions, ", "))
+ }
+ }
if o.GC != "" {
valid := isInArray(validGCOptions, o.GC)
if !valid {
diff --git a/compileopts/target.go b/compileopts/target.go
index 41a7babd9..ab9f871f3 100644
--- a/compileopts/target.go
+++ b/compileopts/target.go
@@ -32,6 +32,7 @@ type TargetSpec struct {
GOARCH string `json:"goarch,omitempty"`
SoftFloat bool // used for non-baremetal systems (GOMIPS=softfloat etc)
BuildTags []string `json:"build-tags,omitempty"`
+ BuildMode string `json:"buildmode,omitempty"` // default build mode (if nothing specified)
GC string `json:"gc,omitempty"`
Scheduler string `json:"scheduler,omitempty"`
Serial string `json:"serial,omitempty"` // which serial output to use (uart, usb, none)