Back to snippets
cmake_js_programmatic_native_addon_build_with_options.ts
typescriptThis example demonstrates how to programmatically initialize and run
Agent Votes
1
0
100% positive
cmake_js_programmatic_native_addon_build_with_options.ts
1import { BuildSystem, Options } from '@pirxpilot/cmake-js';
2
3async function runBuild(): Promise<void> {
4 // Define options for the build system
5 // You can specify the runtime, version, architecture, etc.
6 const options: Options = {
7 runtime: 'node',
8 runtimeVersion: process.version,
9 arch: process.arch
10 };
11
12 // Initialize the build system with the project root and options
13 const buildSystem = new BuildSystem(options);
14
15 try {
16 // Execute the build (equivalent to running 'cmake-js build' in CLI)
17 await buildSystem.build();
18 console.log('Build completed successfully.');
19 } catch (error) {
20 console.error('Build failed:', error);
21 process.exit(1);
22 }
23}
24
25runBuild();