diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e9b6d56..f2f86c7 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -97,15 +97,15 @@ jobs: - name: Create fat library run: | mkdir universal - lipo -create ./artifacts/x86_64-apple-darwin/libyxy_abi.a ./artifacts/aarch64-apple-darwin/libyxy_abi.a -output ./universal/libyxy_macos.a - lipo -create ./artifacts/x86_64-apple-ios/libyxy_abi.a ./artifacts/aarch64-apple-ios-sim/libyxy_abi.a -output ./universal/libyxy_iossim.a + lipo -create ./artifacts/x86_64-apple-darwin/libyxy_ffi.a ./artifacts/aarch64-apple-darwin/libyxy_ffi.a -output ./universal/libyxy_macos.a + lipo -create ./artifacts/x86_64-apple-ios/libyxy_ffi.a ./artifacts/aarch64-apple-ios-sim/libyxy_ffi.a -output ./universal/libyxy_iossim.a - name: Create XCFramework & Bundle run: | - xcodebuild -create-xcframework -library ./universal/libyxy_macos.a -headers ./crates/abi/include/ -library ./universal/libyxy_iossim.a -headers ./crates/abi/include/ -library ./artifacts/aarch64-apple-ios/libyxy_abi.a -headers ./crates/abi/include/ -output yxy.xcframework + xcodebuild -create-xcframework -library ./universal/libyxy_macos.a -headers ./crates/ffi/include/ -library ./universal/libyxy_iossim.a -headers ./crates/ffi/include/ -library ./artifacts/aarch64-apple-ios/libyxy_ffi.a -headers ./crates/ffi/include/ -output yxy.xcframework zip -r xcframework-universal.zip yxy.xcframework openssl dgst -sha256 xcframework-universal.zip > xcframework-universal.zip.checksum - cp ./crates/abi/include/yxy.h . + cp ./crates/ffi/include/yxy.h . - name: Package core crate run: | @@ -124,20 +124,20 @@ jobs: mkdir dist mv artifacts/x86_64-apple-darwin/yxy-cli dist/yxy-cli-x86_64-apple-darwin mv artifacts/x86_64-apple-darwin/yxy-httpd dist/yxy-httpd-x86_64-apple-darwin - mv artifacts/x86_64-apple-darwin/libyxy_abi.dylib dist/libyxy-x86_64-apple-darwin.dylib - mv artifacts/x86_64-apple-darwin/libyxy_abi.a dist/libyxy-x86_64-apple-darwin.a + mv artifacts/x86_64-apple-darwin/libyxy_ffi.dylib dist/libyxy-x86_64-apple-darwin.dylib + mv artifacts/x86_64-apple-darwin/libyxy_ffi.a dist/libyxy-x86_64-apple-darwin.a mv artifacts/x86_64-pc-windows-msvc/yxy-cli.exe dist/yxy-cli-x86_64-pc-windows-msvc.exe mv artifacts/x86_64-pc-windows-msvc/yxy-httpd.exe dist/yxy-httpd-x86_64-pc-windows-msvc.exe - mv artifacts/x86_64-pc-windows-msvc/yxy_abi.dll dist/yxy-x86_64-pc-windows-msvc.dll - mv artifacts/x86_64-pc-windows-msvc/yxy_abi.lib dist/yxy-x86_64-pc-windows-msvc.lib + mv artifacts/x86_64-pc-windows-msvc/yxy_ffi.dll dist/yxy-x86_64-pc-windows-msvc.dll + mv artifacts/x86_64-pc-windows-msvc/yxy_ffi.lib dist/yxy-x86_64-pc-windows-msvc.lib mv artifacts/x86_64-unknown-linux-gnu/yxy-cli dist/yxy-cli-x86_64-unknown-linux-gnu mv artifacts/x86_64-unknown-linux-gnu/yxy-httpd dist/yxy-httpd-x86_64-unknown-linux-gnu - mv artifacts/x86_64-unknown-linux-gnu/libyxy_abi.so dist/libyxy-x86_64-unknown-linux-gnu.so - mv artifacts/x86_64-unknown-linux-gnu/libyxy_abi.a dist/libyxy-x86_64-unknown-linux-gnu.a + mv artifacts/x86_64-unknown-linux-gnu/libyxy_ffi.so dist/libyxy-x86_64-unknown-linux-gnu.so + mv artifacts/x86_64-unknown-linux-gnu/libyxy_ffi.a dist/libyxy-x86_64-unknown-linux-gnu.a mv artifacts/aarch64-apple-darwin/yxy-cli dist/yxy-cli-aarch64-apple-darwin mv artifacts/aarch64-apple-darwin/yxy-httpd dist/yxy-httpd-aarch64-apple-darwin - mv artifacts/aarch64-apple-darwin/libyxy_abi.dylib dist/libyxy-aarch64-apple-darwin.dylib - mv artifacts/aarch64-apple-darwin/libyxy_abi.a dist/libyxy-aarch64-apple-darwin.a + mv artifacts/aarch64-apple-darwin/libyxy_ffi.dylib dist/libyxy-aarch64-apple-darwin.dylib + mv artifacts/aarch64-apple-darwin/libyxy_ffi.a dist/libyxy-aarch64-apple-darwin.a mv xcframework-universal.zip dist/xcframework-universal.zip mv xcframework-universal.zip.checksum dist/xcframework-universal.zip.checksum mv target/package/yxy-*.crate dist/ diff --git a/Cargo.lock b/Cargo.lock index eb611b3..2233401 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2143,14 +2143,6 @@ dependencies = [ "uuid", ] -[[package]] -name = "yxy-abi" -version = "0.2.0-alpha" -dependencies = [ - "ffi-destruct", - "yxy", -] - [[package]] name = "yxy-cli" version = "0.3.0-alpha" @@ -2164,6 +2156,14 @@ dependencies = [ "yxy", ] +[[package]] +name = "yxy-ffi" +version = "0.2.0-alpha" +dependencies = [ + "ffi-destruct", + "yxy", +] + [[package]] name = "yxy-httpd" version = "0.1.1" diff --git a/Cargo.toml b/Cargo.toml index 75eaca3..beec645 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,3 +1,3 @@ [workspace] resolver = "2" -members = ["crates/abi", "crates/cli", "crates/core", "crates/httpd"] \ No newline at end of file +members = ["crates/ffi", "crates/cli", "crates/core", "crates/httpd"] diff --git a/Makefile b/Makefile index b172a6c..eac7d0d 100644 --- a/Makefile +++ b/Makefile @@ -1,16 +1,16 @@ CC=cc APPLE_TARGETS=aarch64-apple-darwin aarch64-apple-ios aarch64-apple-ios-sim x86_64-apple-darwin x86_64-apple-ios -HEADER_FILE=./crates/abi/include/yxy.h +HEADER_FILE=./crates/ffi/include/yxy.h -.PHONY: core abi cli all apple clean-xcf xcf clean cbindgen ctest httpd server +.PHONY: core ffi cli all apple clean-xcf xcf clean cbindgen ctest httpd server core: @echo "Building core lib..." @cargo build -p yxy -abi: +ffi: @echo "Building cdylib & staticlib..." - @cargo build -p yxy-abi --all-features + @cargo build -p yxy-ffi --all-features cli: @echo "Building CLI..." @@ -56,12 +56,12 @@ clean-xcf: apple: @echo "Building Apple targets..." @for target in $(APPLE_TARGETS); do \ - cargo build -p yxy-abi --all-features --target $$target --release; \ + cargo build -p yxy-ffi --all-features --target $$target --release; \ done cbindgen: @echo "Generating C bindings..." - @rustup run nightly cbindgen --config ./crates/abi/cbindgen.toml --crate yxy-abi --output $(HEADER_FILE) + @rustup run nightly cbindgen --config ./crates/ffi/cbindgen.toml --crate yxy-ffi --output $(HEADER_FILE) @echo "Generate successfully out to: $(HEADER_FILE)" xcf: apple cbindgen clean-xcf @@ -69,26 +69,26 @@ xcf: apple cbindgen clean-xcf @mkdir -p target/universal/release @lipo -create \ - target/x86_64-apple-darwin/release/libyxy_abi.a \ - target/aarch64-apple-darwin/release/libyxy_abi.a \ + target/x86_64-apple-darwin/release/libyxy_ffi.a \ + target/aarch64-apple-darwin/release/libyxy_ffi.a \ -output target/universal/release/libyxy_macos.a @lipo -create \ - target/aarch64-apple-ios-sim/release/libyxy_abi.a \ - target/x86_64-apple-ios/release/libyxy_abi.a \ + target/aarch64-apple-ios-sim/release/libyxy_ffi.a \ + target/x86_64-apple-ios/release/libyxy_ffi.a \ -output target/universal/release/libyxy_iossim.a @xcodebuild -create-xcframework \ - -library ./target/universal/release/libyxy_macos.a -headers ./crates/abi/include/ \ - -library ./target/universal/release/libyxy_iossim.a -headers ./crates/abi/include/ \ - -library ./target/aarch64-apple-ios/release/libyxy_abi.a -headers ./crates/abi/include/ \ + -library ./target/universal/release/libyxy_macos.a -headers ./crates/ffi/include/ \ + -library ./target/universal/release/libyxy_iossim.a -headers ./crates/ffi/include/ \ + -library ./target/aarch64-apple-ios/release/libyxy_ffi.a -headers ./crates/ffi/include/ \ -output target/universal/yxy-static.xcframework -ctest: abi +ctest: ffi @echo "Building C test..." @mkdir -p ./target/tests - @rustup run nightly cbindgen --crate yxy-abi -c ./crates/abi/cbindgen.toml --output ./tests/yxy.h - @$(CC) -l yxy_abi -L ./target/debug -o ./target/debug/main ./tests/main.c + @rustup run nightly cbindgen --crate yxy-ffi -c ./crates/ffi/cbindgen.toml --output ./tests/yxy.h + @$(CC) -l yxy_ffi -L ./target/debug -o ./target/debug/main ./tests/main.c @echo "Runing tests..." @./target/debug/main diff --git a/README.md b/README.md index 929b0d3..5a8d990 100644 --- a/README.md +++ b/README.md @@ -47,12 +47,12 @@ A simple tool: [`yxy-cli`][yxy-cli] ## For other programming languages -See more: [`yxy-abi`][yxy-abi] or [`yxy-httpd`][yxy-httpd] +See more: [`yxy-ffi`][yxy-ffi] or [`yxy-httpd`][yxy-httpd] # Disclaimer Completely FREE software for learning only. **Any inappropriate use is at your own risk.** [yxy-cli]: https://github.com/DumpTime/yxy/tree/dev/crates/cli -[yxy-abi]: https://github.com/DumpTime/yxy/tree/dev/crates/abi +[yxy-ffi]: https://github.com/DumpTime/yxy/tree/dev/crates/ffi [yxy-httpd]: https://github.com/DumpTime/yxy/tree/dev/crates/httpd \ No newline at end of file diff --git a/crates/abi/Cargo.toml b/crates/ffi/Cargo.toml similarity index 95% rename from crates/abi/Cargo.toml rename to crates/ffi/Cargo.toml index 4f11712..48ce766 100644 --- a/crates/abi/Cargo.toml +++ b/crates/ffi/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "yxy-abi" +name = "yxy-ffi" version = "0.2.0-alpha" edition = "2021" license = "Apache-2.0" diff --git a/crates/abi/README.md b/crates/ffi/README.md similarity index 97% rename from crates/abi/README.md rename to crates/ffi/README.md index 3a5897a..c7a4292 100644 --- a/crates/abi/README.md +++ b/crates/ffi/README.md @@ -1,4 +1,4 @@ -# YXY C ABI +# YXY C FFI C-style yxy bindings for other language calls. @@ -21,7 +21,7 @@ See [yxy-httpd]. ### Manual In the root of source tree: ```bash -rustup run nightly cbindgen --crate yxy-abi -c ./crates/abi/cbindgen.toml -o ./crates/abi/include/yxy.h +rustup run nightly cbindgen --crate yxy-ffi -c ./crates/ffi/cbindgen.toml -o ./crates/ffi/include/yxy.h ``` ## Safety diff --git a/crates/abi/cbindgen.toml b/crates/ffi/cbindgen.toml similarity index 99% rename from crates/abi/cbindgen.toml rename to crates/ffi/cbindgen.toml index 3d4c95d..c0f054e 100644 --- a/crates/abi/cbindgen.toml +++ b/crates/ffi/cbindgen.toml @@ -127,7 +127,7 @@ extra_bindings = [] [parse.expand] -crates = ["yxy-abi"] +crates = ["yxy-ffi"] all_features = false default_features = true features = ["blocking"] diff --git a/crates/abi/include/module.modulemap b/crates/ffi/include/module.modulemap similarity index 100% rename from crates/abi/include/module.modulemap rename to crates/ffi/include/module.modulemap diff --git a/crates/abi/include/yxy.h b/crates/ffi/include/yxy.h similarity index 89% rename from crates/abi/include/yxy.h rename to crates/ffi/include/yxy.h index 9d519fd..7f78f93 100644 --- a/crates/abi/include/yxy.h +++ b/crates/ffi/include/yxy.h @@ -3,7 +3,8 @@ /* Generated with cbindgen:0.24.3 */ -/* Warning, this file is autogenerated by cbindgen. Don't modify this manually. */ +/* Warning, this file is autogenerated by cbindgen. Don't modify this manually. + */ #include #include @@ -124,7 +125,7 @@ typedef struct LoginInfo { * Deallocate c-style string to avoid memory leak. * * ## Safety - * C-ABI usage only + * C-FFI usage only * */ void destruct_c_string(char *ptr); @@ -137,7 +138,7 @@ void destruct_room_info(struct RoomInfo *ptr); #if defined(DEFINE_BLOCKING) /** * ## Safety - * C-ABI usage only + * C-FFI usage only */ struct RoomInfo *query_ele_bind(const struct AppHandler *handler); #endif @@ -149,7 +150,7 @@ void destruct_electricity_info(struct ElectricityInfo *ptr); #if defined(DEFINE_BLOCKING) /** * ## Safety - * C-ABI usage only + * C-FFI usage only */ struct ElectricityInfo *query_ele(const struct AppHandler *handler); #endif @@ -157,7 +158,7 @@ struct ElectricityInfo *query_ele(const struct AppHandler *handler); #if defined(DEFINE_BLOCKING) /** * ## Safety - * C-ABI usage only + * C-FFI usage only */ struct ElectricityInfo *query_ele_by_room_info(const struct AppHandler *handler, const struct RoomInfo *info); @@ -177,7 +178,7 @@ void destruct_app_handler(struct AppHandler *ptr); * - `*mut c_char`: token c-string, UTF-8. Return nullptr on error. * * # Safety - * C-ABI usage only + * C-FFI usage only */ char *app_auth(const char *uid); #endif @@ -187,7 +188,7 @@ char *app_auth(const char *uid); * Build [`AppHandler`] by exist session token * * ## Safety - * C-ABI usage only + * C-FFI usage only */ struct AppHandler *build_app_handler(const char *token); #endif @@ -197,7 +198,7 @@ struct AppHandler *build_app_handler(const char *token); * Get [`AppHandler`] by UID with default query * * ## Safety - * C-ABI usage only + * C-FFI usage only */ struct AppHandler *get_app_handler(const char *uid); #endif @@ -209,7 +210,7 @@ void destruct_login_handler(struct LoginHandler *ptr); #if defined(DEFINE_BLOCKING) /** * ## Safety - * C-ABI usage only + * C-FFI usage only */ struct LoginHandler *new_login_handler(void); #endif @@ -219,7 +220,7 @@ struct LoginHandler *new_login_handler(void); * Build [`LoginHandler`] by provided `device_id` * * ## Safety - * C-ABI usage only + * C-FFI usage only */ struct LoginHandler *build_login_handler(char *device_id); #endif @@ -233,7 +234,7 @@ void destruct_security_token(struct SecurityToken *ptr); * Get security token * * ## Safety - * C-ABI usage only + * C-FFI usage only */ struct SecurityToken *get_security_token(const struct LoginHandler *handler); #endif @@ -243,9 +244,10 @@ struct SecurityToken *get_security_token(const struct LoginHandler *handler); * Get captcha image * * ## Safety - * C-ABI usage only + * C-FFI usage only */ -char *get_captcha_image(const struct LoginHandler *handler, const char *security_token); +char *get_captcha_image(const struct LoginHandler *handler, + const char *security_token); #endif #if defined(DEFINE_BLOCKING) @@ -259,14 +261,14 @@ char *get_captcha_image(const struct LoginHandler *handler, const char *security * If captcha input `NULL`, it means no captcha is required. * * ## Returns - * - `c_int`: `0` on success, `1` on user is not exist(registered), otherwise error code + * - `c_int`: `0` on success, `1` on user is not exist(registered), otherwise + * error code * * ## Safety - * C-ABI usage only + * C-FFI usage only */ int send_verification_code(const struct LoginHandler *handler, - const char *phone_number, - const char *security_token, + const char *phone_number, const char *security_token, const char *captcha); #endif @@ -279,11 +281,10 @@ void destruct_login_info(struct LoginInfo *ptr); * Do login by SMS verification code * * ## Safety - * C-ABI usage only + * C-FFI usage only */ struct LoginInfo *do_login_by_code(const struct LoginHandler *handler, - const char *phone_number, - const char *code); + const char *phone_number, const char *code); #endif #endif /* yxy_h */ diff --git a/crates/abi/src/blocking/app.rs b/crates/ffi/src/blocking/app.rs similarity index 98% rename from crates/abi/src/blocking/app.rs rename to crates/ffi/src/blocking/app.rs index 432f40e..2617154 100644 --- a/crates/abi/src/blocking/app.rs +++ b/crates/ffi/src/blocking/app.rs @@ -44,7 +44,7 @@ impl From<&RoomInfo> for yxy::blocking::RoomInfo { } /// ## Safety -/// C-ABI usage only +/// C-FFI usage only #[no_mangle] pub unsafe extern "C" fn query_ele_bind(handler: *const AppHandler) -> *mut RoomInfo { check_null_return_null!(handler); @@ -116,7 +116,7 @@ impl TryFrom for ElectricityInfo { } /// ## Safety -/// C-ABI usage only +/// C-FFI usage only #[no_mangle] pub unsafe extern "C" fn query_ele(handler: *const AppHandler) -> *mut ElectricityInfo { check_null_return_null!(handler); @@ -145,7 +145,7 @@ pub unsafe extern "C" fn query_ele(handler: *const AppHandler) -> *mut Electrici } /// ## Safety -/// C-ABI usage only +/// C-FFI usage only #[no_mangle] pub unsafe extern "C" fn query_ele_by_room_info( handler: *const AppHandler, diff --git a/crates/abi/src/blocking/auth.rs b/crates/ffi/src/blocking/auth.rs similarity index 96% rename from crates/abi/src/blocking/auth.rs rename to crates/ffi/src/blocking/auth.rs index 52b360e..6835b24 100644 --- a/crates/abi/src/blocking/auth.rs +++ b/crates/ffi/src/blocking/auth.rs @@ -15,7 +15,7 @@ extern_c_destructor!(AppHandler); /// - `*mut c_char`: token c-string, UTF-8. Return nullptr on error. /// /// # Safety -/// C-ABI usage only +/// C-FFI usage only #[no_mangle] pub unsafe extern "C" fn app_auth(uid: *const c_char) -> *mut c_char { check_null_return_null!(uid); @@ -33,7 +33,7 @@ pub unsafe extern "C" fn app_auth(uid: *const c_char) -> *mut c_char { /// Build [`AppHandler`] by exist session token /// /// ## Safety -/// C-ABI usage only +/// C-FFI usage only #[no_mangle] pub unsafe extern "C" fn build_app_handler(token: *const c_char) -> *mut AppHandler { check_null_return_null!(token); @@ -51,7 +51,7 @@ pub unsafe extern "C" fn build_app_handler(token: *const c_char) -> *mut AppHand /// Get [`AppHandler`] by UID with default query /// /// ## Safety -/// C-ABI usage only +/// C-FFI usage only #[no_mangle] pub unsafe extern "C" fn get_app_handler(uid: *const c_char) -> *mut AppHandler { check_null_return_null!(uid); diff --git a/crates/abi/src/blocking/login.rs b/crates/ffi/src/blocking/login.rs similarity index 97% rename from crates/abi/src/blocking/login.rs rename to crates/ffi/src/blocking/login.rs index 7ed1eda..d37c9fb 100644 --- a/crates/abi/src/blocking/login.rs +++ b/crates/ffi/src/blocking/login.rs @@ -9,7 +9,7 @@ use yxy::blocking::LoginHandler; extern_c_destructor!(LoginHandler); /// ## Safety -/// C-ABI usage only +/// C-FFI usage only #[no_mangle] pub unsafe extern "C" fn new_login_handler() -> *mut LoginHandler { let handler = match LoginHandler::new() { @@ -22,7 +22,7 @@ pub unsafe extern "C" fn new_login_handler() -> *mut LoginHandler { /// Build [`LoginHandler`] by provided `device_id` /// /// ## Safety -/// C-ABI usage only +/// C-FFI usage only #[no_mangle] pub unsafe extern "C" fn build_login_handler(device_id: *mut c_char) -> *mut LoginHandler { check_null_return_null!(device_id); @@ -51,7 +51,7 @@ extern_c_destructor!(SecurityToken); /// Get security token /// /// ## Safety -/// C-ABI usage only +/// C-FFI usage only #[no_mangle] pub unsafe extern "C" fn get_security_token(handler: *const LoginHandler) -> *mut SecurityToken { check_null_return_null!(handler); @@ -76,7 +76,7 @@ pub unsafe extern "C" fn get_security_token(handler: *const LoginHandler) -> *mu /// Get captcha image /// /// ## Safety -/// C-ABI usage only +/// C-FFI usage only #[no_mangle] pub unsafe extern "C" fn get_captcha_image( handler: *const LoginHandler, @@ -109,7 +109,7 @@ pub unsafe extern "C" fn get_captcha_image( /// - `c_int`: `0` on success, `1` on user is not exist(registered), otherwise error code /// /// ## Safety -/// C-ABI usage only +/// C-FFI usage only #[no_mangle] pub unsafe extern "C" fn send_verification_code( handler: *const LoginHandler, @@ -160,7 +160,7 @@ extern_c_destructor!(LoginInfo); /// Do login by SMS verification code /// /// ## Safety -/// C-ABI usage only +/// C-FFI usage only #[no_mangle] pub unsafe extern "C" fn do_login_by_code( handler: *const LoginHandler, diff --git a/crates/abi/src/blocking/mod.rs b/crates/ffi/src/blocking/mod.rs similarity index 95% rename from crates/abi/src/blocking/mod.rs rename to crates/ffi/src/blocking/mod.rs index 81bf2ae..c036d60 100644 --- a/crates/abi/src/blocking/mod.rs +++ b/crates/ffi/src/blocking/mod.rs @@ -13,7 +13,7 @@ pub mod login; /// Deallocate c-style string to avoid memory leak. /// /// ## Safety -/// C-ABI usage only +/// C-FFI usage only /// #[no_mangle] pub unsafe extern "C" fn destruct_c_string(ptr: *mut c_char) { diff --git a/crates/abi/src/lib.rs b/crates/ffi/src/lib.rs similarity index 98% rename from crates/abi/src/lib.rs rename to crates/ffi/src/lib.rs index d1881d8..cd483fc 100644 --- a/crates/abi/src/lib.rs +++ b/crates/ffi/src/lib.rs @@ -1,4 +1,4 @@ -//! # yxy-abi +//! # yxy-ffi //! //! C-style yxy bindings //! diff --git a/crates/abi/src/utils.rs b/crates/ffi/src/utils.rs similarity index 100% rename from crates/abi/src/utils.rs rename to crates/ffi/src/utils.rs