From e264cbaacbc6b51b7497da1dd0de1633d2249f9d Mon Sep 17 00:00:00 2001 From: mii443 Date: Tue, 15 Apr 2025 18:16:44 +0900 Subject: [PATCH] first --- .gitignore | 1 + Cargo.lock | 7 ++++ Cargo.toml | 5 +++ azookey-swift/.gitignore | 8 +++++ azookey-swift/Package.swift | 34 +++++++++++++++++++ .../Sources/azookey-swift/azookey_swift.swift | 7 ++++ azookey-swift/Sources/ffi/ffi.c | 0 azookey-swift/Sources/ffi/include/ffi.h | 7 ++++ azookey-swift/Sources/ffi/module.modulemap | 5 +++ .../azookey_swiftTests.swift | 6 ++++ build.rs | 8 +++++ src/lib.rs | 3 ++ src/main.rs | 3 ++ 13 files changed, 94 insertions(+) create mode 100644 .gitignore create mode 100644 Cargo.lock create mode 100644 Cargo.toml create mode 100644 azookey-swift/.gitignore create mode 100644 azookey-swift/Package.swift create mode 100644 azookey-swift/Sources/azookey-swift/azookey_swift.swift create mode 100644 azookey-swift/Sources/ffi/ffi.c create mode 100644 azookey-swift/Sources/ffi/include/ffi.h create mode 100644 azookey-swift/Sources/ffi/module.modulemap create mode 100644 azookey-swift/Tests/azookey-swiftTests/azookey_swiftTests.swift create mode 100644 build.rs create mode 100644 src/lib.rs create mode 100644 src/main.rs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/target diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..207ecc2 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "azookey-binding" +version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..35430ea --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,5 @@ +[package] +name = "azookey-binding" +version = "0.1.0" +edition = "2024" + diff --git a/azookey-swift/.gitignore b/azookey-swift/.gitignore new file mode 100644 index 0000000..0023a53 --- /dev/null +++ b/azookey-swift/.gitignore @@ -0,0 +1,8 @@ +.DS_Store +/.build +/Packages +xcuserdata/ +DerivedData/ +.swiftpm/configuration/registries.json +.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata +.netrc diff --git a/azookey-swift/Package.swift b/azookey-swift/Package.swift new file mode 100644 index 0000000..0760205 --- /dev/null +++ b/azookey-swift/Package.swift @@ -0,0 +1,34 @@ +// swift-tools-version: 6.1 +// The swift-tools-version declares the minimum version of Swift required to build this package. + +import PackageDescription + +let package = Package( + name: "azookey-swift", + products: [ + // Products define the executables and libraries a package produces, making them visible to other packages. + .library( + name: "azookey-swift", + type: .dynamic, + targets: ["azookey-swift"]), + .library( + name: "ffi", + targets: ["azookey-swift"] + ) + ], + targets: [ + // Targets are the basic building blocks of a package, defining a module or a test suite. + // Targets can depend on other targets in this package and products from dependencies. + .target(name: "ffi"), + .target( + name: "azookey-swift", + dependencies: [ + "ffi" + ] + ), + .testTarget( + name: "azookey-swiftTests", + dependencies: ["azookey-swift"] + ), + ] +) diff --git a/azookey-swift/Sources/azookey-swift/azookey_swift.swift b/azookey-swift/Sources/azookey-swift/azookey_swift.swift new file mode 100644 index 0000000..d23ae17 --- /dev/null +++ b/azookey-swift/Sources/azookey-swift/azookey_swift.swift @@ -0,0 +1,7 @@ +import Foundation +import ffi + +@_silgen_name("HelloSwift") +@MainActor public func hello_swift() { + print("hello_swift") +} diff --git a/azookey-swift/Sources/ffi/ffi.c b/azookey-swift/Sources/ffi/ffi.c new file mode 100644 index 0000000..e69de29 diff --git a/azookey-swift/Sources/ffi/include/ffi.h b/azookey-swift/Sources/ffi/include/ffi.h new file mode 100644 index 0000000..cb1c76e --- /dev/null +++ b/azookey-swift/Sources/ffi/include/ffi.h @@ -0,0 +1,7 @@ +#ifndef ffi_h +#define ffi_h + +#include + +#endif + diff --git a/azookey-swift/Sources/ffi/module.modulemap b/azookey-swift/Sources/ffi/module.modulemap new file mode 100644 index 0000000..80bc267 --- /dev/null +++ b/azookey-swift/Sources/ffi/module.modulemap @@ -0,0 +1,5 @@ +module ffi { + header "ffi.h" + + export * +} diff --git a/azookey-swift/Tests/azookey-swiftTests/azookey_swiftTests.swift b/azookey-swift/Tests/azookey-swiftTests/azookey_swiftTests.swift new file mode 100644 index 0000000..f0bc3ad --- /dev/null +++ b/azookey-swift/Tests/azookey-swiftTests/azookey_swiftTests.swift @@ -0,0 +1,6 @@ +import Testing +@testable import azookey_swift + +@Test func example() async throws { + // Write your test here and use APIs like `#expect(...)` to check expected conditions. +} diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..1096425 --- /dev/null +++ b/build.rs @@ -0,0 +1,8 @@ +fn main() { + let project_dir = std::env::var("CARGO_MANIFEST_DIR").unwrap(); + println!( + "cargo:rustc-link-search={}/azookey-swift/.build/release/", + project_dir + ); + println!("cargo:rustc-link-lib=azookey-swift"); +} diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..2448040 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,3 @@ +unsafe extern "C" { + pub fn HelloSwift(); +} diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..d23b6a8 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + unsafe { azookey_binding::HelloSwift() }; +}