]> git.proxmox.com Git - rustc.git/blame - src/doc/unstable-book/src/compiler-flags/codegen-backend.md
Merge tag 'debian/1.52.1+dfsg1-1_exp2' into proxmox/buster
[rustc.git] / src / doc / unstable-book / src / compiler-flags / codegen-backend.md
CommitLineData
29967ef6
XL
1# `codegen-backend`
2
3The tracking issue for this feature is: [#77933](https://github.com/rust-lang/rust/issues/77933).
4
5------------------------
6
7This feature allows you to specify a path to a dynamic library to use as rustc's
8code generation backend at runtime.
9
10Set the `-Zcodegen-backend=<path>` compiler flag to specify the location of the
11backend. The library must be of crate type `dylib` and must contain a function
12named `__rustc_codegen_backend` with a signature of `fn() -> Box<dyn rustc_codegen_ssa::traits::CodegenBackend>`.
13
14## Example
15See also the [`hotplug_codegen_backend`](https://github.com/rust-lang/rust/tree/master/src/test/run-make-fulldeps/hotplug_codegen_backend) test
16for a full example.
17
6a06907d 18```rust,ignore (partial-example)
29967ef6
XL
19use rustc_codegen_ssa::traits::CodegenBackend;
20
21struct MyBackend;
22
23impl CodegenBackend for MyBackend {
24 // Implement codegen methods
25}
26
27#[no_mangle]
28pub fn __rustc_codegen_backend() -> Box<dyn CodegenBackend> {
29 Box::new(MyBackend)
30}
31```