Skip to content

Commit 2547197

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

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

.github/workflows/ci.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,18 @@ 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+
ls -la build.em/llvm-project/install/
150+
env:
151+
GH_TOKEN: ${{ github.token }}
152+
continue-on-error: true
153+
146154
- name: Prettier
147155
run: |
148156
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: 22 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,
@@ -129,6 +140,14 @@ async function emsdkBuild({ cmake, emcmake, flatc, kwgen }) {
129140
`-B ${projectRootSourcePath}/build.em`,
130141
];
131142

143+
if (hasMLIR) {
144+
cmakeOptions.push(
145+
`-DCXX_ENABLE_MLIR=YES`,
146+
`-DLLVM_DIR=${projectRootSourcePath}/build.em/llvm-project/install/lib/cmake/llvm`,
147+
`-DMLIR_DIR=${projectRootSourcePath}/build.em/llvm-project/install/lib/cmake/mlir`,
148+
);
149+
}
150+
132151
if (argv.debug) {
133152
cmakeOptions.push(`-DCMAKE_BUILD_TYPE=Debug`);
134153
} else {
@@ -146,7 +165,9 @@ async function emsdkBuild({ cmake, emcmake, flatc, kwgen }) {
146165
async function emsdkBuildPresets() {
147166
const cmake = await which("cmake", { nothrow: true });
148167

149-
await $`${cmake} -S ${projectRootSourcePath} --preset emscripten`;
168+
const preset = hasMLIR ? "emscripten-mlir" : "emscripten";
169+
170+
await $`${cmake} -S ${projectRootSourcePath} --preset ${preset}`;
150171

151172
await $`${cmake} --build ${projectRootSourcePath}/build.em --target install`;
152173
}

0 commit comments

Comments
 (0)