environment.dart
1 /// This is copied from Cargokit (which is the official way to use it currently) 2 /// Details: https://fzyzcjy.github.io/flutter_rust_bridge/manual/integrate/builtin 3 4 import 'dart:io'; 5 6 extension on String { 7 String resolveSymlink() => File(this).resolveSymbolicLinksSync(); 8 } 9 10 class Environment { 11 /// Current build configuration (debug or release). 12 static String get configuration => 13 _getEnv("CARGOKIT_CONFIGURATION").toLowerCase(); 14 15 static bool get isDebug => configuration == 'debug'; 16 static bool get isRelease => configuration == 'release'; 17 18 /// Temporary directory where Rust build artifacts are placed. 19 static String get targetTempDir => _getEnv("CARGOKIT_TARGET_TEMP_DIR"); 20 21 /// Final output directory where the build artifacts are placed. 22 static String get outputDir => _getEnvPath('CARGOKIT_OUTPUT_DIR'); 23 24 /// Path to the crate manifest (containing Cargo.toml). 25 static String get manifestDir => _getEnvPath('CARGOKIT_MANIFEST_DIR'); 26 27 /// Directory inside root project. Not necessarily root folder. Symlinks are 28 /// not resolved on purpose. 29 static String get rootProjectDir => _getEnv('CARGOKIT_ROOT_PROJECT_DIR'); 30 31 // Pod 32 33 /// Platform name (macosx, iphoneos, iphonesimulator). 34 static String get darwinPlatformName => 35 _getEnv("CARGOKIT_DARWIN_PLATFORM_NAME"); 36 37 /// List of architectures to build for (arm64, armv7, x86_64). 38 static List<String> get darwinArchs => 39 _getEnv("CARGOKIT_DARWIN_ARCHS").split(' '); 40 41 // Gradle 42 static String get minSdkVersion => _getEnv("CARGOKIT_MIN_SDK_VERSION"); 43 static String get ndkVersion => _getEnv("CARGOKIT_NDK_VERSION"); 44 static String get sdkPath => _getEnvPath("CARGOKIT_SDK_DIR"); 45 static String get javaHome => _getEnvPath("CARGOKIT_JAVA_HOME"); 46 static List<String> get targetPlatforms => 47 _getEnv("CARGOKIT_TARGET_PLATFORMS").split(','); 48 49 // CMAKE 50 static String get targetPlatform => _getEnv("CARGOKIT_TARGET_PLATFORM"); 51 52 static String _getEnv(String key) { 53 final res = Platform.environment[key]; 54 if (res == null) { 55 throw Exception("Missing environment variable $key"); 56 } 57 return res; 58 } 59 60 static String _getEnvPath(String key) { 61 final res = _getEnv(key); 62 if (Directory(res).existsSync()) { 63 return res.resolveSymlink(); 64 } else { 65 return res; 66 } 67 } 68 }