Skip to content

Tracking Issue for -Z codegen-backend #77933

Open

Description

@XAMPPRocky

This is a tracking issue for the -Zcodegen-backend compiler flag.

rustc today only supports one stable backend ("llvm"), but it has many unstable backends.

In the future, it will support multiple stable backends.

Our plan is that the stable backends will all be allowlisted in the compiler. The general pattern will be that every stable backend will be denoted by an identifier with no . in its name (e.g. "cranelift", "gcc", "llvm"). When we start reaching a point where one of the alternative backends is getting close to being ready to stabilize, we will then discuss how to offer a stable form of this flag (i.e. -C codegen-backend flag).

Meanwhile, the -Z codegen-backend flag will always unstably support an interface for connecting to an arbitrary backend loaded as a dynamic library, as described below.


This flag unstably allows you specify a path to a dynamic library containing a function named __rustc_codegen_backend with a signature of fn() -> Box<dyn rustc_codegen_ssa::traits::CodegenBackend> to use as code generation backend at runtime. (CodegenBackend trait)

Example

use rustc_codegen_ssa::traits::CodegenBackend;

struct MyBackend;

impl CodegenBackend for MyBackend {
   // Implement codegen methods
}

#[no_mangle]
pub fn __rustc_codegen_backend() -> Box<dyn CodegenBackend> {
    Box::new(MyBackend)
}

About tracking issues

Tracking issues are used to record the overall progress of implementation.
They are also used as hubs connecting to other relevant issues, e.g., bugs or open design questions.
A tracking issue is however not meant for large scale discussion, questions, or bug reports about a feature.
Instead, open a dedicated issue for the specific matter and add the relevant feature gate label.

Implementation history

Summary Notes

Generated by triagebot, see help for how to add more

Activity

  1. added
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    B-unstableBlocker: Implemented in the nightly compiler and unstable.
    C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFC
    on Oct 14, 2020
  2. added a commit that references this issue on Oct 14, 2020
  3. pnkfelix commented on Oct 21, 2022

    @pnkfelix
    Contributor

    Discussed at backlog bonanza

    https://rust-lang.zulipchat.com/#narrow/stream/238009-t-compiler.2Fmeetings/topic/.5Bplanning.20meeting.5D.202022-10-21/near/305370223

    We won't need a stable form of this flag until we have a alternative backend that is far enough along to be a candidate to be stabilized (i.e., its "blocked" on that issue, and thus impl-incomplete). Once we do, then we'll figure out whether we need two tracking issues (one for the stable parts of this, and another for the perma-unstable parts), or if we'll just have the one perma-unstable tracking issue.

  4. pnkfelix commented on Oct 21, 2022

    @pnkfelix
    Contributor

    @rustbot label: S-tracking-impl-incomplete

  5. added
    A-CLIArea: Command-line interface (CLI) to the compiler
    on Mar 5, 2023
  6. weihanglo commented on May 19, 2025

    @weihanglo
    Member

    @rustbot note cargo-integration

    I am too lazy to create a tracking issue on cargo side.

    Just noting that when stabilization in Cargo, Cargo might want to allow only known codegen backends. The full path of dylib codegen-backend support is perma-unstable, see rust-lang/cargo#15562 (comment).

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

    A-CLIArea: Command-line interface (CLI) to the compilerA-codegenArea: Code generationB-unstableBlocker: Implemented in the nightly compiler and unstable.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCS-tracking-impl-incompleteStatus: The implementation is incomplete.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions