Call Swift functions from Rust with ease!

Related tags

Utility swift-rs
Overview

swift-rs

Call Swift functions from Rust with ease!

Todo

  • Swift class deallocation from rust (implementing Drop and using deallocate_{type} methods)
  • More ease of use and utility functions
Comments
  • Decrement ARC counts on SRObject drop

    Decrement ARC counts on SRObject drop

    After looking over swift-bindgen's code, it seems that it's possible to manually alter ARC counts for arbitrary pointers, meaning that it should be possible to let the swift runtime know when rust is done with an SRObject by decrementing the corresponding ARC. This should avoid memory leaks that I believe exist at the moment, since I don't thing swift knows when rust is finished with a value.

    opened by Brendonovich 10
  • Handle nil

    Handle nil

    How do I handle nil returned from a swift function? The *const pointer in SRObject is private, so I can't check result.0.is_null(). Any other option?

    EDIT: Opened a PR: #5

    opened by 0rvar 5
  • Please consider dual-licensing under MIT + Apache License

    Please consider dual-licensing under MIT + Apache License

    The rest of the ecosystem mostly uses dual licensing under MIT + Apache, and so does the Rust project. See this issue as an example, and for steps on how to do it.

    Should you choose to do it, you have the permission from me: I license past and future contributions to this project under the dual MIT/Apache-2.0 license, allowing licensees to chose either at their option.

    opened by amodm 3
  • what a some scenarios where such interoperability could be useful?

    what a some scenarios where such interoperability could be useful?

    Hey, just been wandering here and there when i landed on this project. This questions is out of pure curiosity as I am mostly a jr. programmer but rust<->swift interoperability looks like kind of exotic thing. I see that for both rust and swift its important to have access to the legacy of c world, but what are I some potential real world scenarios where swift-rust interop is a thing?

    Just to make things clear - I am genuinely asking and appreciate the work done on this project!

    opened by shengchalover 3
  • Build script breaks when package_root does not end with slash

    Build script breaks when package_root does not end with slash

    Currently, string concatenation is used to determine the path to be output for cargo:rustc-link-search=native=, as seen here: https://github.com/Brendonovich/swift-rs/blob/1ca64300e3deedbd47d782d86770d5fc673ffaa4/src-rs/build.rs#L80

    So if the package_root argument to link_swift_package does not end with a /, the build breaks, and it's not obvious to the user why that has happened.

    This needs to be changed to use std::path's join mechanism instead of a simple string concatenation.

    opened by amodm 1
  • Fix build failure, and miscellaneous cleanups

    Fix build failure, and miscellaneous cleanups

    Currently, there's a build failure when link_swift_package() is called with package_root not ending in /. This happens because cargo:rustc-link-search is determined using string concatenation. This PR modifies it to use std::path join methods instead.

    When trying to test this change, I realised that there were the following other miscellaneous issues, which I've fixed as well:

    1. Removed Cargo.lock. This file is supposed to be committed to repo only by end binaries. Given that this crate is a library, it shouldn't be having this.
    2. Add tests to the repo. Without this it would be difficult to continue to expand the work of this crate. cargo test now works.
    3. Add Github Actions workflows to run cargo build and cargo test on every push to master branch, and for PRs.
    4. Include crates.io, license and build status badges in README header. The build status would start working only after you've merged this PR.
    5. Miscellaneous changes to code to satisfy rustfmt and clippy.

    Thank you for this useful crate.

    opened by amodm 1
  • Remove Swift Runtime Compatability Version String

    Remove Swift Runtime Compatability Version String

    The version of Swift running on my M1 MacBook Pro does not output a runtime compatibility version string which causes the unwrap to fail in the build script. This small change should fix the issue but I am not sure how it will act on other systems so further testing is certainly required. Also removed native and static declarations as those also caused issues with my system.

    Output of swift -version on my system swift-driver version: 1.26.9 Apple Swift version 5.5.1 (swiftlang-1300.0.31.4 clang-1300.0.29.6) Target: arm64-apple-macosx12.0

    opened by haydenstith 1
  • Does this work in Liux environment too?

    Does this work in Liux environment too?

    Hello. I'm making a Rust program that uses Swift libraries and developing it in a Linux environment (WSL2). Do you know if this binding library works in Linux environments, or not? Thank you in advance.

    opened by yoching 1
  • better handling of minimum macOS version

    better handling of minimum macOS version

    Changes:

    • swift-rs now supports macOS 10.10 (OS X Yosemite) or higher
    • build::link_swift takes an argument for the minimum macOS version. Eg. build::link_swift("10.10");
    • Some docs

    Closes #3

    opened by oscartbeaumont 0
  • Issue with pointer being released

    Issue with pointer being released

    See downstream issue for more details: https://github.com/tauri-apps/tauri/issues/4314

    In theory, I think the memory management mechanism being used on the Swift side is the issue.

    https://github.com/Brendonovich/swift-rs/blob/1c309f652428ecc549fbe8eaccba4835a97d3aa8/src-swift/lib.swift#L66-L69

    It seems like memory is being freed twice.

    opened by lorenzolewis 1
Releases(0.3.0)
  • 0.3.0(Mar 27, 2022)

    New Features

    • Optional NSObject values are now supported (#4)
    • Objects created in Swift are now released when their Rust counterparts are dropped (#2)
    • Build script has been updated to support M1 Macs (#6)

    Changes

    • Build module has been renamed from build_utils to build and is behind corresponding Cargo feature (avoids requiring serde and serde_json to be included by default)
    • Serde support is now behind Cargo feature serde
    • getMounts example no longer leaks huge amounts of memory
    Source code(tar.gz)
    Source code(zip)
Owner
Typescript, Rust and a touch of Elixir
null
A cross-platform library of Swift utils to ease your iOS | macOS | watchOS | tvOS and Linux development.

Mechanica A library of Swift utils to ease your iOS, macOS, watchOS, tvOS and Linux development. Requirements Documentation Installation License Contr

Alessandro 28 Aug 28, 2022
Use this package in order to ease up working with Combine URLSession.

Use this package in order to ease up working with Combine URLSession. We support working with Codable for all main HTTP methods GET, POST, PUT and DELETE. We also support MultipartUpload

Daniel Mandea 1 Jan 6, 2022
Swift-friendly API for a set of powerful Objective C runtime functions.

ObjectiveKit ObjectiveKit provides a Swift friendly API for a set of powerful Objective C runtime functions. Usage To use ObjectiveKit: Import Objecti

Roy Marmelstein 850 Oct 25, 2022
Infix operators for monadic functions in Swift

Indecipherable symbols that some people claim have actual meaning. Please see the documentation for installation instructions. What's included? Import

thoughtbot, inc. 825 Dec 7, 2022
A set of helper classes and functions in Swift

SwiftTools This is a set of tools written in Swift that add some sugar and some small functionality. Mainly meant for small projects and scripts, as a

Vinicius Vendramini 0 Dec 13, 2021
Useful functions and extensions for sorting in Swift

SwiftSortUtils Motivation This library takes a shot at making comparing and sorting in Swift more pleasant. It also allows you to reuse your old NSSor

Daniel Strittmatter 60 Sep 9, 2022
Functional data types and functions for any project

Swiftx Swiftx is a Swift library containing functional abstractions and extensions to the Swift Standard Library. Swiftx is a smaller and simpler way

TypeLift 219 Aug 30, 2022
Utility functions for validating IBOutlet and IBAction connections

Outlets Utility functions for validating IBOutlet and IBAction connections. About Outlets provides a set of functions which validate that IBOutlets ar

Ben Chatelain 129 May 2, 2022
DGLabelSize - Functions that calculate the size of uilabel based on different string lengths

DGLabelSize Functions that calculate the size of uilabel based on different stri

donggyu 5 Jun 10, 2022
BCSwiftTor - Opinionated pure Swift controller for Tor, including full support for Swift 5.5 and Swift Concurrency

BCSwiftTor Opinionated pure Swift controller for Tor, including full support for

Blockchain Commons, LLC — A “not-for-profit” benefit corporation 4 Oct 6, 2022
Swift Markdown is a Swift package for parsing, building, editing, and analyzing Markdown documents.

Swift Markdown is a Swift package for parsing, building, editing, and analyzing Markdown documents.

Apple 2k Dec 28, 2022
Swift-DocC is a documentation compiler for Swift frameworks and packages aimed at making it easy to write and publish great developer documentation.

Swift-DocC is a documentation compiler for Swift frameworks and packages aimed at making it easy to write and publish great developer docum

Apple 833 Jan 3, 2023
Cross-Platform, Protocol-Oriented Programming base library to complement the Swift Standard Library. (Pure Swift, Supports Linux)

SwiftFoundation Cross-Platform, Protocol-Oriented Programming base library to complement the Swift Standard Library. Goals Provide a cross-platform in

null 620 Oct 11, 2022
Swift - ✏️Swift 공부 저장소✏️

Swift 스위프트의 기초 1. Swift의 기본 2. 변수와 상수 [3. 데이터 타입 기본] [4. 데이터 타입 고급] 5. 연산자 6. 흐름 제어 7. 함수 8. 옵셔널 객체지향 프로그래밍과 스위프트 9. 구조체와 클래스 10. 프로퍼티와 메서드 11. 인스턴스 생

Jiwon 0 Mar 9, 2022
Swift-ndi - Swift wrapper around NewTek's NDI SDK

swift-ndi Swift wrapper around NewTek's NDI SDK. Make sure you extracted latest

Alessio Nossa 12 Dec 29, 2022
__.swift is a port of Underscore.js to Swift.

__.swift Now, __.swift is version 0.2.0! With the chain of methods, __.swift became more flexible and extensible. Documentation: http://lotz84.github.

Tatsuya Hirose 86 Jun 29, 2022
SNTabBarDemo-Swift - Cool TabBar With Swift

SNTabBarDemo-Swift Cool TabBar How To Use // MARK: - setup private func setu

iAnchor 3 Sep 29, 2022
Swift-when - Expression switch support in Swift

Swift When - supporting switch expressions in Swift! What is it? Basically, it a

Gordan Glavaš 7 Nov 24, 2022
Swift-compute-runtime - Swift runtime for Fastly Compute@Edge

swift-compute-runtime Swift runtime for Fastly Compute@Edge Getting Started Crea

Andrew Barba 57 Dec 24, 2022