Skip to content

Commit a7e3d13

Browse files
committed
add docs to cc-detect
1 parent d88ffcd commit a7e3d13

File tree

1 file changed

+32
-3
lines changed

1 file changed

+32
-3
lines changed

src/bootstrap/src/utils/cc_detect.rs

+32-3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ use crate::utils::exec::{BootstrapCommand, command};
3030
use crate::{Build, CLang, GitRepo};
3131

3232
/// FIXME(onur-ozkan): This logic should be replaced by calling into the `cc` crate.
33+
/// Determines the archiver tool to use for the given target based on the compiler.
3334
fn cc2ar(cc: &Path, target: TargetSelection, default_ar: PathBuf) -> Option<PathBuf> {
3435
if let Some(ar) = env::var_os(format!("AR_{}", target.triple.replace('-', "_"))) {
3536
Some(PathBuf::from(ar))
@@ -58,6 +59,11 @@ fn cc2ar(cc: &Path, target: TargetSelection, default_ar: PathBuf) -> Option<Path
5859
}
5960
}
6061

62+
/// Creates and configures a new [`cc::Build`] instance for the given target.
63+
///
64+
/// This function initializes a new `cc::Build` object with a set of default options
65+
/// including optimization level, warning settings, and target/host configuration. It also
66+
/// applies static runtime configuration based on the target and build settings.
6167
fn new_cc_build(build: &Build, target: TargetSelection) -> cc::Build {
6268
let mut cfg = cc::Build::new();
6369
cfg.cargo_metadata(false)
@@ -84,6 +90,12 @@ fn new_cc_build(build: &Build, target: TargetSelection) -> cc::Build {
8490
cfg
8591
}
8692

93+
/// Probes for C and C++ compilers and configures the corresponding entries in the [`Build`]
94+
/// structure.
95+
///
96+
/// This function determines which targets need a C compiler (and, if needed, a C++ compiler)
97+
/// by combining the primary build target, host targets, and any additional targets. For
98+
/// each target, it calls [`find_target`] to configure the necessary compiler tools.
8799
pub fn find(build: &Build) {
88100
let targets: HashSet<_> = match build.config.cmd {
89101
// We don't need to check cross targets for these commands.
@@ -112,6 +124,11 @@ pub fn find(build: &Build) {
112124
}
113125
}
114126

127+
/// Probes and configures the C and C++ compilers for a single target.
128+
///
129+
/// This function uses both user-specified configuration (from `config.toml`) and auto-detection
130+
/// logic to determine the correct C/C++ compilers for the target. It also determines the appropriate
131+
/// archiver (`ar`) and sets up additional compilation flags (both handled and unhandled).
115132
pub fn find_target(build: &Build, target: TargetSelection) {
116133
let mut cfg = new_cc_build(build, target);
117134
let config = build.config.target_config.get(&target);
@@ -172,6 +189,8 @@ pub fn find_target(build: &Build, target: TargetSelection) {
172189
}
173190
}
174191

192+
/// Determines the default compiler for a given target and language when not explicitly
193+
/// configured in `config.toml`.
175194
fn default_compiler(
176195
cfg: &mut cc::Build,
177196
compiler: Language,
@@ -248,6 +267,12 @@ fn default_compiler(
248267
}
249268
}
250269

270+
/// Constructs the path to the Android NDK compiler for the given target triple and language.
271+
///
272+
/// This helper function transform the target triple by converting certain architecture names
273+
/// (for example, translating "arm" to "arm7a"), appends the minimum API level (hardcoded as "21"
274+
/// for NDK r26d), and then constructs the full path based on the provided NDK directory and host
275+
/// platform.
251276
pub(crate) fn ndk_compiler(compiler: Language, triple: &str, ndk: &Path) -> PathBuf {
252277
let mut triple_iter = triple.split('-');
253278
let triple_translated = if let Some(arch) = triple_iter.next() {
@@ -277,7 +302,11 @@ pub(crate) fn ndk_compiler(compiler: Language, triple: &str, ndk: &Path) -> Path
277302
ndk.join("toolchains").join("llvm").join("prebuilt").join(host_tag).join("bin").join(compiler)
278303
}
279304

280-
/// The target programming language for a native compiler.
305+
/// An enum representing the target programming language for a native compiler.
306+
///
307+
/// This enum is used to indicate whether a particular compiler is intended for C or C++.
308+
/// It also provides helper methods for obtaining the standard executable names for GCC and
309+
/// clang-based compilers.
281310
#[derive(PartialEq)]
282311
pub(crate) enum Language {
283312
/// The compiler is targeting C.
@@ -287,15 +316,15 @@ pub(crate) enum Language {
287316
}
288317

289318
impl Language {
290-
/// Obtains the name of a compiler in the GCC collection.
319+
/// Returns the executable name for a GCC compiler corresponding to this language.
291320
fn gcc(self) -> &'static str {
292321
match self {
293322
Language::C => "gcc",
294323
Language::CPlusPlus => "g++",
295324
}
296325
}
297326

298-
/// Obtains the name of a compiler in the clang suite.
327+
/// Returns the executable name for a clang-based compiler corresponding to this language.
299328
fn clang(self) -> &'static str {
300329
match self {
301330
Language::C => "clang",

0 commit comments

Comments
 (0)