this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

cmd/cue: disable the wasm interpreter by default for now

We aren't shipping wasm support right now, so bundling the interpreter
pulls in wazero and makes cue binaries significantly larger
while bringing in no real value to users yet.

For now, disable it in cmd/cue unless the build tag cuewasm is used,
which brings down the size of a "go build" binary
from 26.2MiB to 23.8 MiB on linux/amd64.

We use a build tag rather than disabling the code in cmd/cue/cmd
because otherwise we would completely break the wasm.TestExe tests,
which use cmd/cue as a form of integration test.
A build tag also allows us to opt into the feature as needed.

The tests in cue/interpreter/wasm are updated accordingly,
as TestExe now requires the build tag to be set as well.
We also teach CI to test with the new build tag as well.

There is no particular reason I chose "cuewasm" as the build tag here.
We can't go for "wasm", as that conflicts with GOARCH=wasm.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
Change-Id: I3f5ef18d5c0b58c687d43bd691a688779c1ab33d
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1190172
Reviewed-by: Aram Hăvărneanu <aram@cue.works>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>

+101 -34
+2
.github/workflows/trybot.yml
··· 166 166 run: go test -race ./... 167 167 env: 168 168 GORACE: atexit_sleep_ms=10 169 + - name: Test with -tags=cuewasm 170 + run: go test -tags cuewasm ./cmd/cue/cmd ./cue/interpreter/wasm 169 171 - name: gcloud auth for end-to-end tests 170 172 id: auth 171 173 if: |-
+3 -2
cmd/cue/cmd/root.go
··· 26 26 "cuelang.org/go/cue" 27 27 "cuelang.org/go/cue/cuecontext" 28 28 "cuelang.org/go/cue/errors" 29 - "cuelang.org/go/cue/interpreter/wasm" 30 29 "cuelang.org/go/cue/stats" 31 30 "cuelang.org/go/internal/core/adt" 32 31 "cuelang.org/go/internal/cuedebug" ··· 176 175 c := &Command{ 177 176 Command: cmd, 178 177 root: cmd, 179 - ctx: cuecontext.New(cuecontext.Interpreter(wasm.New())), 178 + ctx: cuecontext.New(rootContextOptions...), 180 179 } 181 180 182 181 cmdCmd := newCmdCmd(c) ··· 225 224 cmd.SetArgs(args) 226 225 return c, nil 227 226 } 227 + 228 + var rootContextOptions []cuecontext.Option 228 229 229 230 // MainTest is like Main, runs the cue tool and returns the code for passing to os.Exit. 230 231 func MainTest() int {
+28
cmd/cue/cmd/root_cuewasm.go
··· 1 + // Copyright 2024 The CUE Authors 2 + // 3 + // Licensed under the Apache License, Version 2.0 (the "License"); 4 + // you may not use this file except in compliance with the License. 5 + // You may obtain a copy of the License at 6 + // 7 + // http://www.apache.org/licenses/LICENSE-2.0 8 + // 9 + // Unless required by applicable law or agreed to in writing, software 10 + // distributed under the License is distributed on an "AS IS" BASIS, 11 + // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 + // See the License for the specific language governing permissions and 13 + // limitations under the License. 14 + 15 + //go:build cuewasm 16 + 17 + package cmd 18 + 19 + import ( 20 + "cuelang.org/go/cue/cuecontext" 21 + "cuelang.org/go/cue/interpreter/wasm" 22 + ) 23 + 24 + // The wasm interpreter can be enabled by default once we are ready to ship the feature. 25 + // For now, it's not ready, and makes cue binaries heavier by over 2MiB. 26 + func init() { 27 + rootContextOptions = append(rootContextOptions, cuecontext.Interpreter(wasm.New())) 28 + }
+60
cue/interpreter/wasm/exe_test.go
··· 1 + // Copyright 2023 CUE Authors 2 + // 3 + // Licensed under the Apache License, Version 2.0 (the "License"); 4 + // you may not use this file except in compliance with the License. 5 + // You may obtain a copy of the License at 6 + // 7 + // http://www.apache.org/licenses/LICENSE-2.0 8 + // 9 + // Unless required by applicable law or agreed to in writing, software 10 + // distributed under the License is distributed on an "AS IS" BASIS, 11 + // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 + // See the License for the specific language governing permissions and 13 + // limitations under the License. 14 + 15 + // TestExe expects cmd/cue to be configured with wasm support, 16 + // which it only is with the cuewasm build tag enabled. 17 + 18 + //go:build cuewasm 19 + 20 + package wasm_test 21 + 22 + import ( 23 + "os" 24 + "path/filepath" 25 + "testing" 26 + 27 + "cuelang.org/go/cmd/cue/cmd" 28 + "cuelang.org/go/internal/cuetest" 29 + 30 + "github.com/rogpeppe/go-internal/gotooltest" 31 + "github.com/rogpeppe/go-internal/testscript" 32 + ) 33 + 34 + // We are using TestMain because we want to ensure Wasm is enabled and 35 + // works as expected with the command-line tool. 36 + func TestMain(m *testing.M) { 37 + os.Exit(testscript.RunMain(m, map[string]func() int{ 38 + "cue": cmd.MainTest, 39 + })) 40 + } 41 + 42 + // TestExe tests Wasm using the command-line tool. 43 + func TestExe(t *testing.T) { 44 + root := must(filepath.Abs("testdata"))(t) 45 + wasmFiles := filepath.Join(root, "cue") 46 + p := testscript.Params{ 47 + Dir: "testdata/cue", 48 + UpdateScripts: cuetest.UpdateGoldenFiles, 49 + RequireExplicitExec: true, 50 + Setup: func(e *testscript.Env) error { 51 + copyWasmFiles(t, e.WorkDir, wasmFiles) 52 + return nil 53 + }, 54 + Condition: cuetest.Condition, 55 + } 56 + if err := gotooltest.Setup(&p); err != nil { 57 + t.Fatal(err) 58 + } 59 + testscript.Run(t, p) 60 + }
-32
cue/interpreter/wasm/wasm_test.go
··· 23 23 "strings" 24 24 "testing" 25 25 26 - "cuelang.org/go/cmd/cue/cmd" 27 26 "cuelang.org/go/cue" 28 27 "cuelang.org/go/cue/ast" 29 28 "cuelang.org/go/cue/ast/astutil" ··· 35 34 "cuelang.org/go/cue/parser" 36 35 "cuelang.org/go/internal/cuetest" 37 36 "cuelang.org/go/internal/cuetxtar" 38 - 39 - "github.com/rogpeppe/go-internal/gotooltest" 40 - "github.com/rogpeppe/go-internal/testscript" 41 37 ) 42 - 43 - // We are using TestMain because we want to ensure Wasm is enabled and 44 - // works as expected with the command-line tool. 45 - func TestMain(m *testing.M) { 46 - os.Exit(testscript.RunMain(m, map[string]func() int{ 47 - "cue": cmd.MainTest, 48 - })) 49 - } 50 - 51 - // TestExe tests Wasm using the command-line tool. 52 - func TestExe(t *testing.T) { 53 - root := must(filepath.Abs("testdata"))(t) 54 - wasmFiles := filepath.Join(root, "cue") 55 - p := testscript.Params{ 56 - Dir: "testdata/cue", 57 - UpdateScripts: cuetest.UpdateGoldenFiles, 58 - RequireExplicitExec: true, 59 - Setup: func(e *testscript.Env) error { 60 - copyWasmFiles(t, e.WorkDir, wasmFiles) 61 - return nil 62 - }, 63 - Condition: cuetest.Condition, 64 - } 65 - if err := gotooltest.Setup(&p); err != nil { 66 - t.Fatal(err) 67 - } 68 - testscript.Run(t, p) 69 - } 70 38 71 39 // TestWasm tests Wasm using the API. 72 40 func TestWasm(t *testing.T) {
+8
internal/ci/github/trybot.cue
··· 75 75 _goTestRace & { 76 76 if: _isLatestLinux 77 77 }, 78 + _goTestWasm, 78 79 for v in _e2eTestSteps {v}, 79 80 _goCheck, 80 81 _repo.checkGitClean, ··· 174 175 name: "Test with -race" 175 176 env: GORACE: "atexit_sleep_ms=10" // Otherwise every Go package being tested sleeps for 1s; see https://go.dev/issues/20364. 176 177 run: "go test -race ./..." 178 + } 179 + 180 + _goTestWasm: json.#step & { 181 + name: "Test with -tags=cuewasm" 182 + // The wasm interpreter is only bundled into cmd/cue with the cuewasm build tag. 183 + // Test the related packages with the build tag enabled as well. 184 + run: "go test -tags cuewasm ./cmd/cue/cmd ./cue/interpreter/wasm" 177 185 } 178 186 }