...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package main
16
17 import (
18 "os"
19 "os/exec"
20 "path/filepath"
21 )
22
23
24
25 func main() {
26
27
28
29 if _, ok := os.LookupEnv("CUE_WASM_BUILD_RUST"); !ok {
30 return
31 }
32
33 cwd, _ := os.Getwd()
34 src := filepath.Join(cwd, "rust")
35 buildRust(src)
36
37 target := filepath.Join(src, "target")
38 bins := filepath.Join(target, "wasm32-unknown-unknown", "release")
39 cue := filepath.Join(cwd, "cue")
40 copyWasm(bins, cue)
41
42 os.RemoveAll(target)
43 }
44
45 func buildRust(srcDir string) {
46 cmd := exec.Command(
47 "cargo", "build", "--release", "--target", "wasm32-unknown-unknown",
48 )
49 cmd.Dir = srcDir
50 cmd.Run()
51 }
52
53 func copyWasm(binDir, wasmDir string) {
54 files, _ := filepath.Glob(filepath.Join(binDir, "*.wasm"))
55 for _, f := range files {
56 os.Rename(f, filepath.Join(wasmDir, filepath.Base(f)))
57 }
58 }
59
View as plain text