build/llvmPackages: abstract buildLLVMPackagesUUID

This commit is contained in:
2025-07-21 16:35:49 +08:00
parent 7a25ce9f4e
commit 8e489591d8
2 changed files with 53 additions and 39 deletions

View File

@@ -1,12 +1,6 @@
import yargs from 'yargs';
import { hideBin } from 'yargs/helpers';
import { llvmPackages } from '../build/llvmPackages.js';
import path from 'path';
import { buildPackage } from '../build/build.js';
import { randomUUID } from 'crypto';
import { arch } from 'os';
import * as sunway from '../sunway.js';
import chalk from 'chalk';
import { buildLLVMPackagesUUID, BuildOptions } from '../build/llvmPackages.js';
const argv = await yargs(hideBin(process.argv))
.version("0.0.0")
@@ -37,30 +31,4 @@ const argv = await yargs(hideBin(process.argv))
.help()
.parse();
const src = path.resolve(argv.src);
const build = argv.build ?? path.resolve(src, "build");
const prefix = argv.prefix ?? path.resolve(src, "install", randomUUID());
const cpuVariant = argv.mcpu === "host" ? sunway.getHostGeneration() : argv.platform as sunway.SunwayGeneration;
console.log(`prefix: ${chalk.red(prefix)}`);
console.log(`mcpu: ${cpuVariant}`);
const packages = llvmPackages({
src: argv.src,
buildDir(packageName) {
return path.join(build, packageName);
},
installPrefix: prefix,
// FIXME: arguments to platform?
platform: {
buildPlatform: { arch: arch() },
hostPlatform: { arch: arch() },
},
mathSIMD: argv['math-simd'],
cpuVariant,
});
for (const pkg of packages) {
await buildPackage(pkg);
}
buildLLVMPackagesUUID(argv as BuildOptions);

View File

@@ -1,10 +1,13 @@
import path from "path";
import { GeneralVariable, LLVMVariable, buildCompilerFlags, command, variable } from "../commands/cmake.js";
import { PackagePlatform, PackageTask } from "./build.js";
import { promisifySpawn } from "../cli.js";
import os from "os";
import chalk from 'chalk';
import { SpawnOptions, spawn } from "child_process";
import { randomUUID } from 'crypto';
import os, { arch } from "os";
import path from "path";
import { buildPackage } from '../build/build.js';
import { promisifySpawn } from "../cli.js";
import { GeneralVariable, LLVMVariable, buildCompilerFlags, command, variable } from "../commands/cmake.js";
import * as sunway from '../sunway.js';
import { PackagePlatform, PackageTask } from "./build.js";
export interface LLVMPackageOverrides {
cmakeDefinitionOverrides?: {
@@ -226,3 +229,46 @@ export function llvmPackages({
return [mkLLVMPackage(), mkLibpgmathPackage(), mkCflangPackage()];
}
export interface BuildOptions {
src: string;
build?: string;
prefix?: string;
'math-simd': boolean;
mcpu: '8a' | '6b' | 'host';
}
/// 构建带 UUID 的 LLVM 包
export async function buildLLVMPackagesUUID(options: BuildOptions): Promise<string> {
const { src, build, prefix, 'math-simd': mathSIMD, mcpu } = options;
const resolvedSrc = path.resolve(src);
const resolvedBuild = build ?? path.resolve(resolvedSrc, "build");
const resolvedPrefix = prefix ?? path.resolve(resolvedSrc, "install", randomUUID());
const cpuVariant = mcpu === "host"
? sunway.getHostGeneration()
: mcpu as sunway.SunwayGeneration;
const packages = llvmPackages({
src: resolvedSrc,
buildDir(packageName: string) {
return path.join(resolvedBuild, packageName);
},
installPrefix: resolvedPrefix,
platform: {
buildPlatform: { arch: arch() },
hostPlatform: { arch: arch() },
},
mathSIMD,
cpuVariant,
});
for (const pkg of packages) {
await buildPackage(pkg);
}
return resolvedPrefix;
}