MCPcopy Create free account
hub / github.com/vercel/vercel / buildExecutableForDev

Function buildExecutableForDev

packages/rust/src/lib/dev-build.ts:9–68  ·  view source on GitHub ↗
(
  workPath: string,
  entrypoint: string
)

Source from the content-addressed store, hash-verified

7type RustEnv = Record<'RUSTFLAGS' | 'PATH', string>;
8
9export async function buildExecutableForDev(
10 workPath: string,
11 entrypoint: string
12): Promise<string> {
13 debug(`Building executable for development: ${entrypoint}`);
14
15 const HOME =
16 process.platform === 'win32' ? assertEnv('USERPROFILE') : assertEnv('HOME');
17 const PATH = assertEnv('PATH');
18
19 const rustEnv: RustEnv = {
20 PATH: `${path.join(HOME, '.cargo/bin')}${path.delimiter}${PATH}`,
21 RUSTFLAGS: [process.env.RUSTFLAGS].filter(Boolean).join(' '),
22 };
23
24 const entryPath = path.join(workPath, entrypoint);
25 const cargoWorkspace = await findCargoWorkspace({
26 env: rustEnv,
27 cwd: path.dirname(entryPath),
28 });
29
30 const binaryName = findBinaryName(cargoWorkspace, entryPath);
31
32 debug(`Building binary "${binaryName}" in debug mode for dev server`);
33
34 try {
35 await execa(
36 'cargo',
37 [
38 'build',
39 '--bin',
40 binaryName,
41 '--message-format=json-diagnostic-rendered-ansi',
42 ],
43 {
44 cwd: workPath,
45 env: rustEnv,
46 stdio: 'pipe',
47 }
48 );
49 } catch (err) {
50 debug(`Cargo build failed for ${binaryName}`);
51 throw new Error(`Failed to build Rust binary for development: ${err}`);
52 }
53
54 // Get the target directory and construct the path to the built executable
55 const { target_directory: targetDirectory } = await getCargoMetadata({
56 cwd: workPath,
57 env: rustEnv,
58 });
59
60 const executablePath = path.join(
61 targetDirectory,
62 'debug',
63 getExecutableName(binaryName)
64 );
65
66 debug(`Built executable at: ${executablePath}`);

Callers 1

startDevServerFunction · 0.90

Calls 9

debugFunction · 0.90
assertEnvFunction · 0.90
findCargoWorkspaceFunction · 0.90
findBinaryNameFunction · 0.90
getCargoMetadataFunction · 0.90
getExecutableNameFunction · 0.90
execaFunction · 0.85
filterMethod · 0.80
joinMethod · 0.45

Tested by

no test coverage detected