From b055ea369904d27b806bcb27f66f3f45f10a44f7 Mon Sep 17 00:00:00 2001 From: Binlogo Date: Thu, 25 Jul 2024 09:04:08 +0800 Subject: [PATCH] Util cargo alias config and cargo-make to gen kotlin --- .cargo/config.toml | 1 + examples/simple_counter/.cargo/config.toml | 4 --- .../Android/shared/build.gradle | 17 ++++----- examples/simple_counter/Cargo.toml | 1 + .../simple_counter/shared/.cargo/config.toml | 5 +++ examples/simple_counter/shared/Makefile.toml | 36 +++++++++++++++++++ 6 files changed, 49 insertions(+), 15 deletions(-) delete mode 100644 examples/simple_counter/.cargo/config.toml create mode 100644 examples/simple_counter/shared/.cargo/config.toml create mode 100644 examples/simple_counter/shared/Makefile.toml diff --git a/.cargo/config.toml b/.cargo/config.toml index cd923acbd..ac29baebb 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,2 +1,3 @@ [alias] xcode = ["bin", "cargo-xcode"] +make = ["bin", "cargo-make"] diff --git a/examples/simple_counter/.cargo/config.toml b/examples/simple_counter/.cargo/config.toml deleted file mode 100644 index f96e108b0..000000000 --- a/examples/simple_counter/.cargo/config.toml +++ /dev/null @@ -1,4 +0,0 @@ -[alias] -uniffi-gen-swift = "run --bin uniffi-bindgen generate --library target/release/libshared.dylib --language swift --out-dir shared/generated/swift/SharedFFI" -uniffi-gen-java = "run --bin uniffi-bindgen generate --library target/release/libshared.dylib --language kotlin --out-dir shared/generated/java" -generate-types = "run --bin generate-types --features typegen" diff --git a/examples/simple_counter/Android/shared/build.gradle b/examples/simple_counter/Android/shared/build.gradle index 071dfaeeb..84e7d801b 100644 --- a/examples/simple_counter/Android/shared/build.gradle +++ b/examples/simple_counter/Android/shared/build.gradle @@ -84,26 +84,21 @@ afterEvaluate { tasks.register('bindGen', Exec) { def outDir = "${projectDir}/../../shared/generated/java" - workingDir "../../" + workingDir "../../shared" if (System.getProperty('os.name').toLowerCase().contains('windows')) { commandLine("cmd", "/c", - "cargo build -p shared && " + "target\\debug\\uniffi-bindgen generate --library target\\debug\\libshared.dylib " + "--language kotlin " + "--out-dir " + outDir.replace('/', '\\')) + "cargo make uniffi-gen-java") } else { commandLine("sh", "-c", - """\ - cargo build -p shared && \ - target/debug/uniffi-bindgen generate --library target/debug/libshared.dylib \ - --language kotlin \ - --out-dir $outDir - """) + "cargo make uniffi-gen-java") } } tasks.register('typesGen', Exec) { - workingDir "../../" + workingDir "../../shared" if (System.getProperty('os.name').toLowerCase().contains('windows')) { - commandLine("cmd", "/c", "cargo run --bin generate-types --features typegen") + commandLine("cmd", "/c", "cargo make generate-types") } else { - commandLine("sh", "-c", "cargo run --bin generate-types --features typegen") + commandLine("sh", "-c", "cargo make generate-types") } } diff --git a/examples/simple_counter/Cargo.toml b/examples/simple_counter/Cargo.toml index e0dc274b3..8663f33ad 100644 --- a/examples/simple_counter/Cargo.toml +++ b/examples/simple_counter/Cargo.toml @@ -19,3 +19,4 @@ uniffi = { git = "https://github.com/mozilla/uniffi-rs.git", branch = "main" } [workspace.metadata.bin] cargo-xcode = { version = "=1.7.0" } +cargo-make = { version = "=0.37.14" } diff --git a/examples/simple_counter/shared/.cargo/config.toml b/examples/simple_counter/shared/.cargo/config.toml new file mode 100644 index 000000000..5066635a0 --- /dev/null +++ b/examples/simple_counter/shared/.cargo/config.toml @@ -0,0 +1,5 @@ +[alias] +generate-types = "run --bin generate-types --features typegen" +uniffi-bindgen = "run --bin uniffi-bindgen" +uniffi-gen-swift = "uniffi-bindgen generate --language swift" +uniffi-gen-kotlin = "uniffi-bindgen generate --language kotlin" diff --git a/examples/simple_counter/shared/Makefile.toml b/examples/simple_counter/shared/Makefile.toml new file mode 100644 index 000000000..88f6ceb5e --- /dev/null +++ b/examples/simple_counter/shared/Makefile.toml @@ -0,0 +1,36 @@ +[env] +CARGO_MAKE_EXTEND_WORKSPACE_MAKEFILE = true + +[tasks.build] +command = "cargo" +args = ["build", "-p", "shared", "--release"] + +[tasks.uniffi-gen-swift] +command = "cargo" +args = [ + "uniffi-gen-swift", + "--library", + "${CARGO_MAKE_CRATE_TARGET_DIRECTORY}/release/libshared.dylib", + "--out-dir", + "generated/swift/SharedFFI", +] +dependencies = ["build"] + +[tasks.build-android] +command = "cargo" +args = ["build", "-p", "shared", "--target", "aarch64-linux-android"] + +[tasks.uniffi-gen-java] +command = "cargo" +args = [ + "uniffi-gen-kotlin", + "--library", + "${CARGO_MAKE_CRATE_TARGET_DIRECTORY}/aarch64-linux-android/debug/libshared.so", + "--out-dir", + "generated/java", +] +dependencies = ["build-android"] + +[tasks.generate-types] +command = "cargo" +args = ["generate-types"]