Skip to content

Commit a845a4e

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

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-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: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ $.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+
3138
// get the source path of the cxx-frontend package
3239
const cxxFrontendSourcePath = path.join(
3340
projectRootSourcePath,
@@ -129,6 +136,14 @@ async function emsdkBuild({ cmake, emcmake, flatc, kwgen }) {
129136
`-B ${projectRootSourcePath}/build.em`,
130137
];
131138

139+
if (hasMLIR) {
140+
cmakeOptions.push(
141+
`-DCXX_ENABLE_MLIR=YES`,
142+
`-DLLVM_DIR=${projectRootSourcePath}/build.em/llvm-project/install/lib/cmake/llvm`,
143+
`-DMLIR_DIR=${projectRootSourcePath}/build.em/llvm-project/install/lib/cmake/mlir`,
144+
);
145+
}
146+
132147
if (argv.debug) {
133148
cmakeOptions.push(`-DCMAKE_BUILD_TYPE=Debug`);
134149
} else {
@@ -146,7 +161,9 @@ async function emsdkBuild({ cmake, emcmake, flatc, kwgen }) {
146161
async function emsdkBuildPresets() {
147162
const cmake = await which("cmake", { nothrow: true });
148163

149-
await $`${cmake} -S ${projectRootSourcePath} --preset emscripten`;
164+
const preset = hasMLIR ? "emscripten-mlir" : "emscripten";
165+
166+
await $`${cmake} -S ${projectRootSourcePath} --preset ${preset}`;
150167

151168
await $`${cmake} --build ${projectRootSourcePath}/build.em --target install`;
152169
}

0 commit comments

Comments
 (0)