Skip to content

Allow configuring arbitrary codegen backends #15562

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

Merged
merged 1 commit into from
May 19, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 5 additions & 24 deletions src/cargo/util/toml/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2465,25 +2465,15 @@ pub fn validate_profile(
features: &Features,
warnings: &mut Vec<String>,
) -> CargoResult<()> {
validate_profile_layer(root, name, cli_unstable, features)?;
validate_profile_layer(root, cli_unstable, features)?;
if let Some(ref profile) = root.build_override {
validate_profile_override(profile, "build-override")?;
validate_profile_layer(
profile,
&format!("{name}.build-override"),
cli_unstable,
features,
)?;
validate_profile_layer(profile, cli_unstable, features)?;
}
if let Some(ref packages) = root.package {
for (override_name, profile) in packages {
for profile in packages.values() {
validate_profile_override(profile, "package")?;
validate_profile_layer(
profile,
&format!("{name}.package.{override_name}"),
cli_unstable,
features,
)?;
validate_profile_layer(profile, cli_unstable, features)?;
}
}

Expand Down Expand Up @@ -2548,26 +2538,17 @@ pub fn validate_profile(
/// This is a shallow check, which is reused for the profile itself and any overrides.
fn validate_profile_layer(
profile: &manifest::TomlProfile,
name: &str,
cli_unstable: &CliUnstable,
features: &Features,
) -> CargoResult<()> {
if let Some(codegen_backend) = &profile.codegen_backend {
if profile.codegen_backend.is_some() {
match (
features.require(Feature::codegen_backend()),
cli_unstable.codegen_backend,
) {
(Err(e), false) => return Err(e),
_ => {}
}

if codegen_backend.contains(|c: char| !c.is_ascii_alphanumeric() && c != '_') {
bail!(
"`profile.{}.codegen-backend` setting of `{}` is not a valid backend name.",
name,
codegen_backend,
);
}
Copy link
Member Author

Choose a reason for hiding this comment

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

If preferred I can also keep this check on the cargo side when nightly features are disabled.

Copy link
Member

Choose a reason for hiding this comment

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

How arbitrary you'd like to have for codegen-backend name? What is the real use case here?

The change seems fine to me though, as a nightly feature.

Copy link
Member Author

Choose a reason for hiding this comment

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

Basically -Zcodegen-backend allows either of the following:

  • The name of a builtin codegen backend. This will eventually be stabilized once one of the non-LLVM backends gets stabilized.
  • The full path to a dylib implementing a codegen backend. This will never be stable. It exists to allow codegen backends not shipped as part of rustc to be used. For example cg_clif uses it when you locally build it or when using the version from its CI rather than the rustup distributed version (the CI version is newer). Same for cg_gcc when you locally build it.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for the info! It makes sense to relax it a bit for now.

When stabilization, Cargo should only allow a set of known backends. We should track it somewhere, though we dont really have a Cargo tracking issue for codegen-backend right now.

Copy link
Member

Choose a reason for hiding this comment

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

}
if profile.rustflags.is_some() {
match (
Expand Down