build: move all build stuff under this directory
This commit is contained in:
154
build/llvmPackages.ts
Normal file
154
build/llvmPackages.ts
Normal file
@@ -0,0 +1,154 @@
|
||||
import path from "path";
|
||||
import { GeneralVariable, LLVMVariable, command, variable } from "commands/cmake";
|
||||
import { SYSROOT_PREFIX } from "environment";
|
||||
import { PackageTask, buildPackage } from "./build";
|
||||
import { checkedSpawnSync } from "cli";
|
||||
import os from "os";
|
||||
import { SpawnOptions, spawn } from "child_process";
|
||||
|
||||
export 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 env = {
|
||||
...process.env,
|
||||
MAKEFLAGS: ["-j", os.cpus().length].join(" "),
|
||||
LD_LIBRARY_PATH: [
|
||||
path.join(SYSROOT_PREFIX, 'usr', 'lib'),
|
||||
path.join(SYSROOT_PREFIX, 'lib'),
|
||||
].join(':'),
|
||||
};
|
||||
|
||||
const spawnOptions: SpawnOptions = {
|
||||
stdio: "inherit",
|
||||
env,
|
||||
cwd: src,
|
||||
};
|
||||
|
||||
const mkBuildPhase = (build: string) => {
|
||||
checkedSpawnSync(cmake, ["--build", build], spawnOptions);
|
||||
};
|
||||
|
||||
const mkInstallPhase = (build: string) => {
|
||||
checkedSpawnSync(cmake, ["--build", build, "--target", "install"], spawnOptions);
|
||||
};
|
||||
|
||||
function mkLLVMPackage(): PackageTask {
|
||||
const build = path.join(LLVM_BUILD, "llvm");
|
||||
return {
|
||||
name: "llvm",
|
||||
patchPhase: () => {
|
||||
// Apply llvm omp patch
|
||||
checkedSpawnSync("git",
|
||||
[
|
||||
"apply",
|
||||
path.resolve(__dirname, "..", "..", "assets", "omp.diff"),
|
||||
], spawnOptions);
|
||||
},
|
||||
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,
|
||||
}), spawnOptions);
|
||||
},
|
||||
buildPhase: () => mkBuildPhase(build),
|
||||
installPhase: () => mkInstallPhase(build),
|
||||
};
|
||||
}
|
||||
|
||||
function mkLibpgmathPackage(): PackageTask {
|
||||
const build = path.join(LLVM_BUILD, "libpgmath");
|
||||
return {
|
||||
name: "libpgmath",
|
||||
configurePhase: () => {
|
||||
checkedSpawnSync(rm, ["-rf", build], spawnOptions);
|
||||
|
||||
// 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,
|
||||
}), spawnOptions);
|
||||
},
|
||||
buildPhase: () => mkBuildPhase(build),
|
||||
installPhase: () => mkInstallPhase(build),
|
||||
};
|
||||
}
|
||||
|
||||
function mkCflangPackage(): PackageTask {
|
||||
const build = path.join(LLVM_BUILD, "cflang");
|
||||
return {
|
||||
name: "cflang",
|
||||
configurePhase: () => {
|
||||
checkedSpawnSync(rm, ["-rf", build], spawnOptions);
|
||||
|
||||
// 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,
|
||||
}), spawnOptions);
|
||||
},
|
||||
buildPhase: () => mkBuildPhase(build),
|
||||
installPhase: () => mkInstallPhase(build),
|
||||
};
|
||||
}
|
||||
|
||||
return [mkLLVMPackage(), mkLibpgmathPackage(), mkCflangPackage()];
|
||||
|
||||
|
||||
} export 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);
|
||||
}
|
||||
Reference in New Issue
Block a user