(format: ModuleFormat, name: string)
| 146 | |
| 147 | // we define the config for wasm |
| 148 | function wasmEdgeRuntimeBuildConfig(format: ModuleFormat, name: string): BuildOptions { |
| 149 | return { |
| 150 | ...runtimesCommonBuildConfig, |
| 151 | format, |
| 152 | target: 'ES2022', |
| 153 | name, |
| 154 | outfile: `runtime/${name}`, |
| 155 | outExtension: getOutExtension(format), |
| 156 | define: { |
| 157 | ...runtimesCommonBuildConfig.define, |
| 158 | TARGET_BUILD_TYPE: `"${name}"`, |
| 159 | }, |
| 160 | plugins: [ |
| 161 | fillPlugin({ |
| 162 | // not yet enabled in edge build while driverAdapters is not GA |
| 163 | fillerOverrides: { ...commonRuntimesOverrides, ...smallBuffer, ...smallDecimal }, |
| 164 | }), |
| 165 | { |
| 166 | name: 'wasm-base64-encoder', |
| 167 | setup(build) { |
| 168 | build.onEnd(() => { |
| 169 | const extToModuleFormatMap = { |
| 170 | esm: 'mjs', |
| 171 | cjs: 'js', |
| 172 | } satisfies Record<ModuleFormat, string> |
| 173 | |
| 174 | for (const provider of DRIVER_ADAPTER_SUPPORTED_PROVIDERS) { |
| 175 | for (const buildType of QUERY_COMPILER_BUILD_TYPES) { |
| 176 | const wasmFilePath = path.join(wasmQueryCompilerDir, provider, `query_compiler_${buildType}_bg.wasm`) |
| 177 | try { |
| 178 | const wasmBuffer = fs.readFileSync(wasmFilePath) |
| 179 | for (const [moduleFormat, extension] of Object.entries(extToModuleFormatMap)) { |
| 180 | const base64FilePath = path.join( |
| 181 | runtimeDir, |
| 182 | `query_compiler_${buildType}_bg.${provider}.wasm-base64.${extension}`, |
| 183 | ) |
| 184 | const base64Content = wasmFileToBase64(wasmBuffer, moduleFormat as ModuleFormat) |
| 185 | fs.writeFileSync(base64FilePath, base64Content) |
| 186 | } |
| 187 | } catch (error) { |
| 188 | throw new Error(`Failed to create base64 encoded WASM file for ${provider}`, { |
| 189 | cause: error, |
| 190 | }) |
| 191 | } |
| 192 | } |
| 193 | } |
| 194 | }) |
| 195 | }, |
| 196 | }, |
| 197 | ], |
| 198 | } |
| 199 | } |
| 200 | |
| 201 | // old-style generator compatiblity shim for studio |
| 202 | const generatorBuildConfig: BuildOptions = { |
no test coverage detected