diff --git a/dist/index.js b/dist/index.js index 5e07cb4..9099a10 100644 --- a/dist/index.js +++ b/dist/index.js @@ -11488,7 +11488,7 @@ function getCliValue(args, key) { } return undefined; } -function getCargoTargetDir(args) { +async function getCargoTargetDir(args) { let targetDir = 'target'; const val = getCliValue(args, '--target-dir'); const manifestPath = getCliValue(args, '--manifest-path') || getCliValue(args, '-m'); @@ -11500,7 +11500,16 @@ function getCargoTargetDir(args) { targetDir = process.env.CARGO_TARGET_DIR; } else if (manifestPath && manifestPath.length > 0) { - targetDir = path.join(path.dirname(manifestPath), 'target'); + const res = await mexec.exec('cargo', ['metadata', '--format-version', '1', '--manifest-path', manifestPath], true); + if (res.success) { + const metadata = JSON.parse(res.stdout); + targetDir = metadata.target_directory; + } + else { + core.warning('Failed to get Cargo target directory from `cargo metadata`'); + core.debug(res.stderr); + targetDir = path.join(path.dirname(manifestPath), 'target'); + } } return targetDir; } @@ -11715,7 +11724,7 @@ async function dockerBuild(container, maturinRelease, args) { const scriptPath = path.join(os.tmpdir(), 'run-maturin-action.sh'); (0, fs_1.writeFileSync)(scriptPath, commands.join('\n')); await fs_1.promises.chmod(scriptPath, 0o755); - const targetDir = getCargoTargetDir(args); + const targetDir = await getCargoTargetDir(args); core.startGroup('Cleanup build scripts artifact directory'); const debugBuildDir = path.join(targetDir, 'debug', 'build'); if ((0, fs_1.existsSync)(debugBuildDir)) { diff --git a/src/index.ts b/src/index.ts index d5b810b..a1f68e1 100644 --- a/src/index.ts +++ b/src/index.ts @@ -220,7 +220,7 @@ function getCliValue(args: string[], key: string): string | undefined { return undefined } -function getCargoTargetDir(args: string[]): string { +async function getCargoTargetDir(args: string[]): Promise { let targetDir = 'target' const val = getCliValue(args, '--target-dir') const manifestPath = @@ -233,7 +233,19 @@ function getCargoTargetDir(args: string[]): string { ) { targetDir = process.env.CARGO_TARGET_DIR } else if (manifestPath && manifestPath.length > 0) { - targetDir = path.join(path.dirname(manifestPath), 'target') + const res = await mexec.exec( + 'cargo', + ['metadata', '--format-version', '1', '--manifest-path', manifestPath], + true + ) + if (res.success) { + const metadata = JSON.parse(res.stdout) + targetDir = metadata.target_directory + } else { + core.warning('Failed to get Cargo target directory from `cargo metadata`') + core.debug(res.stderr) + targetDir = path.join(path.dirname(manifestPath), 'target') + } } return targetDir } @@ -537,7 +549,7 @@ async function dockerBuild( writeFileSync(scriptPath, commands.join('\n')) await fs.chmod(scriptPath, 0o755) - const targetDir = getCargoTargetDir(args) + const targetDir = await getCargoTargetDir(args) core.startGroup('Cleanup build scripts artifact directory') const debugBuildDir = path.join(targetDir, 'debug', 'build')