Skip to content

Commit 6bdf340

Browse files
committed
add docs to cc-detect
1 parent c3fe9e7 commit 6bdf340

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

src/bootstrap/src/utils/cc_detect.rs

+28-3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ use crate::core::config::TargetSelection;
2929
use crate::utils::exec::{BootstrapCommand, command};
3030
use crate::{Build, CLang, GitRepo};
3131

32+
/// Finds archiver tool for the given target if possible.
3233
/// FIXME(onur-ozkan): This logic should be replaced by calling into the `cc` crate.
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('-', "_"))) {
@@ -58,6 +59,7 @@ 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.
6163
fn new_cc_build(build: &Build, target: TargetSelection) -> cc::Build {
6264
let mut cfg = cc::Build::new();
6365
cfg.cargo_metadata(false)
@@ -84,6 +86,12 @@ fn new_cc_build(build: &Build, target: TargetSelection) -> cc::Build {
8486
cfg
8587
}
8688

89+
/// Probes for C and C++ compilers and configures the corresponding entries in the [`Build`]
90+
/// structure.
91+
///
92+
/// This function determines which targets need a C compiler (and, if needed, a C++ compiler)
93+
/// by combining the primary build target, host targets, and any additional targets. For
94+
/// each target, it calls [`find_target`] to configure the necessary compiler tools.
8795
pub fn find(build: &Build) {
8896
let targets: HashSet<_> = match build.config.cmd {
8997
// We don't need to check cross targets for these commands.
@@ -112,6 +120,11 @@ pub fn find(build: &Build) {
112120
}
113121
}
114122

123+
/// Probes and configures the C and C++ compilers for a single target.
124+
///
125+
/// This function uses both user-specified configuration (from `config.toml`) and auto-detection
126+
/// logic to determine the correct C/C++ compilers for the target. It also determines the appropriate
127+
/// archiver (`ar`) and sets up additional compilation flags (both handled and unhandled).
115128
pub fn find_target(build: &Build, target: TargetSelection) {
116129
let mut cfg = new_cc_build(build, target);
117130
let config = build.config.target_config.get(&target);
@@ -172,6 +185,8 @@ pub fn find_target(build: &Build, target: TargetSelection) {
172185
}
173186
}
174187

188+
/// Determines the default compiler for a given target and language when not explicitly
189+
/// configured in `config.toml`.
175190
fn default_compiler(
176191
cfg: &mut cc::Build,
177192
compiler: Language,
@@ -248,6 +263,12 @@ fn default_compiler(
248263
}
249264
}
250265

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

280-
/// The target programming language for a native compiler.
301+
/// Representing the target programming language for a native compiler.
302+
///
303+
/// This enum is used to indicate whether a particular compiler is intended for C or C++.
304+
/// It also provides helper methods for obtaining the standard executable names for GCC and
305+
/// clang-based compilers.
281306
#[derive(PartialEq)]
282307
pub(crate) enum Language {
283308
/// The compiler is targeting C.
@@ -287,15 +312,15 @@ pub(crate) enum Language {
287312
}
288313

289314
impl Language {
290-
/// Obtains the name of a compiler in the GCC collection.
315+
/// Returns the executable name for a GCC compiler corresponding to this language.
291316
fn gcc(self) -> &'static str {
292317
match self {
293318
Language::C => "gcc",
294319
Language::CPlusPlus => "g++",
295320
}
296321
}
297322

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

0 commit comments

Comments
 (0)