Skip to content

Commit

Permalink
Util cargo alias config and cargo-make to gen kotlin
Browse files Browse the repository at this point in the history
  • Loading branch information
Binlogo committed Jul 25, 2024
1 parent 01a712a commit b055ea3
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 15 deletions.
1 change: 1 addition & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
[alias]
xcode = ["bin", "cargo-xcode"]
make = ["bin", "cargo-make"]
4 changes: 0 additions & 4 deletions examples/simple_counter/.cargo/config.toml

This file was deleted.

17 changes: 6 additions & 11 deletions examples/simple_counter/Android/shared/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
1 change: 1 addition & 0 deletions examples/simple_counter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
5 changes: 5 additions & 0 deletions examples/simple_counter/shared/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -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"
36 changes: 36 additions & 0 deletions examples/simple_counter/shared/Makefile.toml
Original file line number Diff line number Diff line change
@@ -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"]

0 comments on commit b055ea3

Please sign in to comment.