1use anyhow::Result;
2
3mod cargo_cmd;
4mod cli;
5mod command;
6mod sysroot;
7pub mod toolchain;
8pub mod toolchain_flags;
9
10use cargo_cmd::CargoCmd;
11pub use cli::Args;
12pub use command::Command;
13mod util;
14
15pub fn cargo() -> Result<Command> {
44 Command::new()
45}
46
47impl Args {
48 pub fn sysroot_dir(&self) -> std::path::PathBuf {
49 self.target_dir.join("sysroot")
50 }
51
52 pub fn triplet_dir(&self) -> std::path::PathBuf {
53 self.sysroot_dir()
54 .join("lib")
55 .join("rustlib")
56 .join(&self.target)
57 }
58
59 pub fn build_dir(&self) -> std::path::PathBuf {
60 self.sysroot_dir().join("target")
61 }
62
63 pub fn c_libs_dir(&self) -> std::path::PathBuf {
64 self.sysroot_dir().join("lib")
65 }
66
67 pub fn wrapper_src_dir(&self) -> std::path::PathBuf {
68 self.sysroot_dir().join("wrapper")
69 }
70
71 pub fn wrapper_dir(&self) -> std::path::PathBuf {
72 self.sysroot_dir().join("bin")
73 }
74
75 pub fn rust_libs_dir(&self) -> std::path::PathBuf {
76 self.triplet_dir().join("lib")
77 }
78
79 pub fn includes_dir(&self) -> std::path::PathBuf {
80 self.sysroot_dir().join("include")
81 }
82
83 pub fn crate_dir(&self) -> std::path::PathBuf {
84 self.sysroot_dir().join("crate")
85 }
86}
87
88trait CargoCommandExt {
89 fn populate_from_args(&mut self, args: &Args, bootstrap: bool) -> &mut Self;
90}
91
92impl CargoCommandExt for std::process::Command {
93 fn populate_from_args(&mut self, args: &Args, bootstrap: bool) -> &mut Self {
94 self.target(&args.target);
95 self.sysroot(args.sysroot_dir());
96 self.append_rustflags("--cfg=hyperlight");
97 self.append_rustflags("--check-cfg=cfg(hyperlight)");
98 self.entrypoint("entrypoint");
99 if let Some(clang) = &args.clang {
100 self.cc_env(&args.target, clang);
101 } else {
102 self.cc_env(&args.target, "clang");
106 }
107 if let Some(ar) = &args.ar {
108 self.ar_env(&args.target, ar);
109 } else {
110 }
112 self.append_cflags(&args.target, toolchain::cflags(args, bootstrap).joined());
113
114 self
115 }
116}
117
118impl Args {
119 pub fn prepare_sysroot(&self) -> Result<()> {
120 sysroot::build(self)?;
122
123 toolchain::prepare(self)?;
125
126 Ok(())
127 }
128}