-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.go
157 lines (131 loc) · 3.32 KB
/
build.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
package main
import (
"log"
"os"
"os/exec"
"path/filepath"
"runtime"
"github.com/termie/go-shutil"
)
func ensure(err error) {
if err != nil {
log.Fatalln(err)
}
}
func main() {
SHADER := os.Args[1]
CLANGPP := "clang++"
cpfiles, _ := filepath.Glob("runtime/*")
for _, f := range cpfiles {
fi, _ := os.Stat(f)
ft := f[len("runtime/"):]
if fi.IsDir() {
ensure(shutil.CopyTree(f, filepath.Join("build", filepath.Base(ft)), nil))
} else {
_, e := shutil.Copy(f, filepath.Join("build", ft), false)
ensure(e)
}
}
ensure(os.MkdirAll("build/generated", 0777))
// first use lcpp to concatenate all into one file by processing the
// includes such that we have single file we can build.
ts := filepath.Base(SHADER)
path := filepath.Dir(SHADER)
ts = filepath.Join("build", ts+".inc.comp")
println("run lua")
ensure(run("lua", "script/lcpp.lua", SHADER, "-I"+path, "-o", ts))
SHADER = ts
println("lua run")
ensure(run("glslangValidator", SHADER))
println("a")
ensure(runf("gl2c", "cargo", "run", "-q", "--", "../"+SHADER, "../build/kernel.json"))
println("b")
files, _ := filepath.Glob("glbind/*.go")
ensure(run("go", append([]string{"run"}, files...)...))
println("c")
ensure(run("goimports", "-w", "build/kernel.go"))
println("d")
ensure(run("goimports", "-w", "build/types.go"))
println("e")
// TODO: here we want to build for multiple platforms...
cargs := []string{
"-std=c++2a",
//"-fvisibility=hidden",
"-Wall",
"-Wextra",
"-Werror",
"-Wno-unused-function",
"-Wuninitialized",
"-pedantic-errors",
"-Wmost",
"-Wno-extra-semi",
"-Ofast",
"-ffast-math",
"-fno-math-errno",
}
asm := ""
outf := ""
if runtime.GOOS == "windows" {
asm = "co/arch/amd64_win.S"
outf = "shader.dll"
} else {
asm = "co/arch/amd64_nix.S"
outf = "./shader.so"
cargs = append(cargs, "-fPIC")
}
println("run c")
ensure(runf("build", CLANGPP, append([]string{"lib.cpp", asm, "-shared", "-o", outf}, cargs...)...))
ensure(os.MkdirAll("build/go/build", 0777))
if ex("build/test_test.go") {
cp("build/test_test.go", "build/go/test_test.go")
}
if ex("build/util_test.go") {
cp("build/util_test.go", "build/go/util_test.go")
}
cp("build/kernel.go", "build/go/kernel.go")
cp("build/types.go", "build/go/types.go")
if runtime.GOOS == "windows" {
cp("build/shader.dll", "build/go/shader.dll")
} else {
cp("build/shader.so", "build/go/shader.so")
cp("build/shader.so", "build/go/build/shader.so")
}
cp("build/generated/shared.h", "build/go/shared.h")
files, _ = filepath.Glob("build/go/*.go")
for i := range files {
files[i] = filepath.Base(files[i])
}
ensure(runf("build/go", "go", append([]string{"test", "-v"}, files...)...))
}
func run(m string, args ...string) error {
return runf("", m, args...)
}
func runf(path, m string, args ...string) error {
c := exec.Command(m, args...)
c.Dir = path
c.Stderr = os.Stderr
c.Stdout = os.Stdout
return c.Run()
}
func ex(path string) bool {
_, err := os.Stat(path)
if err == nil {
return true
}
if os.IsNotExist(err) {
return false
}
ensure(err)
panic("cannot be reached")
}
func cp(from, to string) {
_, e := shutil.Copy(from, to, false)
ensure(e)
}
/*
cp build/shader.so build/go/build
cp build/shader.so build/go
cp build/generated/shared.h build/go/
# build the go pacae and run it to test it wors
(cd build/go && go test -v . )
*/