Skip to content

Commit 6b14a86

Browse files
committed
Compile with MLIR for Emscripten builds in CI
1 parent bb088a0 commit 6b14a86

File tree

3 files changed

+40
-3
lines changed

3 files changed

+40
-3
lines changed

.github/workflows/ci.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,17 @@ jobs:
139139
restore-keys: |
140140
${{ runner.os }}-emscripten
141141
142-
- name: Install dependenciesch
142+
- name: Install dependencies
143143
run: |
144144
npm ci
145145
146+
- name: Download MLIR
147+
run: |
148+
npm run download-mlir
149+
env:
150+
GH_TOKEN: ${{ github.token }}
151+
continue-on-error: true
152+
146153
- name: Prettier
147154
run: |
148155
npm -w cxx-frontend run prettier

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"update-tests": "zx scripts/update-tests.mjs",
4242
"cxx-gen-ast": "node packages/cxx-gen-ast",
4343
"cxx-gen-lsp": "node packages/cxx-gen-lsp packages/cxx-gen-lsp/metaModel.json packages/cxx-gen-lsp -o src/lsp/cxx/lsp",
44-
"download-lsp-model": "zx scripts/download-lsp-model.mjs"
44+
"download-lsp-model": "zx scripts/download-lsp-model.mjs",
45+
"download-mlir": "gh run download -n mlir --dir build.em/llvm-project/install/"
4546
}
4647
}

packages/cxx-frontend/scripts/build.js

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,17 @@ $.verbose = true;
2828
// get the root directory of the project
2929
const projectRootSourcePath = path.join(__dirname, "../../..");
3030

31+
const hasMLIR = fs.existsSync(
32+
path.join(
33+
projectRootSourcePath,
34+
"build.em/llvm-project/install/bin/llvm-tblgen.js",
35+
),
36+
);
37+
38+
if (hasMLIR) {
39+
console.log("building with MLIR support");
40+
}
41+
3142
// get the source path of the cxx-frontend package
3243
const cxxFrontendSourcePath = path.join(
3344
projectRootSourcePath,
@@ -108,6 +119,14 @@ async function dockerBuild() {
108119
);
109120
}
110121

122+
if (hasMLIR) {
123+
cmakeOptions.push(
124+
`-DCXX_ENABLE_MLIR=YES`,
125+
`-DLLVM_DIR=/code/build.em/llvm-project/install/lib/cmake/llvm`,
126+
`-DMLIR_DIR=/code/build.em/llvm-project/install/lib/cmake/mlir`,
127+
);
128+
}
129+
111130
const user = await $`id -u`;
112131

113132
await $`mkdir -p ${emscriptenCacheDir}`;
@@ -129,6 +148,14 @@ async function emsdkBuild({ cmake, emcmake, flatc, kwgen }) {
129148
`-B ${projectRootSourcePath}/build.em`,
130149
];
131150

151+
if (hasMLIR) {
152+
cmakeOptions.push(
153+
`-DCXX_ENABLE_MLIR=YES`,
154+
`-DLLVM_DIR=${projectRootSourcePath}/build.em/llvm-project/install/lib/cmake/llvm`,
155+
`-DMLIR_DIR=${projectRootSourcePath}/build.em/llvm-project/install/lib/cmake/mlir`,
156+
);
157+
}
158+
132159
if (argv.debug) {
133160
cmakeOptions.push(`-DCMAKE_BUILD_TYPE=Debug`);
134161
} else {
@@ -146,7 +173,9 @@ async function emsdkBuild({ cmake, emcmake, flatc, kwgen }) {
146173
async function emsdkBuildPresets() {
147174
const cmake = await which("cmake", { nothrow: true });
148175

149-
await $`${cmake} -S ${projectRootSourcePath} --preset emscripten`;
176+
const preset = hasMLIR ? "emscripten-mlir" : "emscripten";
177+
178+
await $`${cmake} -S ${projectRootSourcePath} --preset ${preset}`;
150179

151180
await $`${cmake} --build ${projectRootSourcePath}/build.em --target install`;
152181
}

0 commit comments

Comments
 (0)