Skip to content

Ask Cargo for the target directory instead of guessing it #182

Open

Description

@rvandermeulen

The plugin looks for built libraries in ${module}/target unless targetDirectory, rust.cargoTargetDir or CARGO_TARGET_DIR says otherwise. That guess is wrong for any crate in a Cargo workspace, where Cargo writes to the workspace root's target/. It is also wrong when .cargo/config.toml sets build.target-dir, which the plugin never reads. The other way around, rust.cargoTargetDir only changes where the plugin looks, not where Cargo writes. #181 makes a wrong guess fail the build instead of producing an AAR with no native library, but users still have to work out the right path themselves.

cargo metadata --format-version 1 --no-deps, run in the module directory, reports target_directory with all of these already resolved: workspaces, CARGO_TARGET_DIR and build.target-dir. Running it in CargoBuildTask before the copy, with the same environment as the build, would let the plugin find the output without any configuration.

Open questions:

  • Whether targetDirectory and rust.cargoTargetDir stay as overrides or get deprecated.
  • The metadata call has to see the environment the exec closure sets (for example, a CARGO_TARGET_DIR set there), and a --target-dir passed in extraCargoBuildArguments.
  • An alternative is cargo build --message-format=json-diagnostic-rendered-ansi, which reports the exact path of each built library. That would also remove the guessing of the profile directory and library file names, but the plugin would then have to print the compiler diagnostics itself.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions