@@ -30,6 +30,7 @@ use crate::utils::exec::{BootstrapCommand, command};
30
30
use crate :: { Build , CLang , GitRepo } ;
31
31
32
32
/// 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.
33
34
fn cc2ar ( cc : & Path , target : TargetSelection , default_ar : PathBuf ) -> Option < PathBuf > {
34
35
if let Some ( ar) = env:: var_os ( format ! ( "AR_{}" , target. triple. replace( '-' , "_" ) ) ) {
35
36
Some ( PathBuf :: from ( ar) )
@@ -58,6 +59,11 @@ fn cc2ar(cc: &Path, target: TargetSelection, default_ar: PathBuf) -> Option<Path
58
59
}
59
60
}
60
61
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.
61
67
fn new_cc_build ( build : & Build , target : TargetSelection ) -> cc:: Build {
62
68
let mut cfg = cc:: Build :: new ( ) ;
63
69
cfg. cargo_metadata ( false )
@@ -84,6 +90,12 @@ fn new_cc_build(build: &Build, target: TargetSelection) -> cc::Build {
84
90
cfg
85
91
}
86
92
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.
87
99
pub fn find ( build : & Build ) {
88
100
let targets: HashSet < _ > = match build. config . cmd {
89
101
// We don't need to check cross targets for these commands.
@@ -112,6 +124,11 @@ pub fn find(build: &Build) {
112
124
}
113
125
}
114
126
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).
115
132
pub fn find_target ( build : & Build , target : TargetSelection ) {
116
133
let mut cfg = new_cc_build ( build, target) ;
117
134
let config = build. config . target_config . get ( & target) ;
@@ -172,6 +189,8 @@ pub fn find_target(build: &Build, target: TargetSelection) {
172
189
}
173
190
}
174
191
192
+ /// Determines the default compiler for a given target and language when not explicitly
193
+ /// configured in `config.toml`.
175
194
fn default_compiler (
176
195
cfg : & mut cc:: Build ,
177
196
compiler : Language ,
@@ -248,6 +267,12 @@ fn default_compiler(
248
267
}
249
268
}
250
269
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.
251
276
pub ( crate ) fn ndk_compiler ( compiler : Language , triple : & str , ndk : & Path ) -> PathBuf {
252
277
let mut triple_iter = triple. split ( '-' ) ;
253
278
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
277
302
ndk. join ( "toolchains" ) . join ( "llvm" ) . join ( "prebuilt" ) . join ( host_tag) . join ( "bin" ) . join ( compiler)
278
303
}
279
304
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.
281
310
#[ derive( PartialEq ) ]
282
311
pub ( crate ) enum Language {
283
312
/// The compiler is targeting C.
@@ -287,15 +316,15 @@ pub(crate) enum Language {
287
316
}
288
317
289
318
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 .
291
320
fn gcc ( self ) -> & ' static str {
292
321
match self {
293
322
Language :: C => "gcc" ,
294
323
Language :: CPlusPlus => "g++" ,
295
324
}
296
325
}
297
326
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 .
299
328
fn clang ( self ) -> & ' static str {
300
329
match self {
301
330
Language :: C => "clang" ,
0 commit comments