github.com/goplus/igop@v0.25.0/pkg/gen_js.go (about) 1 //go:build ignore 2 // +build ignore 3 4 /* 5 * Copyright (c) 2022 The GoPlus Authors (goplus.org). All rights reserved. 6 * 7 * Licensed under the Apache License, Version 2.0 (the "License"); 8 * you may not use this file except in compliance with the License. 9 * You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, software 14 * distributed under the License is distributed on an "AS IS" BASIS, 15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 * See the License for the specific language governing permissions and 17 * limitations under the License. 18 */ 19 20 package main 21 22 import ( 23 "log" 24 "os" 25 "os/exec" 26 "runtime" 27 ) 28 29 func main() { 30 ver := runtime.Version()[:6] 31 var tags string 32 var name string 33 var fname string 34 switch ver { 35 case "go1.20": 36 tags = "//+build go1.20" 37 name = "go120_export" 38 fname = "go120_pkgs.go" 39 case "go1.19": 40 tags = "//+build go1.19,!go1.20" 41 name = "go119_export" 42 fname = "go119_pkgs.go" 43 case "go1.18": 44 tags = "//+build go1.18,!go1.19" 45 name = "go118_export" 46 fname = "go118_pkgs.go" 47 case "go1.17": 48 tags = "//+build go1.17,!go1.18" 49 name = "go117_export" 50 fname = "go117_pkgs.go" 51 case "go1.16": 52 tags = "//+build go1.16,!go1.17" 53 name = "go116_export" 54 fname = "go116_pkgs.go" 55 case "go1.15": 56 tags = "//+build go1.15,!go1.16" 57 name = "go115_export" 58 fname = "go115_pkgs.go" 59 case "go1.14": 60 tags = "//+build go1.14,!go1.15" 61 name = "go114_export" 62 fname = "go114_pkgs.go" 63 } 64 65 log.Println(ver, name, fname, tags) 66 67 // syscall/js 68 cmd := exec.Command("qexp", "-outdir", ".", "-addtags", tags+";//+build js", "-filename", name, "-contexts", "js", "syscall/js") 69 cmd.Stderr = os.Stderr 70 cmd.Stdout = os.Stdout 71 cmd.Env = os.Environ() 72 cmd.Env = append(cmd.Env, "GOOS=js") 73 cmd.Env = append(cmd.Env, "GOARCH=wasm") 74 err := cmd.Run() 75 if err != nil { 76 panic(err) 77 } 78 }