|
| 1 | +import * as std from "std" with { local: "./std" }; |
| 2 | +import { $ } from "std" with { local: "./std" }; |
| 3 | +import ninja from "ninja" with { local: "./ninja.tg.ts" }; |
| 4 | +import python from "python" with { local: "./python" }; |
| 5 | + |
| 6 | +export const metadata = { |
| 7 | + homepage: "https://gn.googlesource.com/gn", |
| 8 | + license: "BSD-3-Clause", |
| 9 | + name: "gn", |
| 10 | + repository: "https://gn.googlesource.com/gn", |
| 11 | + version: "0.2216", |
| 12 | + tag: "gn/0.2216", |
| 13 | + provides: { |
| 14 | + binaries: ["gn"], |
| 15 | + }, |
| 16 | +}; |
| 17 | + |
| 18 | +// Pinned commit compatible with V8 146. |
| 19 | +const commit = "20a26907f754fed7927e5c5fd103a23a3a528cdf"; |
| 20 | + |
| 21 | +export const source = async () => { |
| 22 | + const checksum = "sha256:any"; |
| 23 | + const url = `https://gn.googlesource.com/gn/+archive/${commit}.tar.gz`; |
| 24 | + // googlesource archives are flat (no top-level directory). |
| 25 | + return await std |
| 26 | + .download({ checksum, url, mode: "extract" }) |
| 27 | + .then(tg.Directory.expect); |
| 28 | +}; |
| 29 | + |
| 30 | +export type Arg = { |
| 31 | + build?: string; |
| 32 | + env?: std.env.Arg; |
| 33 | + host?: string; |
| 34 | + sdk?: std.sdk.Arg; |
| 35 | +}; |
| 36 | + |
| 37 | +export const build = async (...args: std.Args<Arg>) => { |
| 38 | + const { |
| 39 | + build: build_, |
| 40 | + env: env_, |
| 41 | + host: host_, |
| 42 | + sdk, |
| 43 | + } = await std.args.apply<Arg, Arg>({ |
| 44 | + args, |
| 45 | + map: async (arg) => arg, |
| 46 | + reduce: { |
| 47 | + env: (a, b) => std.env.arg(a, b), |
| 48 | + sdk: (a, b) => std.sdk.arg(a, b), |
| 49 | + }, |
| 50 | + }); |
| 51 | + const host = host_ ?? std.triple.host(); |
| 52 | + const build = build_ ?? host; |
| 53 | + const sourceDir = await source(); |
| 54 | + |
| 55 | + const env = std.env.arg( |
| 56 | + std.sdk({ host: build, target: host, toolchain: "llvm", ...sdk }), |
| 57 | + ninja({ build, host: build }), |
| 58 | + python({ build, host: build }), |
| 59 | + env_, |
| 60 | + ); |
| 61 | + |
| 62 | + return await $` |
| 63 | + cp -R ${sourceDir}/. work |
| 64 | + chmod -R u+w work |
| 65 | + cd work |
| 66 | + python3 build/gen.py --no-last-commit-position |
| 67 | + ninja -C out gn |
| 68 | + mkdir -p $OUTPUT/bin |
| 69 | + cp out/gn $OUTPUT/bin/gn |
| 70 | + ` |
| 71 | + .checksum("sha256:any") |
| 72 | + .env(env) |
| 73 | + .then(tg.Directory.expect); |
| 74 | +}; |
| 75 | + |
| 76 | +export default build; |
| 77 | + |
| 78 | +export const test = async () => { |
| 79 | + const spec = std.assert.defaultSpec(metadata); |
| 80 | + return await std.assert.pkg(build, spec); |
| 81 | +}; |
0 commit comments