feat: rm unused files

This commit is contained in:
2023-12-09 19:04:56 +08:00
parent df36022203
commit baafa7aa31
7 changed files with 0 additions and 326 deletions

View File

@@ -1 +0,0 @@
example/* linguist-vendored

View File

@@ -1,38 +0,0 @@
name: Build
on:
push:
branches: [ master ]
pull_request:
env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: 1
jobs:
build:
name: Build
runs-on: macos-latest
strategy:
matrix:
rust: [stable, beta]
steps:
- uses: actions/checkout@v3
name: Checkout
- name: Install specific rust version
run: |
rustup install ${{ matrix.rust }} --profile minimal
rustup component add --toolchain ${{ matrix.rust }} rustfmt clippy
- name: Setup cache
uses: Swatinem/rust-cache@v2
- name: Test example
working-directory: example
run: cargo +${{ matrix.rust }} run
- name: Run Tests
env:
TEST_SWIFT_RS: "true"
run: cargo +${{ matrix.rust }} test --features build
- name: Check Code Formatting
run: cargo +${{ matrix.rust }} fmt --all -- --check
- name: Lints
run: cargo +${{ matrix.rust }} clippy -- -D warnings

7
swift-rs/.gitignore vendored
View File

@@ -1,7 +0,0 @@
.build/
target/
.swiftpm/
.idea/
.DS_Store
icon.txt
**/Cargo.lock

View File

@@ -1,31 +0,0 @@
// swift-tools-version:5.3
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let package = Package(
name: "test-swift",
platforms: [
.macOS(.v11),
],
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
.library(
name: "test-swift",
type: .static,
targets: ["test-swift"]),
],
dependencies: [
// Dependencies declare other packages that this package depends on.
.package(name: "SwiftRs", path: "../../")
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages this package depends on.
.target(
name: "test-swift",
dependencies: [.product(name: "SwiftRs", package: "SwiftRs")],
path: ".",
exclude: ["test_example.rs", "test_bindings.rs"])
]
)

View File

@@ -1,70 +0,0 @@
import Foundation
import SwiftRs
// SRArray
//
// Notice that IntArray and ArrayStruct are almost identical!
// The only actual difference between these types is how they're used in Rust,
// but if you added more fields to ArrayStruct then that wouldn't be the case anymore.
class IntArray: NSObject {
var data: SRArray<Int>
init(data: [Int]) {
self.data = SRArray(data)
}
}
@_cdecl("get_int_array")
func getIntArray() -> IntArray {
return IntArray(data: [1, 2, 3])
}
class ArrayStruct: NSObject {
var array: SRArray<Int>
init(array: [Int]) {
self.array = SRArray(array)
}
}
@_cdecl("get_array_struct")
func getArrayStruct() -> ArrayStruct {
return ArrayStruct(array: [4, 5, 6])
}
// SRObject
class CustomObject: NSObject {
var a: Int
var b: Bool
init(a: Int, b: Bool) {
self.a = a
self.b = b
}
}
@_cdecl("get_custom_object")
func getCustomObject() -> CustomObject {
return CustomObject(a: 3, b: true)
}
// SRString
@_cdecl("get_greeting")
func getGreeting(name: SRString) -> SRString {
return SRString("Hello \(name.toString())!")
}
@_cdecl("echo")
func echo(string: SRString) -> SRString {
return string
}
// SRData
@_cdecl("get_data")
func getData() -> SRData {
return SRData([1, 2, 3])
}

View File

@@ -1,29 +0,0 @@
import SwiftRs
import Foundation
class Complex: NSObject {
var a: SRString
var b: Int
var c: Bool
public init(a: SRString, b: Int, c: Bool) {
self.a = a
self.b = b
self.c = c
}
}
@_cdecl("complex_data")
func complexData() -> SRObjectArray {
return SRObjectArray([
Complex(a: SRString("Brendan"), b: 0, c: true),
Complex(a: SRString("Amod"), b: 1, c: false),
Complex(a: SRString("Lucas"), b: 2, c: true),
Complex(a: SRString("Oscar"), b: 3, c: false),
])
}
@_cdecl("echo_data")
func echoData(data: SRData) -> SRData {
return SRData(data.toArray())
}

View File

@@ -1,150 +0,0 @@
//! Test for swift-rs bindings
//!
//! Needs to be run with the env var `TEST_SWIFT_RS=true`, to allow for
//! the test swift code to be linked.
use serial_test::serial;
use std::{env, process::Command};
use swift_rs::*;
macro_rules! test_with_leaks {
( $op:expr ) => {{
let leaks_env_var = "TEST_RUNNING_UNDER_LEAKS";
if env::var(leaks_env_var).unwrap_or_else(|_| "false".into()) == "true" {
let _ = $op();
} else {
// we run $op directly in the current process first, as leaks will not give
// us the exit code of $op, but only if memory leaks happened or not
$op();
// and now we run the above codepath under leaks monitoring
let exe = env::current_exe().unwrap();
// codesign the binary first, so that leaks can be run
let debug_plist = exe.parent().unwrap().join("debug.plist");
let plist_path = &debug_plist.to_string_lossy();
std::fs::write(&debug_plist, DEBUG_PLIST_XML.as_bytes()).unwrap();
let status = Command::new("codesign")
.args([
"-s",
"-",
"-v",
"-f",
"--entitlements",
plist_path,
&exe.to_string_lossy(),
])
.status()
.expect("cmd failure");
assert!(status.success(), "failed to codesign");
// run leaks command to detect memory leaks
let status = Command::new("leaks")
.args(["-atExit", "--", &exe.to_string_lossy(), "--nocapture"])
.env(leaks_env_var, "true")
.status()
.expect("cmd failure");
assert!(status.success(), "leaks detected in memory pressure test");
}
}};
}
swift!(fn echo(string: &SRString) -> SRString);
#[test]
#[serial]
fn test_reflection() {
test_with_leaks!(|| {
// create memory pressure
let name: SRString = "Brendan".into();
for _ in 0..10_000 {
let reflected = unsafe { echo(&name) };
assert_eq!(name.as_str(), reflected.as_str());
}
});
}
swift!(fn get_greeting(name: &SRString) -> SRString);
#[test]
#[serial]
fn test_string() {
test_with_leaks!(|| {
let name: SRString = "Brendan".into();
let greeting = unsafe { get_greeting(&name) };
assert_eq!(greeting.as_str(), "Hello Brendan!");
});
}
#[test]
#[serial]
fn test_memory_pressure() {
test_with_leaks!(|| {
// create memory pressure
let name: SRString = "Brendan".into();
for _ in 0..10_000 {
let greeting = unsafe { get_greeting(&name) };
assert_eq!(greeting.as_str(), "Hello Brendan!");
}
});
}
#[test]
#[serial]
fn test_autoreleasepool() {
test_with_leaks!(|| {
// create memory pressure
let name: SRString = "Brendan".into();
for _ in 0..10_000 {
autoreleasepool!({
let greeting = unsafe { get_greeting(&name) };
assert_eq!(greeting.as_str(), "Hello Brendan!");
});
}
});
}
#[repr(C)]
struct Complex {
a: SRString,
b: Int,
c: Bool,
}
swift!(fn complex_data() -> SRObjectArray<Complex>);
#[test]
#[serial]
fn test_complex() {
test_with_leaks!(|| {
let mut v = vec![];
for _ in 0..10_000 {
let data = unsafe { complex_data() };
assert_eq!(data[0].a.as_str(), "Brendan");
v.push(data);
}
});
}
swift!(fn echo_data(data: &SRData) -> SRData);
#[test]
#[serial]
fn test_data() {
test_with_leaks!(|| {
let str: &str = "hello";
let bytes = str.as_bytes();
for _ in 0..10_000 {
let data = unsafe { echo_data(&bytes.into()) };
assert_eq!(data.as_slice(), bytes);
}
});
}
const DEBUG_PLIST_XML: &str = r#"<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "https://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict><key>com.apple.security.get-task-allow</key><true/></dict>
</plist>
"#;