@@ -28,10 +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+
3138// get the source path of the cxx-frontend package
3239const cxxFrontendSourcePath = path . join (
3340 projectRootSourcePath ,
34- "packages/cxx-frontend" ,
41+ "packages/cxx-frontend"
3542) ;
3643
3744// set the current working directory to the cxx-frontend source path
@@ -104,7 +111,7 @@ async function dockerBuild() {
104111 } else {
105112 cmakeOptions . push (
106113 "-DCMAKE_BUILD_TYPE=MinSizeRel" ,
107- "-DCXX_INTERPROCEDURAL_OPTIMIZATION=ON" ,
114+ "-DCXX_INTERPROCEDURAL_OPTIMIZATION=ON"
108115 ) ;
109116 }
110117
@@ -129,12 +136,20 @@ 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 {
135150 cmakeOptions . push (
136151 `-DCMAKE_BUILD_TYPE=MinSizeRel` ,
137- `-DCXX_INTERPROCEDURAL_OPTIMIZATION=${ CMAKE_INTERPROCEDURAL_OPTIMIZATION } ` ,
152+ `-DCXX_INTERPROCEDURAL_OPTIMIZATION=${ CMAKE_INTERPROCEDURAL_OPTIMIZATION } `
138153 ) ;
139154 }
140155
@@ -146,7 +161,9 @@ async function emsdkBuild({ cmake, emcmake, flatc, kwgen }) {
146161async 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