1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
//! Generating the wrapper project that turns a plugin rlib into a cdylib.
//!
//! # Why a wrapper is needed
//!
//! `cargo install` only knows about bin targets, so a `crate-type = ["cdylib"]` crate
//! cannot be installed that way. And `cargo build` on a plugin crate directly does not
//! make Cargo produce a cdylib for a dependency either.
//!
//! So a wrapper project of a few dozen lines is generated:
//!
//! ```text
//! <build dir>/<crate>/
//! ├── Cargo.toml # [lib] crate-type = ["cdylib"], depends on the plugin and the host contract crate
//! └── src/lib.rs # one line: <contract>::export!(<plugin_crate>::create);
//! ```
//!
//! The benefit is that the plugin's own crate stays a plain rlib: crates.io consumes
//! it normally, unit tests can `use` it directly, and the plugin author does not have
//! to write a single `#[no_mangle]`.
//!
//! # Two callers, one implementation
//!
//! | Caller | Plugin source | Purpose |
//! | --- | --- | --- |
//! | [`crate::install::build_host`] | a published crate, pinned | install on the user's machine |
//! | [`crate::pack`] | a local checkout, as a path dependency | produce the release assets |
//!
//! They must not drift apart. If the wrapper here stops calling `export!`, the cdylib
//! has no entry symbol and `dlopen` fails — on someone else's machine. If it stops
//! copying the plugin's own contract requirement, the graph holds two copies of the
//! contract crate and the build fails with an E0308 that mentions neither version.
//!
//! # Why the contract requirement is copied verbatim
//!
//! Getting this wrong is not a cosmetic problem. If the wrapper's requirement and the
//! plugin's own requirement resolve to different versions, the graph holds two copies
//! of the contract crate; each defines its own `PackageManager`, and the `export!` in
//! the wrapper stops typechecking with an E0308 that the plugin author has no way to
//! see coming. Cargo will not unify them for us even when one version satisfies both,
//! because `0.0.x` releases are incompatible across patches by definition. Copying the
//! plugin's own requirement makes the two agree by construction.
//!
//! # Layout
//!
//! [`write`] is the entry point: it renders the two files (`metadata` says where the
//! plugin comes from, `render` turns that into the manifest text) and writes them.
//! The `cargo metadata` helpers live in `metadata`, next to the types describing what
//! the plugin declares.
use Path;
use crateKitConfig;
use crateKitResult;
use wrapper_toml;
pub use ;
/// Writes the wrapper project into `dir` (which must already exist).
pub