@@ -411,15 +411,57 @@ abstract class HookConfigImpl implements HookConfig {
411
411
412
412
final cCompilerJson =
413
413
config.getOptional <Map <String , Object ?>>(CCompilerConfigImpl .configKey);
414
- if (cCompilerJson == null ) return CCompilerConfigImpl ();
415
414
416
- final compiler = _parseCompiler (baseUri, cCompilerJson);
415
+ Uri ? archiver;
416
+ Uri ? compiler;
417
+ Uri ? linker;
418
+ Uri ? envScript;
419
+ List <String >? envScriptArgs;
420
+ if (cCompilerJson != null ) {
421
+ compiler = _parseCompiler (baseUri, cCompilerJson);
422
+ archiver = _parseArchiver (baseUri, cCompilerJson);
423
+ envScript = _parseEnvScript (baseUri, cCompilerJson, compiler);
424
+ envScriptArgs = _parseEnvScriptArgs (cCompilerJson);
425
+ linker = _parseLinker (baseUri, cCompilerJson);
426
+ }
427
+
428
+ // If the bundling tool didn't specify a C compiler we fallback to
429
+ // identifying the C compiler based on specific environment variables.
430
+ {
431
+ final env = Platform .environment;
432
+ String ? unparseKey (String key) => key.replaceAll ('.' , '__' ).toUpperCase ();
433
+ String ? lookup (String key) => env[unparseKey (key)];
434
+ Uri ? lookupUri (String key) {
435
+ final value = lookup (key);
436
+ return value != null ? Uri .file (value) : null ;
437
+ }
438
+
439
+ List <String >? lookupList (String key) {
440
+ final value = lookup (key);
441
+ if (value == null ) return null ;
442
+ final list = value
443
+ .split (' ' )
444
+ .map ((arg) => arg.trim ())
445
+ .where ((arg) => arg.isNotEmpty)
446
+ .toList ();
447
+ if (list.isEmpty) return null ;
448
+ return list;
449
+ }
450
+
451
+ archiver ?? = lookupUri (CCompilerConfigImpl .arConfigKeyFull);
452
+ compiler ?? = lookupUri (CCompilerConfigImpl .ccConfigKeyFull);
453
+ linker ?? = lookupUri (CCompilerConfigImpl .ldConfigKeyFull);
454
+ envScript ?? = lookupUri (CCompilerConfigImpl .envScriptConfigKeyFull);
455
+ envScriptArgs ?? =
456
+ lookupList (CCompilerConfigImpl .envScriptArgsConfigKeyFull);
457
+ }
458
+
417
459
return CCompilerConfigImpl (
418
- archiver: _parseArchiver (baseUri, cCompilerJson) ,
460
+ archiver: archiver ,
419
461
compiler: compiler,
420
- envScript: _parseEnvScript (baseUri, cCompilerJson, compiler) ,
421
- envScriptArgs: _parseEnvScriptArgs (cCompilerJson) ,
422
- linker: _parseLinker (baseUri, cCompilerJson) ,
462
+ envScript: envScript ,
463
+ envScriptArgs: envScriptArgs ,
464
+ linker: linker ,
423
465
);
424
466
}
425
467
0 commit comments