Skip to content

Cannot for the life of me get Xcode + Cargo to work #263

@AngeloMateus

Description

@AngeloMateus

After following the steps in Xcode + Cargo everything compiles and runs as expected until I call I a swift function from rust:

mod native/ios.rs:

#[swift_bridge::bridge]
mod ffi {
    extern "Rust" {
        #[swift_bridge(swift_name = "main_rs")]
        fn main();
    }
    extern "Swift" {
        #[swift_bridge(swift_name = "setAudioCategory")]
        fn set_audio_category();
    }
}

lib.rs:

pub fn main() {
    native::ios::set_audio_category();
}

myapp.swift

import Foundation
import AVFAudio

@main class MyAppIOS {
    static func main() throws {
        main_rs()
    }
}

func setAudioCategory() {
    do {
        try AVFAudio.AVAudioSession.sharedInstance().setCategory(.ambient);
    } catch {
        print("Couldn't set AVAudioSession category");
    }
}

The strange thing is if I don't call native::ios::set_audio_category(); everything within main runs properly so the extern "Rust" works.

The error I get is:

ld: Undefined symbols:
    ___swift_bridge__$set_audio_category, referenced from:
        ___swift_bridge__$main in myapp.my.8bdd3dadde1ac879-cgu.11.rcgu.o

The generated swift:

public func main_rs() {
    __swift_bridge__$main()
}
@_cdecl("__swift_bridge__$set_audio_category")
func __swift_bridge__set_audio_category () {
    setAudioCategory()
}

I've set the Library search paths to basically everything in target/ at this point I've added both debug and release libraries to Frameworks, Libraries and Embedded Content as well as withing Build Phases.
I'm not really sure what I'm missing, is there some way to debug this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions