dora-rs / dora

DORA (Dataflow-Oriented Robotic Architecture) is middleware designed to streamline and simplify the creation of AI-based robotic applications. It offers low latency, composable, and distributed dataflow capabilities. Applications are modeled as directed graphs, also referred to as pipelines.
https://dora-rs.ai
Apache License 2.0
1.5k stars 79 forks source link

Musl C lib support #564

Closed bobd988 closed 2 months ago

bobd988 commented 3 months ago

This may not be Dora specific, but there is a request to support OpenHarmony 4.x (OHOS). OHOS is not using glibc but musl C. Is there any solution that Dora can support operating system that uses musl C.

phil-opp commented 3 months ago

Have you tried compiling dora for a musl target, e.g. for x86_64-unknown-linux-musl? I just tried the following and it worked without error:

> rustup target install x86_64-unknown-linux-musl
> cargo build -p dora-cli --target x86_64-unknown-linux-musl
XxChang commented 3 months ago

I compile it with target "x86_64-unknown-linux-ohos", then I get an error

error[E0412]: cannot find type `IovLen` in this scope
   --> /xxxxxxx/.cargo/registry/src/mirrors.ustc.edu.cn-4affec411d11e50f/socket2-0.4.10/src/sys/unix.rs:837:63
    |
837 |     msg.msg_iovlen = min(bufs.len(), IovLen::MAX as usize) as IovLen;
    |                                                               ^^^^^^ not found in this scope

error[E0412]: cannot find type `IovLen` in this scope
   --> /xxxxxxxx/.cargo/registry/src/mirrors.ustc.edu.cn-4affec411d11e50f/socket2-0.4.10/src/sys/unix.rs:897:63
    |
897 |     msg.msg_iovlen = min(bufs.len(), IovLen::MAX as usize) as IovLen;
    |                                                               ^^^^^^ not found in this scope

error[E0433]: failed to resolve: use of undeclared type `IovLen`
   --> /xxxxxxx/.cargo/registry/src/mirrors.ustc.edu.cn-4affec411d11e50f/socket2-0.4.10/src/sys/unix.rs:837:38
    |
837 |     msg.msg_iovlen = min(bufs.len(), IovLen::MAX as usize) as IovLen;
    |                                      ^^^^^^ use of undeclared type `IovLen`

error[E0433]: failed to resolve: use of undeclared type `IovLen`
   --> /xxxxxxxxx/.cargo/registry/src/mirrors.ustc.edu.cn-4affec411d11e50f/socket2-0.4.10/src/sys/unix.rs:897:38
    |
897 |     msg.msg_iovlen = min(bufs.len(), IovLen::MAX as usize) as IovLen;
    |                                      ^^^^^^ use of undeclared type `IovLen`

It seems like that socket2-0.4.10 had not supported ohos yet (these should be supported in socket2-0.5.*). Too many crates are depend on it.

Please check https://github.com/rust-lang/socket2/issues/451

In addition, to support ohos, we should modify the rust-toolchain.toml. rust-1.76 does not support x86_64-unknown-linux-ohos.

phil-opp commented 3 months ago

It seems like that socket2-0.4.10 had not supported ohos yet (these should be supported in socket2-0.5.*). Too many crates are depend on it.

Please check rust-lang/socket2#451

Ok, looks like we need to update some dependencies then.

In addition, to support ohos, we should modify the rust-toolchain.toml. rust-1.76 does not support x86_64-unknown-linux-ohos.

Is the version too new or too old? The target was addedd in https://github.com/rust-lang/rust/pull/113061 , so it should be available in 1.76. If it's too old, you can easily compile the latest stable version using cargo +stable build or cargo +stable install. We don't want to change the rust-toolchain.toml currently because we don't want to accidentally use features that force users to use the very latest Rust version.

phil-opp commented 3 months ago

I just tried ` and the main error source seems to be the nix 0.23 dependency of https://docs.rs/raw_sync_2/latest/raw_sync_2/ . We probably need to update that crate to the latestnix` version.

@haixuanTao You are author of the crates.io crate, but its repo link still points to the upstream repo. What is the repo of the forked crate?

XxChang commented 3 months ago

Is the version too new or too old? The target was addedd in rust-lang/rust#113061 , so it should be available in 1.76. If it's too old, you can easily compile the latest stable version using cargo +stable build or cargo +stable install. We don't want to change the rust-toolchain.toml currently because we don't want to accidentally use features that force users to use the very latest Rust version.

I just type rustup target list | grep ohos, nothing works with rust 1.76.

phil-opp commented 3 months ago

Ah, looks like the stdlib is only available since https://github.com/rust-lang/compiler-team/issues/719, which was released with rust 1.78. The cargo +stable commands I mentioned above should work though.

Gege-Wang commented 2 months ago

for rk3568 is armv7, we should use musl libc.

docker pull messense/rust-musl-cross:armv7-musleabi
docker run --rm -it -v "$(pwd)":/home/rust/src messense/rust-musl-cross:armv7-musleabihf bash
rustup target add armv7-unknown-linux-musleabi
cargo build -p dora-cli --release --target armv7-unknown-linux-musleabi

so we can move ./dora/target/armv7-unknown-linux-musleabi/release/dora to rk3568. another note: we should use dynamic link with C node

/path/to/dora/.cargo/config.toml
[target."armv7-unknown-linux-musleabi"]
rustflags = "-C target-feature=-crt-static"

and move libgcc_s.so.1 to rk3568:/lib

# in above docker container
the libgcc_s.so.1 path is  /usr/local/armv7-linux-musleabi/lib/libgcc_s.so.1 
haixuanTao commented 2 months ago

I can add arm-musl in our next github release so that it is easier to use dora within arm ohos.