2121#include < string.h>
2222#include < inttypes.h>
2323
24+ #if defined(__ANDROID__)
25+ #include < sys/system_properties.h>
26+ #endif
27+
2428using namespace swift ;
2529
2630namespace {
@@ -187,9 +191,31 @@ extern "C" char **_environ;
187191#endif
188192#endif
189193
194+ #if defined(__ANDROID__)
195+ // On Android, also try loading runtime debug env variables from system props.
196+ static void platformInitialize (void *context) {
197+ (void )context;
198+ char buffer[PROP_VALUE_MAX] = " " ;
199+ // Only system properties prefixed with "debug." can be set without root access.
200+ #define SYSPROP_PREFIX " debug.org.swift.runtime."
201+ #define VARIABLE (name, type, defaultValue, help ) \
202+ if (__system_property_get (SYSPROP_PREFIX #name, buffer)) { \
203+ swift::runtime::environment::name##_isSet_variable = true ; \
204+ swift::runtime::environment::name##_variable = \
205+ parse_##type (#name, buffer, defaultValue); \
206+ }
207+ #include " EnvironmentVariables.def"
208+ #undef VARIABLE
209+ }
210+ #else
211+ static void platformInitialize (void *context) {
212+ (void )context;
213+ }
214+ #endif
215+
190216#if !SWIFT_STDLIB_HAS_ENVIRON
191217void swift::runtime::environment::initialize (void *context) {
192- ( void ) context;
218+ platformInitialize ( context) ;
193219}
194220#elif defined(ENVIRON)
195221void swift::runtime::environment::initialize (void *context) {
@@ -242,6 +268,8 @@ void swift::runtime::environment::initialize(void *context) {
242268 }
243269 }
244270
271+ platformInitialize (context);
272+
245273 if (SWIFT_DEBUG_HELP_variable)
246274 printHelp (nullptr );
247275}
@@ -258,6 +286,8 @@ void swift::runtime::environment::initialize(void *context) {
258286 } while (0 );
259287#include " EnvironmentVariables.def"
260288
289+ platformInitialize (context);
290+
261291 // Print help if requested.
262292 if (parse_bool (" SWIFT_DEBUG_HELP" , getenv (" SWIFT_DEBUG_HELP" ), false ))
263293 printHelp (" Using getenv to read variables. Unknown SWIFT_DEBUG_ variables "
0 commit comments