llvmPackages: split from build-llvm.ts
This commit is contained in:
165
build-llvm.ts
165
build-llvm.ts
@@ -1,164 +1,5 @@
|
||||
import path from "path";
|
||||
import { GeneralVariable, LLVMVariable, command, variable } from "./commands/cmake";
|
||||
import { LLVM_SRC, SYSROOT_PREFIX } from "./environment";
|
||||
import { PackageTask, buildPackage } from "./build";
|
||||
import { checkedSpawnSync } from "./cli";
|
||||
import { LLVM_SRC } from "./environment";
|
||||
import { buildLLVMHash } from "./llvmPackages";
|
||||
|
||||
|
||||
function llvmPackages(src: string, installPrefix: string): PackageTask[] {
|
||||
const LLVM_BUILD = path.join(src, "build-dev");
|
||||
const rm = "rm";
|
||||
const cmake = "cmake";
|
||||
|
||||
const llvmVar: LLVMVariable = {
|
||||
LLVM_ENABLE_PROJECTS: ["clang", "clang-tools-extra", "lld", "openmp"],
|
||||
LLVM_TARGETS_TO_BUILD: ["Sw64"],
|
||||
LIBOMP_ARCH: "Sw64",
|
||||
LIBOMP_USE_ITT_NOTIFY: false,
|
||||
};
|
||||
|
||||
const general: GeneralVariable = {
|
||||
CMAKE_BUILD_TYPE: "Release",
|
||||
CMAKE_INSTALL_PREFIX: installPrefix,
|
||||
CMAKE_SYSROOT: SYSROOT_PREFIX,
|
||||
};
|
||||
|
||||
const mkBuildPhase = (build: string) => {
|
||||
checkedSpawnSync(cmake, ["--build", build], { stdio: 'inherit' });
|
||||
};
|
||||
|
||||
const mkInstallPhase = (build: string) => {
|
||||
checkedSpawnSync(cmake, ["--build", build, "--target", "install"], { stdio: 'inherit' });
|
||||
};
|
||||
|
||||
function mkLLVMPackage(): PackageTask {
|
||||
const build = path.join(LLVM_BUILD, "llvm");
|
||||
return {
|
||||
name: "llvm",
|
||||
patchPhase: () => {
|
||||
// Apply llvm omp patch
|
||||
checkedSpawnSync("git",
|
||||
[
|
||||
"apply",
|
||||
path.join(process.cwd(), "assets", "omp.diff"),
|
||||
], { stdio: "inherit", cwd: src });
|
||||
|
||||
process.env.LD_LIBRARY_PATH = [
|
||||
path.join(SYSROOT_PREFIX, 'usr', 'lib'),
|
||||
path.join(SYSROOT_PREFIX, 'lib'),
|
||||
].join(':');
|
||||
},
|
||||
configurePhase: () => {
|
||||
// Configure
|
||||
checkedSpawnSync(cmake, command({
|
||||
definitions: variable({
|
||||
...llvmVar,
|
||||
...general,
|
||||
}),
|
||||
generator: "Ninja",
|
||||
// LLVM cmake root is under /llvm directory
|
||||
pathToSource: path.join(src, "llvm"),
|
||||
pathToBuild: build,
|
||||
}), { stdio: "inherit" });
|
||||
},
|
||||
buildPhase: () => mkBuildPhase(build),
|
||||
installPhase: () => mkInstallPhase(build),
|
||||
};
|
||||
}
|
||||
|
||||
function mkLibpgmathPackage(): PackageTask {
|
||||
const build = path.join(LLVM_BUILD, "libpgmath");
|
||||
return {
|
||||
name: "libpgmath",
|
||||
configurePhase: () => {
|
||||
checkedSpawnSync(rm, ["-rf", build], { stdio: "inherit" });
|
||||
|
||||
// Configure libpgmath.
|
||||
checkedSpawnSync(cmake, command({
|
||||
definitions: variable({
|
||||
...general,
|
||||
...{
|
||||
CMAKE_C_FLAGS: "-msimd",
|
||||
CMAKE_CXX_FLAGS: "-msimd",
|
||||
CMAKE_C_COMPILER: path.join(installPrefix, "bin", "clang"),
|
||||
CMAKE_CXX_COMPILER: path.join(installPrefix, "bin", "clang++"),
|
||||
} as GeneralVariable,
|
||||
}),
|
||||
generator: "Ninja",
|
||||
pathToSource: path.join(src, "cflang", "runtime", "libpgmath"),
|
||||
pathToBuild: build,
|
||||
}), { stdio: "inherit" });
|
||||
},
|
||||
buildPhase: () => mkBuildPhase(build),
|
||||
installPhase: () => mkInstallPhase(build),
|
||||
};
|
||||
}
|
||||
|
||||
function mkCflangPackage(): PackageTask {
|
||||
const build = path.join(LLVM_BUILD, "cflang");
|
||||
return {
|
||||
name: "cflang",
|
||||
configurePhase: () => {
|
||||
checkedSpawnSync(rm, ["-rf", build], { stdio: "inherit" });
|
||||
|
||||
// Configure cflang.
|
||||
checkedSpawnSync(cmake, command({
|
||||
definitions: variable({
|
||||
...llvmVar,
|
||||
...general,
|
||||
...{
|
||||
CMAKE_C_COMPILER: path.join(installPrefix, "bin", "clang"),
|
||||
CMAKE_CXX_COMPILER: path.join(installPrefix, "bin", "clang++"),
|
||||
CMAKE_Fortran_COMPILER: path.join(installPrefix, "bin", "flang"),
|
||||
CMAKE_Fortran_COMPILER_ID: "Flang",
|
||||
} as GeneralVariable,
|
||||
// Flang specific variables.
|
||||
FLANG_INCLUDE_DOCS: true,
|
||||
FLANG_LLVM_EXTENSIONS: true,
|
||||
WITH_WERROR: false,
|
||||
LLVM_CONFIG: path.join(installPrefix, "bin", "llvm-config"),
|
||||
}),
|
||||
generator: "Unix Makefiles",
|
||||
pathToSource: path.join(src, "cflang"),
|
||||
pathToBuild: build,
|
||||
}), { stdio: "inherit" });
|
||||
},
|
||||
buildPhase: () => mkBuildPhase(build),
|
||||
installPhase: () => mkInstallPhase(build),
|
||||
};
|
||||
}
|
||||
|
||||
return [mkLLVMPackage(), mkLibpgmathPackage(), mkCflangPackage()];
|
||||
}
|
||||
|
||||
|
||||
function buildLLVMHash(src: string, rev: string) {
|
||||
// Checkout a git rev in some git repo.
|
||||
checkedSpawnSync("git", ["checkout", rev], { stdio: "inherit", cwd: src });
|
||||
checkedSpawnSync("git", ["reset", "--hard", "HEAD"], { stdio: "inherit", cwd: src });
|
||||
|
||||
const llvmInstall = path.join(src, "local", "installed");
|
||||
|
||||
llvmPackages(src, path.join(llvmInstall, rev))
|
||||
.forEach(buildPackage);
|
||||
}
|
||||
|
||||
[
|
||||
// "85e4fed0c9e4cd4ab8bce89f307127ccbad31294",
|
||||
"09eed7875e9a5fa8597a3ba88bd5c5bcc18fff9b",
|
||||
"1231573a5c29fc1ea5783b0f8cdd7442d48111b5",
|
||||
"0fef7853ab023a4752c84f889f98461bd7f37728",
|
||||
"cc2144e0cb4e09ca4c4e77ddb124148d3a50ed30",
|
||||
"49025c97a834df250cec6b6c9d292951284308d6",
|
||||
"5a48db93c5ae983513da54929f0600441c2584e7",
|
||||
"76318811282fdfc65435628026636a748b015cb8",
|
||||
"20713c101717338706b502d25a9c57e73b4d1dc9",
|
||||
"33661f021f637512c3a986f1cf8f5828dd974114",
|
||||
"793edc371ded601900fac19144cbddfd9a881b00",
|
||||
"a44d0af59e3a8bac5e2f6c0d02b95ae1853928f2",
|
||||
"9dbcdda68d41590485da61fe9fc09e92da9cadad",
|
||||
"77bfe439d08adccf7a07b3393d8dc0281b7e4792",
|
||||
"a5449bdd6d7df432a5cced42cd137d54eb027e03",
|
||||
"adf1aaa1e498957a367c3052bb1195cef92a01c0",
|
||||
"4a844972f38e2b44519b894ccfe54b6c92051cb7",
|
||||
].forEach(hash => buildLLVMHash(LLVM_SRC, hash));
|
||||
buildLLVMHash(LLVM_SRC, "639a757627d1b28fa03b9438083bc3a163b8bbe8");
|
||||
|
||||
Reference in New Issue
Block a user