-
Hi 👋 I stumbled across this project when researching OpenUSD bindings for Rust, and I noticed that this project uses Rust as well. Poking around in the code appeared to show some kind of Rust Swift interop, but I can't find where the actual C++ interop is? The main thing I'm wondering is, does this project use OpenUSD Rust bindings? And if not, what does it use? Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Hey there @beeeeep54! This repo does not currently offer any Rust/C++ interop, the code found here is some experimentation with Swift/Rust interop, and that example is only related to one of OpenUSD's dependencies Ptex, that is - this line of Swift, calling directly into (Ptex) C++ code being called from Rust through swift-bridge to convert a Rust If you're interested in OpenUSD Rust bindings you can find that here, @scott-wilson is the best resource for more information on that, and you can find him on the ASWF slack rust channel. If you're interested in how interoperability is working between Swift and OpenUSD's C++ codebase, here is how Swift/C++ interop works. Steps to do this easily...
mkdir MyApp
cd MyApp
swift package init
Sources/
MyCxx/
include/
MyCxx.h
MyCxx.cpp
// swift-tools-version: 5.10
import PackageDescription
let package = Package(
name: "MyApp",
platforms: [
.macOS(.v14),
.visionOS(.v1),
.iOS(.v17),
.tvOS(.v17),
.watchOS(.v10)
],
targets: [
.target(
name: "MyCxx"
),
.executableTarget(
name: "MyApp",
dependencies: [
.target(name: "MyCxx")
],
swiftSettings: [
// enable c++ interop.
.interoperabilityMode(.Cxx)
]
)
],
// set c++ language standard.
cxxLanguageStandard: .cxx17
)
// MyCxx.h
#pragma once
void doSomething(); // MyCxx.cpp
#include "MyCxx.h"
#include <stdio.h>
void doSomething()
{
printf("Hello from C++!\n");
}
import MyCxx
@main
struct MyApp {
static func main() {
doSomething() // should print "Hello from C++!"
}
}
swift run
# "Hello from C++!" Hopefully that helps! Cheers 👋🏻. |
Beta Was this translation helpful? Give feedback.
-
Thanks so much for the help! |
Beta Was this translation helpful? Give feedback.
Hey there @beeeeep54! This repo does not currently offer any Rust/C++ interop, the code found here is some experimentation with Swift/Rust interop, and that example is only related to one of OpenUSD's dependencies Ptex, that is - this line of Swift, calling directly into (Ptex) C++ code being called from Rust through swift-bridge to convert a Rust
u32
unsigned integer to it's equivalentPtex.MeshType
enum value, more as a "simple, dumb, test".If you're interested in OpenUSD Rust bindings you can find that here, @scott-wilson is the best resource for more information on that, and you can find him on the ASWF slack rust channel.
If you're interested in how interoperability is working betwe…