(options: BuildOptions)
| 33 | type RustEnv = Record<'RUSTFLAGS' | 'PATH', string>; |
| 34 | |
| 35 | async function buildHandler(options: BuildOptions): Promise<BuildResultV3> { |
| 36 | const BUILDER_DEBUG = Boolean(process.env.VERCEL_BUILDER_DEBUG ?? false); |
| 37 | const isVercelBuild = Boolean(process.env.VERCEL_BUILD_IMAGE ?? false); |
| 38 | |
| 39 | const { files, entrypoint, workPath, config, meta, service } = options; |
| 40 | |
| 41 | // If we are not building on Vercel and we are not initiainted from `vercel dev`, |
| 42 | // we are building for a prebuilt deployment, so we need to cross-compile |
| 43 | const crossCompilationEnabled = !isVercelBuild && !meta?.isDev; |
| 44 | |
| 45 | if (crossCompilationEnabled && process.platform === 'win32') { |
| 46 | throw new Error( |
| 47 | 'Production prebuilt deployments for @vercel/rust are not yet supported on Windows. Please use a Linux or macOS environment, or deploy directly on Vercel.' |
| 48 | ); |
| 49 | } |
| 50 | |
| 51 | await installRustToolchain(); |
| 52 | |
| 53 | debug('Creating file system'); |
| 54 | const downloadedFiles = await download(files, workPath, meta); |
| 55 | const entryPath = downloadedFiles[entrypoint].fsPath; |
| 56 | |
| 57 | const HOME = |
| 58 | process.platform === 'win32' ? assertEnv('USERPROFILE') : assertEnv('HOME'); |
| 59 | const PATH = assertEnv('PATH'); |
| 60 | |
| 61 | const rustEnv: RustEnv = { |
| 62 | PATH: `${path.join(HOME, '.cargo/bin')}${path.delimiter}${PATH}`, |
| 63 | RUSTFLAGS: [process.env.RUSTFLAGS].filter(Boolean).join(' '), |
| 64 | }; |
| 65 | |
| 66 | const cargoWorkspace = await findCargoWorkspace({ |
| 67 | env: rustEnv, |
| 68 | cwd: path.dirname(entryPath), |
| 69 | }); |
| 70 | |
| 71 | const binaryName = findBinaryName(cargoWorkspace, entryPath); |
| 72 | const cargoBuildConfiguration = |
| 73 | await findCargoBuildConfiguration(cargoWorkspace); |
| 74 | |
| 75 | await runUserScripts(workPath); |
| 76 | |
| 77 | const extraFiles = await gatherExtraFiles(config.includeFiles, workPath); |
| 78 | |
| 79 | const lambdaOptions = await getLambdaOptionsFromFunction({ |
| 80 | sourceFile: entrypoint, |
| 81 | config, |
| 82 | }); |
| 83 | |
| 84 | const architecture = lambdaOptions?.architecture || 'x86_64'; |
| 85 | |
| 86 | const buildVariant = meta?.isDev ? 'debug' : 'release'; |
| 87 | const buildTarget = cargoBuildConfiguration?.build.target ?? ''; |
| 88 | const targetTriple = |
| 89 | architecture === 'x86_64' |
| 90 | ? 'x86_64-unknown-linux-gnu' |
| 91 | : 'aarch64-unknown-linux-gnu'; |
| 92 |
nothing calls this directly
no test coverage detected