From c50a04bba3a9d08323b69789f8d567376a82189d Mon Sep 17 00:00:00 2001 From: Erin Power Date: Wed, 14 Oct 2020 14:34:47 +0200 Subject: [PATCH 1/4] Document -Z codegen-backend in the unstable book --- .../src/compiler-flags/codegen-backend.md | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/doc/unstable-book/src/compiler-flags/codegen-backend.md diff --git a/src/doc/unstable-book/src/compiler-flags/codegen-backend.md b/src/doc/unstable-book/src/compiler-flags/codegen-backend.md new file mode 100644 index 00000000000..28f173cb0f3 --- /dev/null +++ b/src/doc/unstable-book/src/compiler-flags/codegen-backend.md @@ -0,0 +1,28 @@ +# `codegen-backend` + +The tracking issue for this feature is: [#77933](https://github.com/rust-lang/rust/issues/77933). + +------------------------ + +This feature allows you to specify a path to a dynamic library to use as rustc's +code generation backend at runtime. + +Set the `-Zcodegen-backend=` compiler flag to specify the location of the +backend. The library must contain a function named `__rustc_codegen_backend` +with a signature of `fn() -> Box`. + +## Example +```rust +use rustc_codegen_ssa::traits::CodegenBackend; + +struct MyBackend; + +impl CodegenBackend for MyBackend { + // Implement codegen methods +} + +#[no_mangle] +pub fn __rustc_codegen_backend() -> Box { + Box::new(MyBackend) +} +``` From a0ea35116b352c194b0f7745812efe36cef752b4 Mon Sep 17 00:00:00 2001 From: XAMPPRocky <4464295+XAMPPRocky@users.noreply.github.com> Date: Wed, 14 Oct 2020 14:44:44 +0200 Subject: [PATCH 2/4] Update src/doc/unstable-book/src/compiler-flags/codegen-backend.md --- src/doc/unstable-book/src/compiler-flags/codegen-backend.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doc/unstable-book/src/compiler-flags/codegen-backend.md b/src/doc/unstable-book/src/compiler-flags/codegen-backend.md index 28f173cb0f3..efccff42caa 100644 --- a/src/doc/unstable-book/src/compiler-flags/codegen-backend.md +++ b/src/doc/unstable-book/src/compiler-flags/codegen-backend.md @@ -12,7 +12,7 @@ backend. The library must contain a function named `__rustc_codegen_backend` with a signature of `fn() -> Box`. ## Example -```rust +```rust,ignore use rustc_codegen_ssa::traits::CodegenBackend; struct MyBackend; From 9ff647a0d1565aa95069a5fc876b57cb35d6da16 Mon Sep 17 00:00:00 2001 From: XAMPPRocky <4464295+XAMPPRocky@users.noreply.github.com> Date: Wed, 14 Oct 2020 14:46:30 +0200 Subject: [PATCH 3/4] Update codegen-backend.md --- src/doc/unstable-book/src/compiler-flags/codegen-backend.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/doc/unstable-book/src/compiler-flags/codegen-backend.md b/src/doc/unstable-book/src/compiler-flags/codegen-backend.md index efccff42caa..87b2184676a 100644 --- a/src/doc/unstable-book/src/compiler-flags/codegen-backend.md +++ b/src/doc/unstable-book/src/compiler-flags/codegen-backend.md @@ -8,8 +8,8 @@ This feature allows you to specify a path to a dynamic library to use as rustc's code generation backend at runtime. Set the `-Zcodegen-backend=` compiler flag to specify the location of the -backend. The library must contain a function named `__rustc_codegen_backend` -with a signature of `fn() -> Box`. +backend. The library must be of crate type `dylib` and must contain a function +named `__rustc_codegen_backend` with a signature of `fn() -> Box`. ## Example ```rust,ignore From 6ae5f36d0d4527224295fbcd26ddbd70072cd6b8 Mon Sep 17 00:00:00 2001 From: XAMPPRocky <4464295+XAMPPRocky@users.noreply.github.com> Date: Wed, 14 Oct 2020 14:49:15 +0200 Subject: [PATCH 4/4] Update codegen-backend.md --- src/doc/unstable-book/src/compiler-flags/codegen-backend.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/doc/unstable-book/src/compiler-flags/codegen-backend.md b/src/doc/unstable-book/src/compiler-flags/codegen-backend.md index 87b2184676a..878c894a6ca 100644 --- a/src/doc/unstable-book/src/compiler-flags/codegen-backend.md +++ b/src/doc/unstable-book/src/compiler-flags/codegen-backend.md @@ -12,6 +12,9 @@ backend. The library must be of crate type `dylib` and must contain a function named `__rustc_codegen_backend` with a signature of `fn() -> Box`. ## Example +See also the [`hotplug_codegen_backend`](https://github.com/rust-lang/rust/tree/master/src/test/run-make-fulldeps/hotplug_codegen_backend) test +for a full example. + ```rust,ignore use rustc_codegen_ssa::traits::CodegenBackend;