Kotlin Native,针对多个目标进行编译时出现问题(仅适用于 Linux 目标)
我在为 androidNativeX64、androidNativeArm64、linuxArm64、linuxX64 目标进行编译时遇到问题。我有一个相当复杂的设置(多模块 gradle 项目)。我有核心模块 sqlx4k 和...
我在针对 androidNativeX64、androidNativeArm64、linuxArm64、linuxX64 目标进行编译时遇到问题。
我有一个相当复杂的设置(多模块 gradle 项目)。
我有核心模块 sqlx4k
和 sqlx4k-mysql
, sqlx4k-postgres
3 个客户端模块 sqlx4k-sqlite
(我们称之为 impl 模块)。
每个模块都“包装”了一个 Rust 库,该库会创建一个静态库( .a
)
.
build-logic
multiplatform-convention
sqlx4k
rust_lib -> produces static lib libsqlx4k.a
src
sqlx4k-mysql
examples
rust_lib -> produces static lib libsqlx4k_mysql.a
src
sqlx4k-postgres
examples
rust_lib -> produces static lib libsqlx4k_postgres.a
src
sqlx4k-sqlite
examples
rust_lib -> produces static lib libsqlx4k_sqlite.a
src
在每个 impl 模块(例如 sqlx4k-mysql)中,rust 包都包含 sqlx4k/rust_lib
as 依赖项。一般来说, sqlx4k
(核心模块)包含 rust 和 kotlin 代码库的通用代码。
当然,每个 impl 模块都包含核心 kotlin 模块 sqlx4k
.
每个模块 .def
针对每个目标都有几个文件。以下是目标的示例 macosArm64
:
package = sqlx4k.impl
headers = sqlx4k_postgres.h
compilerOpts = -I./rust_lib/target
staticLibraries = libsqlx4k_postgres.a
libraryPaths = ./rust_lib/target/aarch64-apple-darwin/release
一般来说,在每个 impl 模块中,我只链接来自同一个模块的静态 rust 库(我不链接 libsqlx4k.a
),因为它已经打包在每个 impl 静态库中。
以下设置仅对 Linux(也包括 Android)目标失败。对于 Apple 目标,运行完全正常。
错误是:
> Task :sqlx4k-mysql:compileNativeMainKotlinMetadata FAILED
e: file:///Users/smyrgeorge/dev/projects/test/sqlx4k/sqlx4k-mysql/src/nativeMain/kotlin/io/github/smyrgeorge/sqlx4k/mysql/MySQL.kt:12:20 Unresolved reference 'sqlx4k_fetch_all'.
e: file:///Users/smyrgeorge/dev/projects/test/sqlx4k/sqlx4k-mysql/src/nativeMain/kotlin/io/github/smyrgeorge/sqlx4k/mysql/MySQL.kt:13:20 Unresolved reference 'sqlx4k_of'.
e: file:///Users/smyrgeorge/dev/projects/test/sqlx4k/sqlx4k-mysql/src/nativeMain/kotlin/io/github/smyrgeorge/sqlx4k/mysql/MySQL.kt:16:20 Unresolved reference 'sqlx4k_query'.
e: file:///Users/smyrgeorge/dev/projects/test/sqlx4k/sqlx4k-mysql/src/nativeMain/kotlin/io/github/smyrgeorge/sqlx4k/mysql/MySQL.kt:17:20 Unresolved reference 'sqlx4k_tx_begin'.
e: file:///Users/smyrgeorge/dev/projects/test/sqlx4k/sqlx4k-mysql/src/nativeMain/kotlin/io/github/smyrgeorge/sqlx4k/mysql/MySQL.kt:18:20 Unresolved reference 'sqlx4k_tx_commit'.
e: file:///Users/smyrgeorge/dev/projects/test/sqlx4k/sqlx4k-mysql/src/nativeMain/kotlin/io/github/smyrgeorge/sqlx4k/mysql/MySQL.kt:19:20 Unresolved reference 'sqlx4k_tx_fetch_all'.
e: file:///Users/smyrgeorge/dev/projects/test/sqlx4k/sqlx4k-mysql/src/nativeMain/kotlin/io/github/smyrgeorge/sqlx4k/mysql/MySQL.kt:20:20 Unresolved reference 'sqlx4k_tx_query'.
e: file:///Users/smyrgeorge/dev/projects/test/sqlx4k/sqlx4k-mysql/src/nativeMain/kotlin/io/github/smyrgeorge/sqlx4k/mysql/MySQL.kt:21:20 Unresolved reference 'sqlx4k_tx_rollback'.
e: file:///Users/smyrgeorge/dev/projects/test/sqlx4k/sqlx4k-mysql/src/nativeMain/kotlin/io/github/smyrgeorge/sqlx4k/mysql/MySQL.kt:34:9 Unresolved reference 'sqlx4k_of'.
e: file:///Users/smyrgeorge/dev/projects/test/sqlx4k/sqlx4k-mysql/src/nativeMain/kotlin/io/github/smyrgeorge/sqlx4k/mysql/MySQL.kt:48:21 Unresolved reference 'sqlx4k_query'.
e: file:///Users/smyrgeorge/dev/projects/test/sqlx4k/sqlx4k-mysql/src/nativeMain/kotlin/io/github/smyrgeorge/sqlx4k/mysql/MySQL.kt:52:21 Unresolved reference 'sqlx4k_fetch_all'.
e: file:///Users/smyrgeorge/dev/projects/test/sqlx4k/sqlx4k-mysql/src/nativeMain/kotlin/io/github/smyrgeorge/sqlx4k/mysql/MySQL.kt:56:30 Unresolved reference 'sqlx4k_tx_begin'.
e: file:///Users/smyrgeorge/dev/projects/test/sqlx4k/sqlx4k-mysql/src/nativeMain/kotlin/io/github/smyrgeorge/sqlx4k/mysql/MySQL.kt:65:29 Unresolved reference 'sqlx4k_tx_commit'.
e: file:///Users/smyrgeorge/dev/projects/test/sqlx4k/sqlx4k-mysql/src/nativeMain/kotlin/io/github/smyrgeorge/sqlx4k/mysql/MySQL.kt:71:29 Unresolved reference 'sqlx4k_tx_rollback'.
e: file:///Users/smyrgeorge/dev/projects/test/sqlx4k/sqlx4k-mysql/src/nativeMain/kotlin/io/github/smyrgeorge/sqlx4k/mysql/MySQL.kt:78:33 Unresolved reference 'sqlx4k_tx_query'.
e: file:///Users/smyrgeorge/dev/projects/test/sqlx4k/sqlx4k-mysql/src/nativeMain/kotlin/io/github/smyrgeorge/sqlx4k/mysql/MySQL.kt:86:29 Unresolved reference 'sqlx4k_tx_fetch_all'.
> Task :sqlx4k-sqlite:compileNativeMainKotlinMetadata FAILED
e: file:///Users/smyrgeorge/dev/projects/test/sqlx4k/sqlx4k-sqlite/src/nativeMain/kotlin/io/github/smyrgeorge/sqlx4k/sqlite/SQLite.kt:12:20 Unresolved reference 'sqlx4k_fetch_all'.
e: file:///Users/smyrgeorge/dev/projects/test/sqlx4k/sqlx4k-sqlite/src/nativeMain/kotlin/io/github/smyrgeorge/sqlx4k/sqlite/SQLite.kt:13:20 Unresolved reference 'sqlx4k_of'.
e: file:///Users/smyrgeorge/dev/projects/test/sqlx4k/sqlx4k-sqlite/src/nativeMain/kotlin/io/github/smyrgeorge/sqlx4k/sqlite/SQLite.kt:16:20 Unresolved reference 'sqlx4k_query'.
e: file:///Users/smyrgeorge/dev/projects/test/sqlx4k/sqlx4k-sqlite/src/nativeMain/kotlin/io/github/smyrgeorge/sqlx4k/sqlite/SQLite.kt:17:20 Unresolved reference 'sqlx4k_tx_begin'.
e: file:///Users/smyrgeorge/dev/projects/test/sqlx4k/sqlx4k-sqlite/src/nativeMain/kotlin/io/github/smyrgeorge/sqlx4k/sqlite/SQLite.kt:18:20 Unresolved reference 'sqlx4k_tx_commit'.
e: file:///Users/smyrgeorge/dev/projects/test/sqlx4k/sqlx4k-sqlite/src/nativeMain/kotlin/io/github/smyrgeorge/sqlx4k/sqlite/SQLite.kt:19:20 Unresolved reference 'sqlx4k_tx_fetch_all'.
e: file:///Users/smyrgeorge/dev/projects/test/sqlx4k/sqlx4k-sqlite/src/nativeMain/kotlin/io/github/smyrgeorge/sqlx4k/sqlite/SQLite.kt:20:20 Unresolved reference 'sqlx4k_tx_query'.
e: file:///Users/smyrgeorge/dev/projects/test/sqlx4k/sqlx4k-sqlite/src/nativeMain/kotlin/io/github/smyrgeorge/sqlx4k/sqlite/SQLite.kt:21:20 Unresolved reference 'sqlx4k_tx_rollback'.
e: file:///Users/smyrgeorge/dev/projects/test/sqlx4k/sqlx4k-sqlite/src/nativeMain/kotlin/io/github/smyrgeorge/sqlx4k/sqlite/SQLite.kt:30:9 Unresolved reference 'sqlx4k_of'.
e: file:///Users/smyrgeorge/dev/projects/test/sqlx4k/sqlx4k-sqlite/src/nativeMain/kotlin/io/github/smyrgeorge/sqlx4k/sqlite/SQLite.kt:40:21 Unresolved reference 'sqlx4k_query'.
e: file:///Users/smyrgeorge/dev/projects/test/sqlx4k/sqlx4k-sqlite/src/nativeMain/kotlin/io/github/smyrgeorge/sqlx4k/sqlite/SQLite.kt:44:21 Unresolved reference 'sqlx4k_fetch_all'.
e: file:///Users/smyrgeorge/dev/projects/test/sqlx4k/sqlx4k-sqlite/src/nativeMain/kotlin/io/github/smyrgeorge/sqlx4k/sqlite/SQLite.kt:48:30 Unresolved reference 'sqlx4k_tx_begin'.
e: file:///Users/smyrgeorge/dev/projects/test/sqlx4k/sqlx4k-sqlite/src/nativeMain/kotlin/io/github/smyrgeorge/sqlx4k/sqlite/SQLite.kt:57:29 Unresolved reference 'sqlx4k_tx_commit'.
e: file:///Users/smyrgeorge/dev/projects/test/sqlx4k/sqlx4k-sqlite/src/nativeMain/kotlin/io/github/smyrgeorge/sqlx4k/sqlite/SQLite.kt:63:29 Unresolved reference 'sqlx4k_tx_rollback'.
e: file:///Users/smyrgeorge/dev/projects/test/sqlx4k/sqlx4k-sqlite/src/nativeMain/kotlin/io/github/smyrgeorge/sqlx4k/sqlite/SQLite.kt:70:33 Unresolved reference 'sqlx4k_tx_query'.
e: file:///Users/smyrgeorge/dev/projects/test/sqlx4k/sqlx4k-sqlite/src/nativeMain/kotlin/io/github/smyrgeorge/sqlx4k/sqlite/SQLite.kt:78:29 Unresolved reference 'sqlx4k_tx_fetch_all'.
> Task :sqlx4k-postgres:compileNativeMainKotlinMetadata FAILED
e: file:///Users/smyrgeorge/dev/projects/test/sqlx4k/sqlx4k-postgres/src/nativeMain/kotlin/io/github/smyrgeorge/sqlx4k/postgres/PostgreSQL.kt:26:20 Unresolved reference 'sqlx4k_fetch_all'.
e: file:///Users/smyrgeorge/dev/projects/test/sqlx4k/sqlx4k-postgres/src/nativeMain/kotlin/io/github/smyrgeorge/sqlx4k/postgres/PostgreSQL.kt:28:20 Unresolved reference 'sqlx4k_listen'.
e: file:///Users/smyrgeorge/dev/projects/test/sqlx4k/sqlx4k-postgres/src/nativeMain/kotlin/io/github/smyrgeorge/sqlx4k/postgres/PostgreSQL.kt:29:20 Unresolved reference 'sqlx4k_of'.
e: file:///Users/smyrgeorge/dev/projects/test/sqlx4k/sqlx4k-postgres/src/nativeMain/kotlin/io/github/smyrgeorge/sqlx4k/postgres/PostgreSQL.kt:32:20 Unresolved reference 'sqlx4k_query'.
e: file:///Users/smyrgeorge/dev/projects/test/sqlx4k/sqlx4k-postgres/src/nativeMain/kotlin/io/github/smyrgeorge/sqlx4k/postgres/PostgreSQL.kt:33:20 Unresolved reference 'sqlx4k_tx_begin'.
e: file:///Users/smyrgeorge/dev/projects/test/sqlx4k/sqlx4k-postgres/src/nativeMain/kotlin/io/github/smyrgeorge/sqlx4k/postgres/PostgreSQL.kt:34:20 Unresolved reference 'sqlx4k_tx_commit'.
e: file:///Users/smyrgeorge/dev/projects/test/sqlx4k/sqlx4k-postgres/src/nativeMain/kotlin/io/github/smyrgeorge/sqlx4k/postgres/PostgreSQL.kt:35:20 Unresolved reference 'sqlx4k_tx_fetch_all'.
e: file:///Users/smyrgeorge/dev/projects/test/sqlx4k/sqlx4k-postgres/src/nativeMain/kotlin/io/github/smyrgeorge/sqlx4k/postgres/PostgreSQL.kt:36:20 Unresolved reference 'sqlx4k_tx_query'.
e: file:///Users/smyrgeorge/dev/projects/test/sqlx4k/sqlx4k-postgres/src/nativeMain/kotlin/io/github/smyrgeorge/sqlx4k/postgres/PostgreSQL.kt:37:20 Unresolved reference 'sqlx4k_tx_rollback'.
e: file:///Users/smyrgeorge/dev/projects/test/sqlx4k/sqlx4k-postgres/src/nativeMain/kotlin/io/github/smyrgeorge/sqlx4k/postgres/PostgreSQL.kt:51:9 Unresolved reference 'sqlx4k_of'.
e: file:///Users/smyrgeorge/dev/projects/test/sqlx4k/sqlx4k-postgres/src/nativeMain/kotlin/io/github/smyrgeorge/sqlx4k/postgres/PostgreSQL.kt:65:21 Unresolved reference 'sqlx4k_query'.
e: file:///Users/smyrgeorge/dev/projects/test/sqlx4k/sqlx4k-postgres/src/nativeMain/kotlin/io/github/smyrgeorge/sqlx4k/postgres/PostgreSQL.kt:69:21 Unresolved reference 'sqlx4k_fetch_all'.
e: file:///Users/smyrgeorge/dev/projects/test/sqlx4k/sqlx4k-postgres/src/nativeMain/kotlin/io/github/smyrgeorge/sqlx4k/postgres/PostgreSQL.kt:73:30 Unresolved reference 'sqlx4k_tx_begin'.
e: file:///Users/smyrgeorge/dev/projects/test/sqlx4k/sqlx4k-postgres/src/nativeMain/kotlin/io/github/smyrgeorge/sqlx4k/postgres/PostgreSQL.kt:96:13 Unresolved reference 'sqlx4k_listen'.
e: file:///Users/smyrgeorge/dev/projects/test/sqlx4k/sqlx4k-postgres/src/nativeMain/kotlin/io/github/smyrgeorge/sqlx4k/postgres/PostgreSQL.kt:121:29 Unresolved reference 'sqlx4k_tx_commit'.
e: file:///Users/smyrgeorge/dev/projects/test/sqlx4k/sqlx4k-postgres/src/nativeMain/kotlin/io/github/smyrgeorge/sqlx4k/postgres/PostgreSQL.kt:127:29 Unresolved reference 'sqlx4k_tx_rollback'.
e: file:///Users/smyrgeorge/dev/projects/test/sqlx4k/sqlx4k-postgres/src/nativeMain/kotlin/io/github/smyrgeorge/sqlx4k/postgres/PostgreSQL.kt:134:33 Unresolved reference 'sqlx4k_tx_query'.
e: file:///Users/smyrgeorge/dev/projects/test/sqlx4k/sqlx4k-postgres/src/nativeMain/kotlin/io/github/smyrgeorge/sqlx4k/postgres/PostgreSQL.kt:142:29 Unresolved reference 'sqlx4k_tx_fetch_all'.
我认为这很奇怪。因为这些符号是每个 impl 模块创建的绑定。
完整项目可以在这里找到: https://github.com/smyrgeorge/sqlx4k
更新:
我刚刚看到如果我跑
./gradlew clean :sqlx4k-sqlite:build -Ptargets=linuxArm64
完美编译 linuxArm64
而构建
但是,如果我运行:
./gradlew clean :sqlx4k-sqlite:build -Ptargets=linuxArm64,linuxX64
这将构建 linuxArm64
并 linuxX64
失败并出现上述错误。
错误出现在 :sqlx4k-sqlite:compileNativeMainKotlinMetadata
任务上。可能在编译过程中写入了公共文件,由于是并行发生的,因此失败。虽然对于苹果目标来说没有问题。
下载声明: 本站所有软件和资料均为软件作者提供或网友推荐发布而来,仅供学习和研究使用,不得用于任何商业用途。如本站不慎侵犯你的版权请联系我,我将及时处理,并撤下相关内容!