Skip to content

Commit 0cf86c2

Browse files
authored
Rollup merge of #77934 - XAMPPRocky:codegen-backend-docs, r=jonas-schievink
Document -Z codegen-backend in the unstable book ### [Rendered](https://github.com/XAMPPRocky/rust/blob/codegen-backend-docs/src/doc/unstable-book/src/compiler-flags/codegen-backend.md) Companion PR to #77933 tracking issue. cc @bjorn3
2 parents b3f9512 + 6ae5f36 commit 0cf86c2

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# `codegen-backend`
2+
3+
The tracking issue for this feature is: [#77933](https://github.com/rust-lang/rust/issues/77933).
4+
5+
------------------------
6+
7+
This feature allows you to specify a path to a dynamic library to use as rustc's
8+
code generation backend at runtime.
9+
10+
Set the `-Zcodegen-backend=<path>` compiler flag to specify the location of the
11+
backend. The library must be of crate type `dylib` and must contain a function
12+
named `__rustc_codegen_backend` with a signature of `fn() -> Box<dyn rustc_codegen_ssa::traits::CodegenBackend>`.
13+
14+
## Example
15+
See also the [`hotplug_codegen_backend`](https://github.com/rust-lang/rust/tree/master/src/test/run-make-fulldeps/hotplug_codegen_backend) test
16+
for a full example.
17+
18+
```rust,ignore
19+
use rustc_codegen_ssa::traits::CodegenBackend;
20+
21+
struct MyBackend;
22+
23+
impl CodegenBackend for MyBackend {
24+
// Implement codegen methods
25+
}
26+
27+
#[no_mangle]
28+
pub fn __rustc_codegen_backend() -> Box<dyn CodegenBackend> {
29+
Box::new(MyBackend)
30+
}
31+
```

0 commit comments

Comments
 (0)