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
use std::ffi::OsString;
use which::which;
pub fn cross_compile_assistance(target_triple: impl AsRef<str>) -> CrossCompileAssistance {
if target_triple.as_ref() == X86_64_UNKNOWN_LINUX_MUSL && cfg!(target_os = "macos") {
let possible_gcc_binary_names =
vec!["x86_64-unknown-linux-musl-gcc", "x86_64-linux-musl-gcc"];
possible_gcc_binary_names
.iter()
.find_map(|binary_name| which(binary_name).ok())
.map_or_else(|| CrossCompileAssistance::HelpText(String::from(
r#"For cross-compilation from macOS to x86_64-unknown-linux-musl, a C compiler and
linker for the target platform must be installed on your computer.
The easiest way to install the required cross-compilation toolchain is to run:
brew install messense/macos-cross-toolchains/x86_64-unknown-linux-musl
For more information, see:
https://github.com/messense/homebrew-macos-cross-toolchains"#,
)), |gcc_binary_path| {
CrossCompileAssistance::Configuration {
cargo_env: vec![
(
OsString::from("CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_LINKER"),
OsString::from(&gcc_binary_path),
),
(
OsString::from("CC_x86_64_unknown_linux_musl"),
OsString::from(&gcc_binary_path),
),
],
}
})
} else if target_triple.as_ref() == X86_64_UNKNOWN_LINUX_MUSL && cfg!(target_os = "linux") {
match which("musl-gcc") {
Ok(_) => CrossCompileAssistance::Configuration { cargo_env: vec![] },
Err(_) => CrossCompileAssistance::HelpText(String::from(
r#"For cross-compilation from Linux to x86_64-unknown-linux-musl, a C compiler and
linker for the target platform must be installed on your computer.
The easiest way to install 'musl-gcc' is to install the 'musl-tools' package:
- https://packages.ubuntu.com/focal/musl-tools
- https://packages.debian.org/bullseye/musl-tools"#,
)),
}
} else {
CrossCompileAssistance::NoAssistance
}
}
pub enum CrossCompileAssistance {
NoAssistance,
HelpText(String),
Configuration {
cargo_env: Vec<(OsString, OsString)>,
},
}
const X86_64_UNKNOWN_LINUX_MUSL: &str = "x86_64-unknown-linux-musl";