mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-03 02:20:19 +08:00
fix(native): opt out napi-derive noop feature (#12686)
It would cause the napi-derive not work as expect in workspace level <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Refactor** - Improved internal handling and type definitions for document parsing, resulting in clearer and more maintainable data structures. - **Chores** - Introduced a new feature flag for mobile native builds, enabling conditional compilation for enhanced flexibility across Android and iOS. - Updated build scripts to support the new feature flag for both Android and iOS platforms. - Updated iOS app dependencies to newer versions, including Apollo iOS, ChidoriMenu, and swift-collections, and removed SQLite.swift. - **Tests** - Enhanced Rust linting and testing workflows to run selectively across workspace packages with the new feature flag enabled. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
@@ -151,7 +151,8 @@ jobs:
|
|||||||
- name: Clippy
|
- name: Clippy
|
||||||
run: |
|
run: |
|
||||||
rustup component add clippy
|
rustup component add clippy
|
||||||
cargo clippy --all-targets --all-features -- -D warnings
|
cargo clippy --workspace --exclude affine_server_native --all-targets --all-features -- -D warnings
|
||||||
|
cargo clippy -p affine_server_native --all-targets --all-features -- -D warnings
|
||||||
|
|
||||||
check-git-status:
|
check-git-status:
|
||||||
name: Check Git Status
|
name: Check Git Status
|
||||||
@@ -923,7 +924,7 @@ jobs:
|
|||||||
uses: taiki-e/install-action@nextest
|
uses: taiki-e/install-action@nextest
|
||||||
|
|
||||||
- name: Run tests
|
- name: Run tests
|
||||||
run: cargo nextest run --release --no-fail-fast
|
run: cargo nextest run --workspace --exclude affine_server_native --features use-as-lib --release --no-fail-fast
|
||||||
|
|
||||||
copilot-api-test:
|
copilot-api-test:
|
||||||
name: Server Copilot Api Test
|
name: Server Copilot Api Test
|
||||||
|
|||||||
Vendored
+11
-1
@@ -8,6 +8,11 @@ export const AFFINE_PRO_LICENSE_AES_KEY: string | undefined | null
|
|||||||
|
|
||||||
export const AFFINE_PRO_PUBLIC_KEY: string | undefined | null
|
export const AFFINE_PRO_PUBLIC_KEY: string | undefined | null
|
||||||
|
|
||||||
|
export interface Chunk {
|
||||||
|
index: number
|
||||||
|
content: string
|
||||||
|
}
|
||||||
|
|
||||||
export declare function fromModelName(modelName: string): Tokenizer | null
|
export declare function fromModelName(modelName: string): Tokenizer | null
|
||||||
|
|
||||||
export declare function getMime(input: Uint8Array): string
|
export declare function getMime(input: Uint8Array): string
|
||||||
@@ -22,6 +27,11 @@ export declare function mergeUpdatesInApplyWay(updates: Array<Buffer>): Buffer
|
|||||||
|
|
||||||
export declare function mintChallengeResponse(resource: string, bits?: number | undefined | null): Promise<string>
|
export declare function mintChallengeResponse(resource: string, bits?: number | undefined | null): Promise<string>
|
||||||
|
|
||||||
export declare function parseDoc(filePath: string, doc: Buffer): Promise<{ name: string, chunks: Array<{index: number, content: string}> }>
|
export interface ParsedDoc {
|
||||||
|
name: string
|
||||||
|
chunks: Array<Chunk>
|
||||||
|
}
|
||||||
|
|
||||||
|
export declare function parseDoc(filePath: string, doc: Buffer): Promise<ParsedDoc>
|
||||||
|
|
||||||
export declare function verifyChallengeResponse(response: string, bits: number, resource: string): Promise<boolean>
|
export declare function verifyChallengeResponse(response: string, bits: number, resource: string): Promise<boolean>
|
||||||
|
|||||||
@@ -1,10 +1,22 @@
|
|||||||
use affine_common::doc_loader::Doc;
|
use affine_common::doc_loader::Doc;
|
||||||
use napi::{
|
use napi::{
|
||||||
anyhow::anyhow,
|
anyhow::anyhow,
|
||||||
bindgen_prelude::{Array, AsyncTask, Buffer, Object},
|
bindgen_prelude::{AsyncTask, Buffer},
|
||||||
Env, Result, Task,
|
Env, Result, Task,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#[napi(object)]
|
||||||
|
pub struct Chunk {
|
||||||
|
pub index: i64,
|
||||||
|
pub content: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[napi(object)]
|
||||||
|
pub struct ParsedDoc {
|
||||||
|
pub name: String,
|
||||||
|
pub chunks: Vec<Chunk>,
|
||||||
|
}
|
||||||
|
|
||||||
pub struct Document {
|
pub struct Document {
|
||||||
inner: Doc,
|
inner: Doc,
|
||||||
}
|
}
|
||||||
@@ -14,21 +26,20 @@ impl Document {
|
|||||||
self.inner.name.clone()
|
self.inner.name.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn chunks(&self, env: &Env) -> Result<Array> {
|
fn chunks(&self) -> Vec<Chunk> {
|
||||||
let vec = self
|
self
|
||||||
.inner
|
.inner
|
||||||
.chunks
|
.chunks
|
||||||
.iter()
|
.iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.map(|(i, chunk)| {
|
.map(|(i, chunk)| {
|
||||||
let content = crate::utils::clean_content(&chunk.content);
|
let content = crate::utils::clean_content(&chunk.content);
|
||||||
let mut obj = Object::new(env)?;
|
Chunk {
|
||||||
obj.set("index", i as i64)?;
|
index: i as i64,
|
||||||
obj.set("content", content)?;
|
content,
|
||||||
Ok(obj)
|
}
|
||||||
})
|
})
|
||||||
.collect::<Result<Vec<Object>>>()?;
|
.collect::<Vec<Chunk>>()
|
||||||
Array::from_vec(env, vec)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,24 +51,22 @@ pub struct AsyncParseDocResponse {
|
|||||||
#[napi]
|
#[napi]
|
||||||
impl Task for AsyncParseDocResponse {
|
impl Task for AsyncParseDocResponse {
|
||||||
type Output = Document;
|
type Output = Document;
|
||||||
type JsValue = Object<'static>;
|
type JsValue = ParsedDoc;
|
||||||
|
|
||||||
fn compute(&mut self) -> Result<Self::Output> {
|
fn compute(&mut self) -> Result<Self::Output> {
|
||||||
let doc = Doc::new(&self.file_path, &self.doc).map_err(|e| anyhow!(e))?;
|
let doc = Doc::new(&self.file_path, &self.doc).map_err(|e| anyhow!(e))?;
|
||||||
Ok(Document { inner: doc })
|
Ok(Document { inner: doc })
|
||||||
}
|
}
|
||||||
|
|
||||||
fn resolve(&mut self, env: Env, doc: Document) -> Result<Self::JsValue> {
|
fn resolve(&mut self, _: Env, doc: Document) -> Result<Self::JsValue> {
|
||||||
let mut obj = Object::new(&env)?;
|
Ok(ParsedDoc {
|
||||||
obj.set("name", doc.name())?;
|
name: doc.name(),
|
||||||
obj.set("chunks", doc.chunks(&env)?)?;
|
chunks: doc.chunks(),
|
||||||
Ok(obj)
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[napi(
|
#[napi]
|
||||||
ts_return_type = "Promise<{ name: string, chunks: Array<{index: number, content: string}> }>"
|
|
||||||
)]
|
|
||||||
pub fn parse_doc(file_path: String, doc: Buffer) -> AsyncTask<AsyncParseDocResponse> {
|
pub fn parse_doc(file_path: String, doc: Buffer) -> AsyncTask<AsyncParseDocResponse> {
|
||||||
AsyncTask::new(AsyncParseDocResponse {
|
AsyncTask::new(AsyncParseDocResponse {
|
||||||
file_path,
|
file_path,
|
||||||
|
|||||||
@@ -136,6 +136,9 @@ dependencies {
|
|||||||
cargo {
|
cargo {
|
||||||
module = "../../../../mobile-native"
|
module = "../../../../mobile-native"
|
||||||
libname = "affine_mobile_native"
|
libname = "affine_mobile_native"
|
||||||
|
features {
|
||||||
|
defaultAnd("use-as-lib")
|
||||||
|
}
|
||||||
targets = ["arm64"]
|
targets = ["arm64"]
|
||||||
pythonCommand = "python3"
|
pythonCommand = "python3"
|
||||||
targetDirectory = "../../../../../../target"
|
targetDirectory = "../../../../../../target"
|
||||||
|
|||||||
+6
-15
@@ -5,8 +5,8 @@
|
|||||||
"kind" : "remoteSourceControl",
|
"kind" : "remoteSourceControl",
|
||||||
"location" : "https://github.com/apollographql/apollo-ios",
|
"location" : "https://github.com/apollographql/apollo-ios",
|
||||||
"state" : {
|
"state" : {
|
||||||
"revision" : "51e535dcf5439c01396d668a9598748ea86c7c1a",
|
"revision" : "39fea7617346c0731be25f61afd537e7032fb562",
|
||||||
"version" : "1.20.0"
|
"version" : "1.22.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -14,8 +14,8 @@
|
|||||||
"kind" : "remoteSourceControl",
|
"kind" : "remoteSourceControl",
|
||||||
"location" : "https://github.com/Lakr233/ChidoriMenu",
|
"location" : "https://github.com/Lakr233/ChidoriMenu",
|
||||||
"state" : {
|
"state" : {
|
||||||
"revision" : "ccd37f01cd4dcf4fb0889f263573d90d5c16e59b",
|
"revision" : "3bb4323fe0f7f8f435d15656c3eeffcbb7c9c605",
|
||||||
"version" : "2.4.3"
|
"version" : "3.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -27,15 +27,6 @@
|
|||||||
"version" : "0.16.0"
|
"version" : "0.16.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"identity" : "sqlite.swift",
|
|
||||||
"kind" : "remoteSourceControl",
|
|
||||||
"location" : "https://github.com/stephencelis/SQLite.swift.git",
|
|
||||||
"state" : {
|
|
||||||
"revision" : "a95fc6df17d108bd99210db5e8a9bac90fe984b8",
|
|
||||||
"version" : "0.15.3"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"identity" : "swift-cmark",
|
"identity" : "swift-cmark",
|
||||||
"kind" : "remoteSourceControl",
|
"kind" : "remoteSourceControl",
|
||||||
@@ -50,8 +41,8 @@
|
|||||||
"kind" : "remoteSourceControl",
|
"kind" : "remoteSourceControl",
|
||||||
"location" : "https://github.com/apple/swift-collections",
|
"location" : "https://github.com/apple/swift-collections",
|
||||||
"state" : {
|
"state" : {
|
||||||
"revision" : "671108c96644956dddcd89dd59c203dcdb36cec7",
|
"revision" : "c1805596154bb3a265fd91b8ac0c4433b4348fb0",
|
||||||
"version" : "1.1.4"
|
"version" : "1.2.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
+6
-6
@@ -5,8 +5,8 @@
|
|||||||
"kind" : "remoteSourceControl",
|
"kind" : "remoteSourceControl",
|
||||||
"location" : "https://github.com/apollographql/apollo-ios.git",
|
"location" : "https://github.com/apollographql/apollo-ios.git",
|
||||||
"state" : {
|
"state" : {
|
||||||
"revision" : "6ecc75281dab2fa231cb0d5fed3a3713826fecae",
|
"revision" : "39fea7617346c0731be25f61afd537e7032fb562",
|
||||||
"version" : "1.21.0"
|
"version" : "1.22.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -14,8 +14,8 @@
|
|||||||
"kind" : "remoteSourceControl",
|
"kind" : "remoteSourceControl",
|
||||||
"location" : "https://github.com/Lakr233/ChidoriMenu",
|
"location" : "https://github.com/Lakr233/ChidoriMenu",
|
||||||
"state" : {
|
"state" : {
|
||||||
"revision" : "ccd37f01cd4dcf4fb0889f263573d90d5c16e59b",
|
"revision" : "3bb4323fe0f7f8f435d15656c3eeffcbb7c9c605",
|
||||||
"version" : "2.4.3"
|
"version" : "3.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -41,8 +41,8 @@
|
|||||||
"kind" : "remoteSourceControl",
|
"kind" : "remoteSourceControl",
|
||||||
"location" : "https://github.com/apple/swift-collections",
|
"location" : "https://github.com/apple/swift-collections",
|
||||||
"state" : {
|
"state" : {
|
||||||
"revision" : "671108c96644956dddcd89dd59c203dcdb36cec7",
|
"revision" : "c1805596154bb3a265fd91b8ac0c4433b4348fb0",
|
||||||
"version" : "1.1.4"
|
"version" : "1.2.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -45,13 +45,13 @@ EXTERNAL SOURCES:
|
|||||||
:path: "../../../../../node_modules/capacitor-plugin-app-tracking-transparency"
|
:path: "../../../../../node_modules/capacitor-plugin-app-tracking-transparency"
|
||||||
|
|
||||||
SPEC CHECKSUMS:
|
SPEC CHECKSUMS:
|
||||||
Capacitor: 106e7a4205f4618d582b886a975657c61179138d
|
Capacitor: 03bc7cbdde6a629a8b910a9d7d78c3cc7ed09ea7
|
||||||
CapacitorApp: d63334c052278caf5d81585d80b21905c6f93f39
|
CapacitorApp: febecbb9582cb353aed037e18ec765141f880fe9
|
||||||
CapacitorBrowser: 081852cf532acf77b9d2953f3a88fe5b9711fb06
|
CapacitorBrowser: 6299776d496e968505464884d565992faa20444a
|
||||||
CapacitorCordova: 5967b9ba03915ef1d585469d6e31f31dc49be96f
|
CapacitorCordova: 5967b9ba03915ef1d585469d6e31f31dc49be96f
|
||||||
CapacitorHaptics: 70e47470fa1a6bd6338cd102552e3846b7f9a1b3
|
CapacitorHaptics: 1f1e17041f435d8ead9ff2a34edd592c6aa6a8d6
|
||||||
CapacitorKeyboard: 969647d0ca2e5c737d7300088e2517aa832434e2
|
CapacitorKeyboard: 09fd91dcde4f8a37313e7f11bde553ad1ed52036
|
||||||
CapacitorPluginAppTrackingTransparency: 2a2792623a5a72795f2e8f9ab3f1147573732fd8
|
CapacitorPluginAppTrackingTransparency: 92ae9c1cfb5cf477753db9269689332a686f675a
|
||||||
CryptoSwift: 967f37cea5a3294d9cce358f78861652155be483
|
CryptoSwift: 967f37cea5a3294d9cce358f78861652155be483
|
||||||
|
|
||||||
PODFILE CHECKSUM: 2c1e4be82121f2d9724ecf7e31dd14e165aeb082
|
PODFILE CHECKSUM: 2c1e4be82121f2d9724ecf7e31dd14e165aeb082
|
||||||
|
|||||||
@@ -47,20 +47,20 @@ for arch in $ARCHS; do
|
|||||||
|
|
||||||
# Intel iOS simulator
|
# Intel iOS simulator
|
||||||
export CFLAGS_x86_64_apple_ios="-target x86_64-apple-ios"
|
export CFLAGS_x86_64_apple_ios="-target x86_64-apple-ios"
|
||||||
$HOME/.cargo/bin/cargo rustc -p "${FFI_TARGET}" --lib --crate-type staticlib --$RELFLAG --target x86_64-apple-ios
|
$HOME/.cargo/bin/cargo rustc -p "${FFI_TARGET}" --lib --crate-type staticlib --$RELFLAG --target x86_64-apple-ios --features use-as-lib
|
||||||
;;
|
;;
|
||||||
|
|
||||||
arm64)
|
arm64)
|
||||||
if [ $IS_SIMULATOR -eq 0 ]; then
|
if [ $IS_SIMULATOR -eq 0 ]; then
|
||||||
# Hardware iOS targets
|
# Hardware iOS targets
|
||||||
$HOME/.cargo/bin/cargo rustc -p "${FFI_TARGET}" --lib --crate-type staticlib --$RELFLAG --target aarch64-apple-ios
|
$HOME/.cargo/bin/cargo rustc -p "${FFI_TARGET}" --lib --crate-type staticlib --$RELFLAG --target aarch64-apple-ios --features use-as-lib
|
||||||
cp $SRC_ROOT/../../../target/aarch64-apple-ios/${RELFLAG}/lib${FFI_TARGET}.a $SRCROOT/lib${FFI_TARGET}.a
|
cp $SRC_ROOT/../../../target/aarch64-apple-ios/${RELFLAG}/lib${FFI_TARGET}.a $SRCROOT/lib${FFI_TARGET}.a
|
||||||
else
|
else
|
||||||
# M1 iOS simulator
|
# M1 iOS simulator
|
||||||
$HOME/.cargo/bin/cargo rustc -p "${FFI_TARGET}" --lib --crate-type staticlib --$RELFLAG --target aarch64-apple-ios-sim
|
$HOME/.cargo/bin/cargo rustc -p "${FFI_TARGET}" --lib --crate-type staticlib --$RELFLAG --target aarch64-apple-ios-sim --features use-as-lib
|
||||||
cp $SRC_ROOT/../../../target/aarch64-apple-ios-sim/${RELFLAG}/lib${FFI_TARGET}.a $SRCROOT/lib${FFI_TARGET}.a
|
cp $SRC_ROOT/../../../target/aarch64-apple-ios-sim/${RELFLAG}/lib${FFI_TARGET}.a $SRCROOT/lib${FFI_TARGET}.a
|
||||||
fi
|
fi
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
$HOME/.cargo/bin/cargo run -p affine_mobile_native --bin uniffi-bindgen generate --library $SRCROOT/lib${FFI_TARGET}.a --language swift --out-dir $SRCROOT/../../ios/App/App/uniffi
|
$HOME/.cargo/bin/cargo run -p affine_mobile_native --features use-as-lib --bin uniffi-bindgen generate --library $SRCROOT/lib${FFI_TARGET}.a --language swift --out-dir $SRCROOT/../../ios/App/App/uniffi
|
||||||
|
|||||||
@@ -17,14 +17,14 @@ execSync(
|
|||||||
|
|
||||||
console.log('[*] rust...');
|
console.log('[*] rust...');
|
||||||
execSync(
|
execSync(
|
||||||
'cargo build -p affine_mobile_native --lib --release --target aarch64-apple-ios',
|
'cargo build -p affine_mobile_native --features use-as-lib --lib --release --target aarch64-apple-ios',
|
||||||
{
|
{
|
||||||
stdio: 'inherit',
|
stdio: 'inherit',
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
execSync(
|
execSync(
|
||||||
`cargo run -p affine_mobile_native --bin uniffi-bindgen generate \
|
`cargo run -p affine_mobile_native --features use-as-lib --bin uniffi-bindgen generate \
|
||||||
--library ${ProjectRoot}/target/aarch64-apple-ios/release/libaffine_mobile_native.a \
|
--library ${ProjectRoot}/target/aarch64-apple-ios/release/libaffine_mobile_native.a \
|
||||||
--language swift --out-dir ${PackageRoot}/App/App/uniffi`,
|
--language swift --out-dir ${PackageRoot}/App/App/uniffi`,
|
||||||
{ stdio: 'inherit' }
|
{ stdio: 'inherit' }
|
||||||
|
|||||||
@@ -11,9 +11,12 @@ crate-type = ["cdylib", "staticlib"]
|
|||||||
name = "uniffi-bindgen"
|
name = "uniffi-bindgen"
|
||||||
path = "uniffi-bindgen.rs"
|
path = "uniffi-bindgen.rs"
|
||||||
|
|
||||||
|
[features]
|
||||||
|
use-as-lib = ["affine_nbstore/use-as-lib"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
affine_common = { workspace = true }
|
affine_common = { workspace = true }
|
||||||
affine_nbstore = { workspace = true, features = ["use-as-lib"] }
|
affine_nbstore = { workspace = true }
|
||||||
anyhow = { workspace = true }
|
anyhow = { workspace = true }
|
||||||
base64-simd = { workspace = true }
|
base64-simd = { workspace = true }
|
||||||
chrono = { workspace = true }
|
chrono = { workspace = true }
|
||||||
|
|||||||
Reference in New Issue
Block a user