launchbadge / sqlx

🧰 The Rust SQL Toolkit. An async, pure Rust SQL crate featuring compile-time checked queries without a DSL. Supports PostgreSQL, MySQL, and SQLite.
Apache License 2.0
12.36k stars 1.18k forks source link

Cross compile failed with OpenHarmony #3277

Closed richerfu closed 3 weeks ago

richerfu commented 3 weeks ago

Bug Description

Now i try to use sqlx with sqlite. when i try to build and i get some errors with sql-macro.

image

Looks like sqlx-macro try to build with sqlite-sys which is built with ohos. For proc-macro lib that always be built with host system. And then i get this error.

Any suggestions?

Minimal Reproduction

Use this guide to build it. https://doc.rust-lang.org/rustc/platform-support/openharmony.html

use napi_derive_ohos::napi;
use sqlx::SqlitePool;

#[napi]
pub async fn test_sqlite() {
    let pool = SqlitePool::connect(":memory:").await.unwrap();
    let mut conn = pool.acquire().await.unwrap();

    // Insert the task, then obtain the ID of this row
    let id = sqlx::query(
        r#"
INSERT INTO todos ( description )
VALUES ( ?1 )
      "#,
    )
    .execute(&mut *conn)
    .await
    .unwrap()
    .last_insert_rowid();
}

Before build it, should run this shell.

#!/bin/sh

export CC=$OHOS_NDK_HOME/native/llvm/bin/clang \
export CXX=$OHOS_NDK_HOME/native/llvm/bin/clang++ \
export AR=$OHOS_NDK_HOME/native/llvm/bin/llvm-ar \
export AS=$OHOS_NDK_HOME/native/llvm/bin/llvm-as \
export LD=$OHOS_NDK_HOME/native/llvm/bin/ld.lld \
export STRIP=$OHOS_NDK_HOME/native/llvm/bin/llvm-strip \
export RANLIB=$OHOS_NDK_HOME/native/llvm/bin/llvm-ranlib \
export OBJDUMP=$OHOS_NDK_HOME/native/llvm/bin/llvm-objdump \
export OBJCOPY=$OHOS_NDK_HOME/native/llvm/bin/llvm-objcopy \
export NM=$OHOS_NDK_HOME/native/llvm/bin/llvm-nm \
export CFLAGS="-target aarch64-linux-ohos --sysroot=${OHOS_NDK_HOME}/native/sysroot -D__MUSL__" \
export CXXFLAGS="-target aarch64-linux-ohos --sysroot=${OHOS_NDK_HOME}/native/sysroot -D__MUSL__" \

Info

richerfu commented 3 weeks ago

Looks i can't set CC directly which will cause proc-macro build failed.