@@ -29,6 +29,7 @@ use crate::core::config::TargetSelection;
29
29
use crate :: utils:: exec:: { BootstrapCommand , command} ;
30
30
use crate :: { Build , CLang , GitRepo } ;
31
31
32
+ /// Finds archiver tool for the given target if possible.
32
33
/// FIXME(onur-ozkan): This logic should be replaced by calling into the `cc` crate.
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( '-' , "_" ) ) ) {
@@ -58,6 +59,7 @@ 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.
61
63
fn new_cc_build ( build : & Build , target : TargetSelection ) -> cc:: Build {
62
64
let mut cfg = cc:: Build :: new ( ) ;
63
65
cfg. cargo_metadata ( false )
@@ -84,6 +86,12 @@ fn new_cc_build(build: &Build, target: TargetSelection) -> cc::Build {
84
86
cfg
85
87
}
86
88
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.
87
95
pub fn find ( build : & Build ) {
88
96
let targets: HashSet < _ > = match build. config . cmd {
89
97
// We don't need to check cross targets for these commands.
@@ -112,6 +120,11 @@ pub fn find(build: &Build) {
112
120
}
113
121
}
114
122
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).
115
128
pub fn find_target ( build : & Build , target : TargetSelection ) {
116
129
let mut cfg = new_cc_build ( build, target) ;
117
130
let config = build. config . target_config . get ( & target) ;
@@ -172,6 +185,8 @@ pub fn find_target(build: &Build, target: TargetSelection) {
172
185
}
173
186
}
174
187
188
+ /// Determines the default compiler for a given target and language when not explicitly
189
+ /// configured in `config.toml`.
175
190
fn default_compiler (
176
191
cfg : & mut cc:: Build ,
177
192
compiler : Language ,
@@ -248,6 +263,12 @@ fn default_compiler(
248
263
}
249
264
}
250
265
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.
251
272
pub ( crate ) fn ndk_compiler ( compiler : Language , triple : & str , ndk : & Path ) -> PathBuf {
252
273
let mut triple_iter = triple. split ( '-' ) ;
253
274
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
277
298
ndk. join ( "toolchains" ) . join ( "llvm" ) . join ( "prebuilt" ) . join ( host_tag) . join ( "bin" ) . join ( compiler)
278
299
}
279
300
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.
281
306
#[ derive( PartialEq ) ]
282
307
pub ( crate ) enum Language {
283
308
/// The compiler is targeting C.
@@ -287,15 +312,15 @@ pub(crate) enum Language {
287
312
}
288
313
289
314
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 .
291
316
fn gcc ( self ) -> & ' static str {
292
317
match self {
293
318
Language :: C => "gcc" ,
294
319
Language :: CPlusPlus => "g++" ,
295
320
}
296
321
}
297
322
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 .
299
324
fn clang ( self ) -> & ' static str {
300
325
match self {
301
326
Language :: C => "clang" ,
0 commit comments