@@ -28,6 +28,17 @@ $.verbose = true;
2828// get the root directory of the project
2929const 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
3243const 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 }) {
146173async 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