diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 02fe5dd5..776be234 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -135,14 +135,21 @@ jobs: uses: actions/cache@v4 with: path: ~/.emscripten-cache - key: ${{ runner.os }}-emscripten + key: ${{ runner.os }}-emscripten-{{ hashFiles('/home/runner/.emscripten-cache/sanity.txt') }} restore-keys: | - ${{ runner.os }}-emscripten + ${{ runner.os }}-emscripten- - - name: Install dependenciesch + - name: Install dependencies run: | npm ci + - name: Download MLIR + run: | + npm run download-mlir + env: + GH_TOKEN: ${{ github.token }} + continue-on-error: true + - name: Prettier run: | npm -w cxx-frontend run prettier diff --git a/package.json b/package.json index de131543..6c3b1289 100644 --- a/package.json +++ b/package.json @@ -41,6 +41,7 @@ "update-tests": "zx scripts/update-tests.mjs", "cxx-gen-ast": "node packages/cxx-gen-ast", "cxx-gen-lsp": "node packages/cxx-gen-lsp packages/cxx-gen-lsp/metaModel.json packages/cxx-gen-lsp -o src/lsp/cxx/lsp", - "download-lsp-model": "zx scripts/download-lsp-model.mjs" + "download-lsp-model": "zx scripts/download-lsp-model.mjs", + "download-mlir": "gh run download -n mlir --dir build.em/llvm-project/install/" } } diff --git a/packages/cxx-frontend/scripts/build.js b/packages/cxx-frontend/scripts/build.js index b396a384..c3ab30fa 100644 --- a/packages/cxx-frontend/scripts/build.js +++ b/packages/cxx-frontend/scripts/build.js @@ -28,6 +28,17 @@ $.verbose = true; // get the root directory of the project const projectRootSourcePath = path.join(__dirname, "../../.."); +const hasMLIR = fs.existsSync( + path.join( + projectRootSourcePath, + "build.em/llvm-project/install/bin/llvm-tblgen.js", + ), +); + +if (hasMLIR) { + console.log("building with MLIR support"); +} + // get the source path of the cxx-frontend package const cxxFrontendSourcePath = path.join( projectRootSourcePath, @@ -108,6 +119,14 @@ async function dockerBuild() { ); } + if (hasMLIR) { + cmakeOptions.push( + `-DCXX_ENABLE_MLIR=YES`, + `-DLLVM_DIR=/code/build.em/llvm-project/install/lib/cmake/llvm`, + `-DMLIR_DIR=/code/build.em/llvm-project/install/lib/cmake/mlir`, + ); + } + const user = await $`id -u`; await $`mkdir -p ${emscriptenCacheDir}`; @@ -129,6 +148,14 @@ async function emsdkBuild({ cmake, emcmake, flatc, kwgen }) { `-B ${projectRootSourcePath}/build.em`, ]; + if (hasMLIR) { + cmakeOptions.push( + `-DCXX_ENABLE_MLIR=YES`, + `-DLLVM_DIR=${projectRootSourcePath}/build.em/llvm-project/install/lib/cmake/llvm`, + `-DMLIR_DIR=${projectRootSourcePath}/build.em/llvm-project/install/lib/cmake/mlir`, + ); + } + if (argv.debug) { cmakeOptions.push(`-DCMAKE_BUILD_TYPE=Debug`); } else { @@ -146,7 +173,9 @@ async function emsdkBuild({ cmake, emcmake, flatc, kwgen }) { async function emsdkBuildPresets() { const cmake = await which("cmake", { nothrow: true }); - await $`${cmake} -S ${projectRootSourcePath} --preset emscripten`; + const preset = hasMLIR ? "emscripten-mlir" : "emscripten"; + + await $`${cmake} -S ${projectRootSourcePath} --preset ${preset}`; await $`${cmake} --build ${projectRootSourcePath}/build.em --target install`; }