Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmake: Use cargo --target-dir #10346

Closed
wants to merge 1 commit into from
Closed

Conversation

faho
Copy link
Member

@faho faho commented Mar 6, 2024

This isolates cargo's output in the cmake build directory, so it no longer creates a target/ in the repository.

Unfortunately cargo still decides to create
"x86_64-unknown-linux-gnu/debug/" (target-triple/profile), there's no way to get it to build in this directory.

Note that this will create about ~600M in the build directory instead of sharing among them.

This isolates cargo's output in the cmake build directory, so it no
longer creates a target/ in the repository.

Unfortunately cargo still decides to create
"x86_64-unknown-linux-gnu/debug/" (target-triple/profile), there's no
way to get it to build *in this directory*.

Note that this *will* create about ~600M in the build directory
instead of sharing among them.
@faho faho added this to the fish next-3.x milestone Mar 6, 2024
COMMAND ${CMAKE_COMMAND} -E env
${VARS_FOR_CARGO}
${Rust_CARGO} ARGS build --bin ${target}
$<$<CONFIG:Release,RelWithDebInfo>:--release>
--target ${Rust_CARGO_TARGET}
--target-dir ${CMAKE_CURRENT_BINARY_DIR}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we already override the target dir witih CARGO_TARGET_DIR which is passed via VARS_FOR_CARGO.
This is why docker/docker_run_tests.sh docker/opensuse-tumbleweed.docker works, which mounts the source tree read-only.
But it looks like our "CARGO_TARGET_DIR=${FISH_RUST_BUILD_DIR}" is inconsistent with ${rust_target_dir}.
We should probably fix that to use the same target dir everywhere, at least inside cmake land.

I think today the top-level target/ directory should only be created by cargo b and things like rust-analyzer and cargo clippy.
I don't know if there's a good way to override this but long-term we should try to get rid of cmake anyway.
Right now, adding a new source file requires a manual cmake rerun.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we already override the target dir witih CARGO_TARGET_DIR which is passed via VARS_FOR_CARGO.

Huh, cool. This is unnecessary then.

I think my "target" might have been created by rust-analyzer then.

But it looks like our "CARGO_TARGET_DIR=${FISH_RUST_BUILD_DIR}" is inconsistent with ${rust_target_dir}.

"rust_target_dir" is FISH_RUST_BUILD_DIR plus the arch-os-triple.

we should try to get rid of cmake anyway

Of course.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could make a .cargo/config.toml with target-dir = "build/cargo/build", which rust-analyzer and friends pick up

https://doc.rust-lang.org/cargo/reference/config.html#configuration

@faho faho closed this Mar 6, 2024
@faho faho deleted the cargo-out-of-tree branch March 7, 2024 07:46
@krobelus
Copy link
Member

krobelus commented Mar 7, 2024 via email

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

Successfully merging this pull request may close these issues.

None yet

3 participants