This commit is contained in:
mii443
2025-04-15 18:16:44 +09:00
commit e264cbaacb
13 changed files with 94 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/target

7
Cargo.lock generated Normal file
View File

@ -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"

5
Cargo.toml Normal file
View File

@ -0,0 +1,5 @@
[package]
name = "azookey-binding"
version = "0.1.0"
edition = "2024"

8
azookey-swift/.gitignore vendored Normal file
View File

@ -0,0 +1,8 @@
.DS_Store
/.build
/Packages
xcuserdata/
DerivedData/
.swiftpm/configuration/registries.json
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
.netrc

View File

@ -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"]
),
]
)

View File

@ -0,0 +1,7 @@
import Foundation
import ffi
@_silgen_name("HelloSwift")
@MainActor public func hello_swift() {
print("hello_swift")
}

View File

View File

@ -0,0 +1,7 @@
#ifndef ffi_h
#define ffi_h
#include <stdio.h>
#endif

View File

@ -0,0 +1,5 @@
module ffi {
header "ffi.h"
export *
}

View File

@ -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.
}

8
build.rs Normal file
View File

@ -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");
}

3
src/lib.rs Normal file
View File

@ -0,0 +1,3 @@
unsafe extern "C" {
pub fn HelloSwift();
}

3
src/main.rs Normal file
View File

@ -0,0 +1,3 @@
fn main() {
unsafe { azookey_binding::HelloSwift() };
}