Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
[alias]
xtask = "run --package xtask --"

# To enable sccache for cross-target compilation caching (recommended for
# Android multi-ABI builds), set RUSTC_WRAPPER=sccache in your environment.
# Install: cargo install sccache (or via package manager)
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ members = ["razemify-core", "razemify-cli", "razemify-wasm", "xtask", "flutter_r
resolver = "2"

[profile.release]
opt-level = "z"
lto = true
codegen-units = 1
strip = true
opt-level = "s" # Nearly as small as "z" but compiles faster
lto = "thin" # ~95% of fat LTO benefit at 3-5x faster link time
codegen-units = 16 # Enables parallel codegen within a single cargo build
strip = true # Strip debug symbols from release binaries
36 changes: 32 additions & 4 deletions flutter_razemify/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,44 @@ def rustTargets = [

def rustBuildTasks = rustTargets.collect { target ->
tasks.register(target.task, Exec) {
def profile = project.ext.isReleaseBuild ? "release" : "debug"
def ndkDir = android.ndkDirectory
def toolchainBin = file("${ndkDir}/toolchains/llvm/prebuilt/${ndkHost}/bin")
def linker = file("${toolchainBin}/${target.triple}${android.defaultConfig.minSdk}-clang")
def cargoHome = System.getenv("CARGO_HOME") ?: "${System.getProperty("user.home")}/.cargo"

// Declare inputs and outputs so Gradle can skip unchanged Rust builds.
inputs.dir("${projectDir}/../rust")
inputs.dir("${projectDir}/../../razemify-core/src")
Comment thread
pawelchcki marked this conversation as resolved.
Resolved
inputs.file("${projectDir}/../../razemify-core/Cargo.toml")
inputs.file("${projectDir}/../../Cargo.toml")
inputs.file("${projectDir}/../../Cargo.lock")
inputs.files(fileTree("${projectDir}/../..") {
include ".cargo/config", ".cargo/config.toml", "rust-toolchain", "rust-toolchain.toml"
})
inputs.files(fileTree(cargoHome) {
include "config", "config.toml"
})
inputs.file(linker).optional()
inputs.file(file("${toolchainBin}/llvm-ar")).optional()
inputs.property("cargoVersion", providers.exec {
commandLine "cargo", "--version"
}.standardOutput.asText)
inputs.property("rustcVersion", providers.exec {
commandLine "rustc", "--version"
}.standardOutput.asText)
inputs.property("rustFlags", providers.environmentVariable("RUSTFLAGS").orElse(""))
inputs.property("encodedRustFlags", providers.environmentVariable("CARGO_ENCODED_RUSTFLAGS").orElse(""))
inputs.property("rustupToolchain", providers.environmentVariable("RUSTUP_TOOLCHAIN").orElse(""))
inputs.property("profile", profile)
Comment thread
pawelchcki marked this conversation as resolved.
Resolved
outputs.file("${projectDir}/src/main/jniLibs/${target.abi}/libflutter_razemify.so")

onlyIf {
!project.ext.rustLibrariesProvidedByBazel &&
(!target.releaseOnly || project.ext.isReleaseBuild)
}

doFirst {
def ndkDir = android.ndkDirectory
def toolchainBin = file("${ndkDir}/toolchains/llvm/prebuilt/${ndkHost}/bin")
def linker = file("${toolchainBin}/${target.triple}${android.defaultConfig.minSdk}-clang")
if (!linker.exists()) {
throw new GradleException("Android NDK linker not found: ${linker}")
}
Expand All @@ -140,7 +169,6 @@ def rustBuildTasks = rustTargets.collect { target ->
}

doLast {
def profile = project.ext.isReleaseBuild ? "release" : "debug"
def rustLib = file("${projectDir}/../../target/${target.triple}/${profile}/libflutter_razemify.so")
if (!rustLib.exists() || rustLib.length() < 1024) {
throw new GradleException("Rust build did not produce a valid library: ${rustLib}")
Expand Down
1 change: 1 addition & 0 deletions flutter_razemify/example/android/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
org.gradle.jvmargs=-Xmx4G -XX:MaxMetaspaceSize=2G -XX:+HeapDumpOnOutOfMemoryError
android.useAndroidX=true
android.enableJetifier=true
org.gradle.parallel=true
Comment thread
pawelchcki marked this conversation as resolved.
Resolved
Loading