mirror of
https://github.com/immich-app/immich.git
synced 2026-10-12 02:16:40 +00:00
chore(mobile): rename the native core crates and package (#31986)
This commit is contained in:
@@ -113,7 +113,7 @@ jobs:
|
||||
~/.cargo/bin
|
||||
~/.cargo/registry
|
||||
~/.cargo/git
|
||||
key: build-mobile-rust-${{ runner.os }}-${{ hashFiles('native/crates/immich_core_ffi/rust-toolchain.toml', 'native/Cargo.lock') }}
|
||||
key: build-mobile-rust-${{ runner.os }}-${{ hashFiles('native/crates/native_core_ffi/rust-toolchain.toml', 'native/Cargo.lock') }}
|
||||
restore-keys: |
|
||||
build-mobile-rust-${{ runner.os }}-
|
||||
|
||||
@@ -261,7 +261,7 @@ jobs:
|
||||
~/.cargo/bin
|
||||
~/.cargo/registry
|
||||
~/.cargo/git
|
||||
key: build-mobile-rust-${{ runner.os }}-${{ hashFiles('native/crates/immich_core_ffi/rust-toolchain.toml', 'native/Cargo.lock') }}
|
||||
key: build-mobile-rust-${{ runner.os }}-${{ hashFiles('native/crates/native_core_ffi/rust-toolchain.toml', 'native/Cargo.lock') }}
|
||||
restore-keys: |
|
||||
build-mobile-rust-${{ runner.os }}-
|
||||
|
||||
|
||||
@@ -107,7 +107,7 @@ jobs:
|
||||
~/.cargo/registry
|
||||
~/.cargo/git
|
||||
native/target
|
||||
key: native-rust-${{ runner.os }}-${{ hashFiles('native/crates/immich_core_ffi/rust-toolchain.toml', 'native/mise.lock', 'native/Cargo.lock') }}
|
||||
key: native-rust-${{ runner.os }}-${{ hashFiles('native/crates/native_core_ffi/rust-toolchain.toml', 'native/mise.lock', 'native/Cargo.lock') }}
|
||||
restore-keys: |
|
||||
native-rust-${{ runner.os }}-
|
||||
|
||||
@@ -686,7 +686,7 @@ jobs:
|
||||
~/.cargo/bin
|
||||
~/.cargo/registry
|
||||
~/.cargo/git
|
||||
key: mobile-rust-${{ runner.os }}-${{ hashFiles('native/crates/immich_core_ffi/rust-toolchain.toml', 'mobile/mise.lock', 'native/Cargo.lock') }}
|
||||
key: mobile-rust-${{ runner.os }}-${{ hashFiles('native/crates/native_core_ffi/rust-toolchain.toml', 'mobile/mise.lock', 'native/Cargo.lock') }}
|
||||
restore-keys: |
|
||||
mobile-rust-${{ runner.os }}-
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ const val INITIAL_BUFFER_SIZE = 32 * 1024
|
||||
|
||||
object NativeBuffer {
|
||||
init {
|
||||
System.loadLibrary("immich_core_ffi")
|
||||
System.loadLibrary("native_core_ffi")
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
|
||||
@@ -4,7 +4,7 @@ import android.graphics.Bitmap
|
||||
|
||||
object NativeImage {
|
||||
init {
|
||||
System.loadLibrary("immich_core_ffi")
|
||||
System.loadLibrary("native_core_ffi")
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -2,7 +2,7 @@ package app.alextran.immich.images
|
||||
|
||||
object ThumbHash {
|
||||
init {
|
||||
System.loadLibrary("immich_core_ffi")
|
||||
System.loadLibrary("native_core_ffi")
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:immich_native_core/immich_native_core.dart';
|
||||
import 'package:integration_test/integration_test.dart';
|
||||
import 'package:native_core/native_core.dart';
|
||||
|
||||
void main() {
|
||||
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import Foundation
|
||||
|
||||
enum NativeCore {
|
||||
private static let library = dlopen("@rpath/immich_core_ffi.framework/immich_core_ffi", RTLD_NOW)
|
||||
private static let library = dlopen("@rpath/native_core_ffi.framework/native_core_ffi", RTLD_NOW)
|
||||
|
||||
private static func symbol<T>(_ name: String, as type: T.Type) -> T? {
|
||||
guard let library, let symbol = dlsym(library, name) else { return nil }
|
||||
return unsafeBitCast(symbol, to: type)
|
||||
}
|
||||
|
||||
private static let coreThumbhash = symbol("immich_core_thumbhash", as: ImmichCoreThumbhashFn.self)
|
||||
private static let coreThumbhash = symbol("native_core_thumbhash", as: NativeCoreThumbhashFn.self)
|
||||
|
||||
static func thumbhash(_ hash: Data) -> (width: Int, height: Int, pointer: UnsafeMutableRawPointer)? {
|
||||
guard let coreThumbhash else { return nil }
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#import "GeneratedPluginRegistrant.h"
|
||||
#include "../../../native/crates/immich_core_ffi/include/immich_core.h"
|
||||
#include "../../../native/crates/native_core_ffi/include/native_core.h"
|
||||
|
||||
// The function pointer type comes from the declaration, so nothing is retyped here.
|
||||
typedef __typeof__(&immich_core_thumbhash) ImmichCoreThumbhashFn;
|
||||
typedef __typeof__(&native_core_thumbhash) NativeCoreThumbhashFn;
|
||||
|
||||
+2
-2
@@ -85,9 +85,9 @@ run = "dart run build_runner watch"
|
||||
|
||||
[tasks."codegen:native"]
|
||||
description = "Generate the C header and the ffigen bindings for the native core"
|
||||
dir = "../native/immich_native_core"
|
||||
dir = "../native/native_core"
|
||||
run = [
|
||||
"cargo build -p immich_core_ffi",
|
||||
"cargo build -p native_core_ffi",
|
||||
"flutter pub get",
|
||||
"dart run ffigen --config ffigen.yaml",
|
||||
]
|
||||
|
||||
+7
-7
@@ -928,13 +928,6 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.2.2"
|
||||
immich_native_core:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
path: "../native/immich_native_core"
|
||||
relative: true
|
||||
source: path
|
||||
version: "0.0.0"
|
||||
immich_ui:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
@@ -1139,6 +1132,13 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.0.5"
|
||||
native_core:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
path: "../native/native_core"
|
||||
relative: true
|
||||
source: path
|
||||
version: "0.0.0"
|
||||
native_toolchain_c:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
||||
+2
-2
@@ -39,8 +39,8 @@ dependencies:
|
||||
hooks_riverpod: ^2.6.1
|
||||
http: ^1.6.0
|
||||
image_picker: ^1.2.3
|
||||
immich_native_core:
|
||||
path: ../native/immich_native_core
|
||||
native_core:
|
||||
path: ../native/native_core
|
||||
immich_ui:
|
||||
path: './packages/ui'
|
||||
intl: ^0.20.2
|
||||
|
||||
+2
-2
@@ -1,3 +1,3 @@
|
||||
/target
|
||||
/crates/immich_core_ffi/include/immich_core.h
|
||||
/immich_native_core/lib/src/bindings.g.dart
|
||||
/crates/native_core_ffi/include/native_core.h
|
||||
/native_core/lib/src/bindings.g.dart
|
||||
|
||||
Generated
+14
-14
@@ -93,20 +93,6 @@ version = "0.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
|
||||
|
||||
[[package]]
|
||||
name = "immich_core"
|
||||
version = "0.1.0"
|
||||
|
||||
[[package]]
|
||||
name = "immich_core_ffi"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"cbindgen",
|
||||
"immich_core",
|
||||
"jni",
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "indexmap"
|
||||
version = "2.14.1"
|
||||
@@ -196,6 +182,20 @@ version = "2.8.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98"
|
||||
|
||||
[[package]]
|
||||
name = "native_core"
|
||||
version = "0.1.0"
|
||||
|
||||
[[package]]
|
||||
name = "native_core_ffi"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"cbindgen",
|
||||
"jni",
|
||||
"libc",
|
||||
"native_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "once_cell"
|
||||
version = "1.21.4"
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
[workspace]
|
||||
resolver = "3"
|
||||
members = ["crates/immich_core", "crates/immich_core_ffi"]
|
||||
members = ["crates/native_core", "crates/native_core_ffi"]
|
||||
|
||||
[workspace.package]
|
||||
version = "0.1.0"
|
||||
|
||||
+4
-4
@@ -1,13 +1,13 @@
|
||||
# Native core
|
||||
|
||||
Rust code that ships inside the mobile app. Flutter compiles it from source through the
|
||||
`immich_native_core` build hook, so building the app needs a Rust toolchain: `mise install`
|
||||
`native_core` build hook, so building the app needs a Rust toolchain: `mise install`
|
||||
in `mobile/` sets one up, otherwise install [rustup](https://rustup.rs) once and the build
|
||||
fetches the pinned toolchain itself.
|
||||
|
||||
- `crates/immich_core`: the shared logic
|
||||
- `crates/immich_core_ffi`: the C ABI, cbindgen writes `include/immich_core.h`
|
||||
- `immich_native_core`: Flutter package with the build hook and the ffigen bindings
|
||||
- `crates/native_core`: the shared logic
|
||||
- `crates/native_core_ffi`: the C ABI, cbindgen writes `include/native_core.h`
|
||||
- `native_core`: Flutter package with the build hook and the ffigen bindings
|
||||
(`NOTICES` carries the licenses of the crates compiled into the core, update it with the dependencies)
|
||||
|
||||
`mise run build`, `test`, `lint`, and `fmt`. The header and the Dart bindings come from `mise run //mobile:codegen:native`.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
[package]
|
||||
name = "immich_core"
|
||||
name = "native_core"
|
||||
version.workspace = true
|
||||
edition.workspace = true
|
||||
license.workspace = true
|
||||
@@ -2,6 +2,6 @@ pub mod convert;
|
||||
pub mod rotate;
|
||||
pub mod thumbhash;
|
||||
|
||||
pub fn core_version() -> &'static str {
|
||||
pub fn version() -> &'static str {
|
||||
env!("CARGO_PKG_VERSION")
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
use immich_core::convert::convert_1010102;
|
||||
use native_core::convert::convert_1010102;
|
||||
|
||||
#[test]
|
||||
fn channels_and_alpha() {
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
use immich_core::rotate::{Orientation, rotate};
|
||||
use native_core::rotate::{Orientation, rotate};
|
||||
|
||||
#[test]
|
||||
fn exif_orientations() {
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
use immich_core::thumbhash::decode;
|
||||
use native_core::thumbhash::decode;
|
||||
|
||||
// Expected pixels come from the old Swift decoder patched to round like the Java did (it truncated),
|
||||
// taken at pixels whose values sit well away from a rounding boundary, so the check is exact on any libm.
|
||||
@@ -1,16 +1,16 @@
|
||||
[package]
|
||||
name = "immich_core_ffi"
|
||||
name = "native_core_ffi"
|
||||
version.workspace = true
|
||||
edition.workspace = true
|
||||
license.workspace = true
|
||||
|
||||
# native_toolchain_rust wants the explicit name and both crate types.
|
||||
[lib]
|
||||
name = "immich_core_ffi"
|
||||
name = "native_core_ffi"
|
||||
crate-type = ["cdylib", "staticlib"]
|
||||
|
||||
[dependencies]
|
||||
immich_core = { path = "../immich_core" }
|
||||
native_core = { path = "../native_core" }
|
||||
libc = { workspace = true }
|
||||
|
||||
[target.'cfg(target_os = "android")'.dependencies]
|
||||
@@ -8,5 +8,5 @@ fn main() {
|
||||
let crate_dir = std::env::var("CARGO_MANIFEST_DIR").unwrap();
|
||||
cbindgen::generate(&crate_dir)
|
||||
.unwrap_or_else(|e| panic!("cbindgen failed: {e}"))
|
||||
.write_to_file(Path::new(&crate_dir).join("include/immich_core.h"));
|
||||
.write_to_file(Path::new(&crate_dir).join("include/native_core.h"));
|
||||
}
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
use immich_core::convert::convert_1010102;
|
||||
use jni::EnvUnowned;
|
||||
use jni::objects::{JClass, JIntArray, JObject};
|
||||
use jni::sys::jlong;
|
||||
use native_core::convert::convert_1010102;
|
||||
|
||||
use super::bitmap::{self, FORMAT_RGBA_1010102};
|
||||
|
||||
@@ -13,11 +13,11 @@ mod convert;
|
||||
mod rotate;
|
||||
mod thumbhash;
|
||||
|
||||
/// Returns the core version as a C string. Free it with `immich_core_free_string`.
|
||||
/// Returns the core version as a C string. Free it with `native_core_free_string`.
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn immich_core_version() -> *mut c_char {
|
||||
pub extern "C" fn native_core_version() -> *mut c_char {
|
||||
guard(ptr::null_mut(), || {
|
||||
match CString::new(immich_core::core_version()) {
|
||||
match CString::new(native_core::version()) {
|
||||
Ok(s) => s.into_raw(),
|
||||
Err(_) => ptr::null_mut(),
|
||||
}
|
||||
@@ -29,7 +29,7 @@ pub extern "C" fn immich_core_version() -> *mut c_char {
|
||||
/// # Safety
|
||||
/// `ptr` must come from this library and must not be freed twice.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn immich_core_free_string(ptr: *mut c_char) {
|
||||
pub unsafe extern "C" fn native_core_free_string(ptr: *mut c_char) {
|
||||
if ptr.is_null() {
|
||||
return;
|
||||
}
|
||||
@@ -50,18 +50,18 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn version_roundtrips() {
|
||||
let p = immich_core_version();
|
||||
let p = native_core_version();
|
||||
assert!(!p.is_null());
|
||||
// SAFETY: `p` is a C string from this library.
|
||||
let s = unsafe { CStr::from_ptr(p) }.to_str().unwrap();
|
||||
assert_eq!(s, immich_core::core_version());
|
||||
assert_eq!(s, native_core::version());
|
||||
// SAFETY: `p` is freed exactly once.
|
||||
unsafe { immich_core_free_string(p) };
|
||||
unsafe { native_core_free_string(p) };
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn free_null_is_noop() {
|
||||
// SAFETY: null is allowed by the contract.
|
||||
unsafe { immich_core_free_string(ptr::null_mut()) };
|
||||
unsafe { native_core_free_string(ptr::null_mut()) };
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
use immich_core::rotate::{Orientation, rotate};
|
||||
use jni::EnvUnowned;
|
||||
use jni::objects::{JClass, JIntArray, JObject};
|
||||
use jni::sys::{jint, jlong};
|
||||
use native_core::rotate::{Orientation, rotate};
|
||||
|
||||
use super::bitmap::{self, FORMAT_RGBA_8888};
|
||||
|
||||
+3
-3
@@ -2,7 +2,6 @@ use std::{ptr, slice};
|
||||
|
||||
use libc::size_t;
|
||||
|
||||
use immich_core::thumbhash;
|
||||
#[cfg(target_os = "android")]
|
||||
use jni::{
|
||||
EnvUnowned,
|
||||
@@ -10,6 +9,7 @@ use jni::{
|
||||
objects::{JByteArray, JClass, JIntArray},
|
||||
sys::jlong,
|
||||
};
|
||||
use native_core::thumbhash;
|
||||
|
||||
use super::guard;
|
||||
|
||||
@@ -20,7 +20,7 @@ use super::guard;
|
||||
/// `hash` must be null or readable for `len` bytes, at most `isize::MAX`.
|
||||
/// `width` and `height` must be null or valid writable pointers, outside `hash`.
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn immich_core_thumbhash(
|
||||
pub unsafe extern "C" fn native_core_thumbhash(
|
||||
hash: *const u8,
|
||||
len: size_t,
|
||||
width: *mut i32,
|
||||
@@ -65,7 +65,7 @@ pub extern "system" fn Java_app_alextran_immich_images_ThumbHash_decode<'caller>
|
||||
let (mut width, mut height) = (0, 0);
|
||||
// SAFETY: the hash bytes and both output pointers are valid for this call.
|
||||
let rgba =
|
||||
unsafe { immich_core_thumbhash(hash.as_ptr(), hash.len(), &mut width, &mut height) };
|
||||
unsafe { native_core_thumbhash(hash.as_ptr(), hash.len(), &mut width, &mut height) };
|
||||
if !rgba.is_null()
|
||||
&& let Err(err) = info.set_region(env, 0, &[width, height, width * 4])
|
||||
{
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
[tools]
|
||||
rust = { version = "1.98.0", components = "rustfmt,clippy" } # keep in sync with crates/immich_core_ffi/rust-toolchain.toml
|
||||
rust = { version = "1.98.0", components = "rustfmt,clippy" } # keep in sync with crates/native_core_ffi/rust-toolchain.toml
|
||||
|
||||
[tasks.build]
|
||||
description = "Build the native crates for the host"
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
# The asset id must match assetName in hook/build.dart.
|
||||
ffi-native:
|
||||
asset-id: 'package:immich_native_core/src/bindings.g.dart'
|
||||
asset-id: 'package:native_core/src/bindings.g.dart'
|
||||
output: 'lib/src/bindings.g.dart'
|
||||
headers:
|
||||
entry-points:
|
||||
- '../crates/immich_core_ffi/include/immich_core.h'
|
||||
- '../crates/native_core_ffi/include/native_core.h'
|
||||
include-directives:
|
||||
- '**/immich_core.h'
|
||||
- '**/native_core.h'
|
||||
@@ -4,14 +4,14 @@ import 'package:code_assets/code_assets.dart';
|
||||
import 'package:hooks/hooks.dart';
|
||||
import 'package:native_toolchain_rust/native_toolchain_rust.dart';
|
||||
|
||||
const _crate = '../crates/immich_core_ffi';
|
||||
const _crate = '../crates/native_core_ffi';
|
||||
|
||||
// Cargo's dep-info only lists source files, so these have to rerun the hook too.
|
||||
const _manifests = [
|
||||
'../.cargo/config.toml',
|
||||
'../Cargo.toml',
|
||||
'../Cargo.lock',
|
||||
'../crates/immich_core/Cargo.toml',
|
||||
'../crates/native_core/Cargo.toml',
|
||||
'$_crate/Cargo.toml',
|
||||
'$_crate/rust-toolchain.toml',
|
||||
];
|
||||
+2
-2
@@ -3,10 +3,10 @@ import 'package:ffi/ffi.dart';
|
||||
import 'src/bindings.g.dart';
|
||||
|
||||
String version() {
|
||||
final ptr = immich_core_version();
|
||||
final ptr = native_core_version();
|
||||
try {
|
||||
return ptr.cast<Utf8>().toDartString();
|
||||
} finally {
|
||||
immich_core_free_string(ptr);
|
||||
native_core_free_string(ptr);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
name: immich_native_core
|
||||
name: native_core
|
||||
publish_to: none
|
||||
|
||||
environment:
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:immich_native_core/immich_native_core.dart';
|
||||
import 'package:native_core/native_core.dart';
|
||||
|
||||
void main() {
|
||||
test('loads the core and returns its version', () {
|
||||
Reference in New Issue
Block a user