Skip to content
This repository has been archived by the owner on Sep 12, 2024. It is now read-only.

Commit

Permalink
refactor(ffi): rename abi to ffi
Browse files Browse the repository at this point in the history
  • Loading branch information
DumpTime committed Oct 28, 2023
1 parent 6e32463 commit c1fad13
Show file tree
Hide file tree
Showing 16 changed files with 78 additions and 77 deletions.
24 changes: 12 additions & 12 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand All @@ -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/
Expand Down
16 changes: 8 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[workspace]
resolver = "2"
members = ["crates/abi", "crates/cli", "crates/core", "crates/httpd"]
members = ["crates/ffi", "crates/cli", "crates/core", "crates/httpd"]
32 changes: 16 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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..."
Expand Down Expand Up @@ -56,39 +56,39 @@ 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
@echo "Building XCFramework..."

@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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion crates/abi/Cargo.toml → crates/ffi/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "yxy-abi"
name = "yxy-ffi"
version = "0.2.0-alpha"
edition = "2021"
license = "Apache-2.0"
Expand Down
4 changes: 2 additions & 2 deletions crates/abi/README.md → crates/ffi/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# YXY C ABI
# YXY C FFI

C-style yxy bindings for other language calls.

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion crates/abi/cbindgen.toml → crates/ffi/cbindgen.toml
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ extra_bindings = []


[parse.expand]
crates = ["yxy-abi"]
crates = ["yxy-ffi"]
all_features = false
default_features = true
features = ["blocking"]
File renamed without changes.
41 changes: 21 additions & 20 deletions crates/abi/include/yxy.h → crates/ffi/include/yxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <stdarg.h>
#include <stdbool.h>
Expand Down Expand Up @@ -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);
Expand All @@ -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
Expand All @@ -149,15 +150,15 @@ 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

#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);
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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

Expand All @@ -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 */
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -116,7 +116,7 @@ impl TryFrom<yxy::blocking::ElectricityInfo> 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);
Expand Down Expand Up @@ -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,
Expand Down
Loading

0 comments on commit c1fad13

Please sign in to comment.