-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmulti-platform.ts
44 lines (38 loc) · 1.32 KB
/
multi-platform.ts
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
import { cacheMount, createFile, PlatformJson, State } from 'dacc'
const goMain = `package main
import (
"fmt"
"runtime"
)
func main() {
fmt.Printf("%s/%s\\n", runtime.GOOS, runtime.GOARCH)
}
`
async function forPlatform(platform: PlatformJson) {
const root = await (new State().from("golang:1.23-alpine", platform))
root.do(createFile("/main.go", goMain))
root.run("go build -o /main /main.go").with(cacheMount("/go/pkg"))
const { stdout } = await root.image.run({
build: { quiet: true },
run: { command: "go", args: ["run", "/main.go"], quiet: true },
})
return { platform, stdout }
}
async function main() {
const platforms: PlatformJson[] = [
{ OS: "linux", Architecture: "amd64" },
{ OS: "linux", Architecture: "arm64" },
{ OS: "linux", Architecture: "arm", Variant: "v6" },
{ OS: "linux", Architecture: "arm", Variant: "v7" },
{ OS: "linux", Architecture: "386" },
{ OS: "linux", Architecture: "ppc64le" },
{ OS: "linux", Architecture: "s390x" },
{ OS: "linux", Architecture: "riscv64" },
]
const results = await Promise.all(platforms.map(forPlatform))
console.log(results.map((r) => JSON.stringify(r)).join("\n"))
}
if (require.main === module) {
(async () => await void main())()
}
export { main as merge }