From a1450b36df5c3744a0216529bcff2ba00c427500 Mon Sep 17 00:00:00 2001 From: Yingchi Long Date: Wed, 19 Jun 2024 17:21:40 +0800 Subject: [PATCH] build: move all build stuff under this directory --- build-llvm.ts | 4 +-- build.ts => build/build.ts | 0 llvmPackages.ts => build/llvmPackages.ts | 46 +++++++++++++++--------- tsconfig.json | 2 +- 4 files changed, 32 insertions(+), 20 deletions(-) rename build.ts => build/build.ts (100%) rename llvmPackages.ts => build/llvmPackages.ts (82%) diff --git a/build-llvm.ts b/build-llvm.ts index 30f4b40..3f2ae29 100644 --- a/build-llvm.ts +++ b/build-llvm.ts @@ -1,5 +1,5 @@ import { LLVM_SRC } from "./environment"; -import { buildLLVMHash } from "./llvmPackages"; +import { buildLLVMHash } from "./build/llvmPackages"; -buildLLVMHash(LLVM_SRC, "639a757627d1b28fa03b9438083bc3a163b8bbe8"); +buildLLVMHash(LLVM_SRC, "31c8e21f40ea654f9d49b3a926acc6ef1f2ca5d5"); diff --git a/build.ts b/build/build.ts similarity index 100% rename from build.ts rename to build/build.ts diff --git a/llvmPackages.ts b/build/llvmPackages.ts similarity index 82% rename from llvmPackages.ts rename to build/llvmPackages.ts index 70e21ca..9fbc276 100644 --- a/llvmPackages.ts +++ b/build/llvmPackages.ts @@ -1,8 +1,10 @@ import path from "path"; -import { GeneralVariable, LLVMVariable, command, variable } from "./commands/cmake"; -import { SYSROOT_PREFIX } from "./environment"; +import { GeneralVariable, LLVMVariable, command, variable } from "commands/cmake"; +import { SYSROOT_PREFIX } from "environment"; import { PackageTask, buildPackage } from "./build"; -import { checkedSpawnSync } from "./cli"; +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"); @@ -22,12 +24,27 @@ export function llvmPackages(src: string, installPrefix: string): PackageTask[] 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], { stdio: 'inherit' }); + checkedSpawnSync(cmake, ["--build", build], spawnOptions); }; const mkInstallPhase = (build: string) => { - checkedSpawnSync(cmake, ["--build", build, "--target", "install"], { stdio: 'inherit' }); + checkedSpawnSync(cmake, ["--build", build, "--target", "install"], spawnOptions); }; function mkLLVMPackage(): PackageTask { @@ -39,13 +56,8 @@ export function llvmPackages(src: string, installPrefix: string): PackageTask[] checkedSpawnSync("git", [ "apply", - path.resolve(__dirname, "..", "assets", "omp.diff"), - ], { stdio: "inherit", cwd: src }); - - process.env.LD_LIBRARY_PATH = [ - path.join(SYSROOT_PREFIX, 'usr', 'lib'), - path.join(SYSROOT_PREFIX, 'lib'), - ].join(':'); + path.resolve(__dirname, "..", "..", "assets", "omp.diff"), + ], spawnOptions); }, configurePhase: () => { // Configure @@ -58,7 +70,7 @@ export function llvmPackages(src: string, installPrefix: string): PackageTask[] // LLVM cmake root is under /llvm directory pathToSource: path.join(src, "llvm"), pathToBuild: build, - }), { stdio: "inherit" }); + }), spawnOptions); }, buildPhase: () => mkBuildPhase(build), installPhase: () => mkInstallPhase(build), @@ -70,7 +82,7 @@ export function llvmPackages(src: string, installPrefix: string): PackageTask[] return { name: "libpgmath", configurePhase: () => { - checkedSpawnSync(rm, ["-rf", build], { stdio: "inherit" }); + checkedSpawnSync(rm, ["-rf", build], spawnOptions); // Configure libpgmath. checkedSpawnSync(cmake, command({ @@ -86,7 +98,7 @@ export function llvmPackages(src: string, installPrefix: string): PackageTask[] generator: "Ninja", pathToSource: path.join(src, "cflang", "runtime", "libpgmath"), pathToBuild: build, - }), { stdio: "inherit" }); + }), spawnOptions); }, buildPhase: () => mkBuildPhase(build), installPhase: () => mkInstallPhase(build), @@ -98,7 +110,7 @@ export function llvmPackages(src: string, installPrefix: string): PackageTask[] return { name: "cflang", configurePhase: () => { - checkedSpawnSync(rm, ["-rf", build], { stdio: "inherit" }); + checkedSpawnSync(rm, ["-rf", build], spawnOptions); // Configure cflang. checkedSpawnSync(cmake, command({ @@ -120,7 +132,7 @@ export function llvmPackages(src: string, installPrefix: string): PackageTask[] generator: "Unix Makefiles", pathToSource: path.join(src, "cflang"), pathToBuild: build, - }), { stdio: "inherit" }); + }), spawnOptions); }, buildPhase: () => mkBuildPhase(build), installPhase: () => mkInstallPhase(build), diff --git a/tsconfig.json b/tsconfig.json index c45cb1b..5281be6 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -25,7 +25,7 @@ "module": "commonjs", /* Specify what module code is generated. */ // "rootDir": "./", /* Specify the root folder within your source files. */ // "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */ - // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ + "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */ // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */