Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Musl C lib support #564

Closed
bobd988 opened this issue Jun 24, 2024 · 8 comments
Closed

Musl C lib support #564

bobd988 opened this issue Jun 24, 2024 · 8 comments

Comments

@bobd988
Copy link
Contributor

bobd988 commented Jun 24, 2024

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
Copy link
Collaborator

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
Copy link
Collaborator

XxChang commented Jun 29, 2024

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 rust-lang/socket2#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
Copy link
Collaborator

phil-opp commented Jul 1, 2024

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 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.

@phil-opp
Copy link
Collaborator

phil-opp commented Jul 1, 2024

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 latest nix 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
Copy link
Collaborator

XxChang commented Jul 1, 2024

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
Copy link
Collaborator

phil-opp commented Jul 1, 2024

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

@Gege-Wang
Copy link
Collaborator

Gege-Wang commented Jul 4, 2024

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
Copy link
Collaborator

haixuanTao commented Jul 4, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants