This message was deleted.
# sdk-rust
s
This message was deleted.
d
đź‘‹ Owen. the C++ SDK is a work-in-progress. Which version of rust sdk are you building with? This might be due to updates to the Rust side that's not properly ported back yet.
m
Thanks for the reply @dry-elephant-14928. I was hoping to explore interop between the rust SDK and C++. We have a large project that will require some basic client functions in C (mainly data channel send/receive). I had checked out the c++ SDK from “main” and then did a submodule init to get: HEAD detached at 1344666 In theory this should be what was working when committed. The last couple commits from the rust sdk were:
d
Got it. Apologies for the trouble here. At the moment a more reliable path would be to build with Rust directly.. and then linking that higher level component into your C++ application. Currently the cpp bridge would still require a lot of work in both functionality and compilation toolchain
m
@dry-elephant-14928 thanks for the help. It does seem that the C++ SDK is still a ways off. Do you happen to know of any resources/documentation on calling tokio async functions from C++? That has been a bit of challenge so far. Or is there possibly a better approach that you would recommend?
d
I was thinking writing some of the logic in Rust, including running the async runloop. Then calling that entrypoint function from C++
m
@dry-elephant-14928, yeah I am following. I am able to get a tokio working well enough to run async functions, use reqwest, and I am just now trying to get livekit working. Hoping it works out. I appreciate the assist.
👍 1
d
sounds good! I hope it works 🤞
m
Ok, I may need another assist. I am encountering a familiar error when building on MacOS.
This is typically caused by the -Objc rustflags not being set.
I have double and triple checked that the flags are currently set and livekit was built using the flags. I am also working out of the examples dir from the git repo which I have compiled other rust applications from. For whatever reason, when compiling a static library and then using that in c++ livekit throws this error. I have used rustc’s --print native-static-libs to get all of the dependencies and ensured those are all included.
Copy code
g++ -L/Library/Developer/CommandLineTools/usr/lib/clang/14.0.3/lib/darwin -L../target/debug -framework Foundation -framework AVFoundation -framework CoreAudio -framework AudioToolbox -framework Appkit -framework CoreMedia -framework CoreGraphics -framework VideoToolbox -framework CoreVideo -framework OpenGL -framework Metal -framework QuartzCore -framework IOKit -framework IOSurface -lclang_rt.osx -lc++ -framework Security -framework CoreFoundation -liconv -lSystem -lc -lm -lc_test_lib  test.cpp -o test
When the library is built you can see that the -C link-args are included:
Copy code
CARGO=/Users/owen.shoemaker/.rustup/toolchains/stable-aarch64-apple-darwin/bin/cargo CARGO_CRATE_NAME=c_test_lib CARGO_MANIFEST_DIR=/Users/owen.shoemaker/Repos/client-sdk-rust/examples/c_test_lib CARGO_PKG_AUTHORS='' CARGO_PKG_DESCRIPTION='' CARGO_PKG_HOMEPAGE='' CARGO_PKG_LICENSE='' CARGO_PKG_LICENSE_FILE='' CARGO_PKG_NAME=c_test_lib CARGO_PKG_README='' CARGO_PKG_REPOSITORY='' CARGO_PKG_RUST_VERSION='' CARGO_PKG_VERSION=0.1.0 CARGO_PKG_VERSION_MAJOR=0 CARGO_PKG_VERSION_MINOR=1 CARGO_PKG_VERSION_PATCH=0 CARGO_PKG_VERSION_PRE='' CARGO_PRIMARY_PACKAGE=1 DYLD_FALLBACK_LIBRARY_PATH='/Users/owen.shoemaker/Repos/client-sdk-rust/examples/target/debug/deps:/Users/owen.shoemaker/.rustup/toolchains/stable-aarch64-apple-darwin/lib:/Users/owen.shoemaker/.rustup/toolchains/stable-aarch64-apple-darwin/lib:/Users/owen.shoemaker/lib:/usr/local/lib:/usr/lib' /Users/owen.shoemaker/.rustup/toolchains/stable-aarch64-apple-darwin/bin/rustc --crate-name c_test_lib --edition=2021 c_test_lib/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=532 --crate-type staticlib --emit=dep-info,link -C embed-bitcode=no -C debuginfo=2 -C split-debuginfo=unpacked -C metadata=7e5c89ea054c0aa6 -C extra-filename=-7e5c89ea054c0aa6 --out-dir /Users/owen.shoemaker/Repos/client-sdk-rust/examples/target/debug/deps -C incremental=/Users/owen.shoemaker/Repos/client-sdk-rust/examples/target/debug/incremental -L dependency=/Users/owen.shoemaker/Repos/client-sdk-rust/examples/target/debug/deps --extern livekit=/Users/owen.shoemaker/Repos/client-sdk-rust/examples/target/debug/deps/liblivekit-d857964e6870397d.rlib --extern reqwest=/Users/owen.shoemaker/Repos/client-sdk-rust/examples/target/debug/deps/libreqwest-ff8d1aed831e5e64.rlib --extern serde=/Users/owen.shoemaker/Repos/client-sdk-rust/examples/target/debug/deps/libserde-e076e87b15861fe7.rlib --extern serde_json=/Users/owen.shoemaker/Repos/client-sdk-rust/examples/target/debug/deps/libserde_json-f670849d9e66653f.rlib --extern tokio=/Users/owen.shoemaker/Repos/client-sdk-rust/examples/target/debug/deps/libtokio-507ff7c85f70d586.rlib -C link-args=-ObjC -L native=/Users/owen.shoemaker/Repos/client-sdk-rust/examples/target/debug/build/ring-c3409cdf04ec0ded/out -L native=/Users/owen.shoemaker/Repos/client-sdk-rust/examples/target/debug/build/cxx-6c47fb7fefc63943/out -L native=/Users/owen.shoemaker/Repos/client-sdk-rust/examples/target/debug/build/link-cplusplus-2f36d7983f127566/out -L native=/Users/owen.shoemaker/Repos/client-sdk-rust/examples/target/debug/build/scratch-1361ce0548d5aa70/out/livekit_webrtc/livekit/webrtc-mac-arm64-release-webrtc-fcdef0d/webrtc-mac-arm64-release/lib -L /Library/Developer/CommandLineTools/usr/lib/clang/14.0.3/lib/darwin -L native=/Users/owen.shoemaker/Repos/client-sdk-rust/examples/target/debug/build/webrtc-sys-96683824efdbb772/out`
@boundless-energy-78552 or @dry-elephant-14928 do you have any ideas? I am scraping the bottom of the barrel for ideas…
b
Hey, make sure to use this config
m
@boundless-energy-78552 I am on macos though…
b
yes, it does include macos rustflags
m
I am using this rustflag: owen.shoemaker@ow3nd c_test_lib % cat ../../.cargo/config [target.x86_64-pc-windows-msvc] rustflags = [“-C”, “target-feature=+crt-static”] [target.aarch64-pc-windows-msvc] rustflags = [“-C”, “target-feature=+crt-static”] [target.x86_64-apple-darwin] rustflags = [“-C”, “link-args=-ObjC”] [target.aarch64-apple-darwin] rustflags = [“-C”, “link-args=-ObjC”] [target.aarch64-apple-ios] rustflags = [“-C”, “link-args=-ObjC”] [target.aarch64-apple-ios-sim] rustflags = [“-C”, “link-args=-ObjC”]%
b
yes it should be fine
make sure cargo is correctly using it
m
I have verified by runing cargo build -vv and looked at the rustc command (listed above). You can see the linker args. Other executables run fine built in the same env. For whatever reason the lib.rs gets the same issue as if the linker args weren’t set.
b
are you building a dynamic library?
oh no a static lib
m
Yeah, building a static lib.
b
so if you’re using a static lib, the -ObjC flag should be added on your CMake config
or whatever C build system your’re using
m
I am building the static lib with “cargo build”
b
yes but how are you using it?
m
Building using g++ and statically linking to .a
Copy code
g++ -L/Library/Developer/CommandLineTools/usr/lib/clang/14.0.3/lib/darwin -L../target/debug -framework Foundation -framework AVFoundation -framework CoreAudio -framework AudioToolbox -framework Appkit -framework CoreMedia -framework CoreGraphics -framework VideoToolbox -framework CoreVideo -framework OpenGL -framework Metal -framework QuartzCore -framework IOKit -framework IOSurface -lclang_rt.osx -lc++ -framework Security -framework CoreFoundation -liconv -lSystem -lc -lm -lc_test_lib  test.cpp -o test
b
yes so I think you can add your -ObjC flag to this cmd
does it work doing that?
I’m not sure if we can directly add the ObjC flag to a staticlib
m
if I add the -ObjC to g++ I get:
Copy code
test.cpp:1:10: fatal error: 'iostream' file not found
#include <iostream>
         ^~~~~~~~~~
b
mmh can you try
g++ -x objective-c++
then
-lobjc
if needed
m
That results in the same NSException unfortunately.
Ah, let me try that.
YES!
b
nice 🙂
m
Rad, thanks so much for the help. 👏🍻
🙏 1
🍻 1