From 753c553a12a14b3c1c9cc0ef334b5c5791f1465e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kr=C3=A6n=20Hansen?= Date: Mon, 20 Oct 2025 16:11:48 +0200 Subject: [PATCH 1/2] Fix expansion of options in --build and --out --- .changeset/fresh-frogs-enter.md | 5 +++++ packages/cmake-rn/src/cli.ts | 29 +++++++++++++++++++++-------- 2 files changed, 26 insertions(+), 8 deletions(-) create mode 100644 .changeset/fresh-frogs-enter.md diff --git a/.changeset/fresh-frogs-enter.md b/.changeset/fresh-frogs-enter.md new file mode 100644 index 00000000..76c39869 --- /dev/null +++ b/.changeset/fresh-frogs-enter.md @@ -0,0 +1,5 @@ +--- +"cmake-rn": patch +--- + +Fix expansion of options in --build and --out diff --git a/packages/cmake-rn/src/cli.ts b/packages/cmake-rn/src/cli.ts index a7d56530..0f4b105e 100644 --- a/packages/cmake-rn/src/cli.ts +++ b/packages/cmake-rn/src/cli.ts @@ -74,7 +74,7 @@ const tripletOption = new Option( const buildPathOption = new Option( "--build ", "Specify the build directory to store the configured CMake project", -); +).default("{source}/build"); const cleanOption = new Option( "--clean", @@ -84,7 +84,7 @@ const cleanOption = new Option( const outPathOption = new Option( "--out ", "Specify the output directory to store the final build artifacts", -).default(false, "./{build}/{configuration}"); +).default("./{build}/{configuration}"); const defineOption = new Option( "-D,--define ", @@ -151,8 +151,27 @@ for (const platform of platforms) { program = platform.amendCommand(program); } +function expandTemplate( + input: string, + values: Record, +): string { + return input.replaceAll(/{([^}]+)}/g, (_, key: string) => + typeof values[key] === "string" ? values[key] : "", + ); +} + program = program.action( wrapAction(async ({ triplet: requestedTriplets, ...baseOptions }) => { + baseOptions.build = path.resolve( + process.cwd(), + expandTemplate(baseOptions.build, baseOptions), + ); + baseOptions.out = path.resolve( + process.cwd(), + expandTemplate(baseOptions.out, baseOptions), + ); + const { build: buildPath } = baseOptions; + assertFixable( fs.existsSync(path.join(baseOptions.source, "CMakeLists.txt")), `No CMakeLists.txt found in source directory: ${chalk.dim(baseOptions.source)}`, @@ -161,7 +180,6 @@ program = program.action( }, ); - const buildPath = getBuildPath(baseOptions); if (baseOptions.clean) { await fs.promises.rm(buildPath, { recursive: true, force: true }); } @@ -288,11 +306,6 @@ function getTripletsSummary( .join(" / "); } -function getBuildPath({ build, source }: BaseOpts) { - // TODO: Add configuration (debug vs release) - return path.resolve(process.cwd(), build || path.join(source, "build")); -} - /** * Namespaces the output path with a triplet name */ From cf53c58fc024031bb55d53cbc285c5a85b1ae130 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kr=C3=A6n=20Hansen?= Date: Tue, 21 Oct 2025 11:28:30 +0200 Subject: [PATCH 2/2] Attempt at correcting paths on windows --- packages/cmake-rn/src/cli.ts | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/packages/cmake-rn/src/cli.ts b/packages/cmake-rn/src/cli.ts index 0f4b105e..10bf9f63 100644 --- a/packages/cmake-rn/src/cli.ts +++ b/packages/cmake-rn/src/cli.ts @@ -84,7 +84,7 @@ const cleanOption = new Option( const outPathOption = new Option( "--out ", "Specify the output directory to store the final build artifacts", -).default("./{build}/{configuration}"); +).default("{build}/{configuration}"); const defineOption = new Option( "-D,--define ", @@ -170,7 +170,7 @@ program = program.action( process.cwd(), expandTemplate(baseOptions.out, baseOptions), ); - const { build: buildPath } = baseOptions; + const { out, build: buildPath } = baseOptions; assertFixable( fs.existsSync(path.join(baseOptions.source, "CMakeLists.txt")), @@ -215,10 +215,6 @@ program = program.action( } } - if (!baseOptions.out) { - baseOptions.out = path.join(buildPath, baseOptions.configuration); - } - const tripletContexts = [...triplets].map((triplet) => { const platform = findPlatformForTriplet(triplet); const tripletBuildPath = getTripletBuildPath(buildPath, triplet); @@ -280,7 +276,7 @@ program = program.action( } await platform.postBuild( { - outputPath: baseOptions.out || baseOptions.source, + outputPath: out, triplets: relevantTriplets, }, baseOptions,