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

Improving MIPS and MIPSEL support (regarding AtomicU64 and Rust Version) #1460

Open
humaita-github opened this issue Jan 28, 2025 · 9 comments

Comments

@humaita-github
Copy link
Contributor

Hi,

up to including version 0.6. libresport can be compiled for MIPS and MIPSEL targets (to be more precise: mips-unknown-linux-musl and mipsel-unknown-linux-musl). This is useful for routers running OpenWRT, since many of them are based on these targets.

However, there are 2 issues that make it difficult to compile:

1) AtomicU64: MIPS and MIPSEL [and PowerPC (?)] don't support this, since they are 32 bit. However, there is a crate that provides shims for these platforms. When it detects it is running on unsupported platforms, it fallbacks to the shim implementation, using crossbeam Mutex. For supported platforms, there should be no change.

This can easily be implemented by changing the 1st line in ./playback/src/mixer/softmixer.rs from

use std::sync::atomic::{AtomicU64, Ordering};

to

use atomic_shim::AtomicU64;
use std::sync::atomic::{Ordering};

2) Rust Version: librespot v0.6. defaults to Rust version 1.75. However, in this version both MIPS and MIPSEL were moved to Tier 3. librespot v0.6 still builds fine with Rust version 1.74 -- so I suggest sticking to this version for a bit longer. I know, sounds like a big decision, but this will keep librespot viable for OpenWRT routers for a longer period of time.

This can easily be implemented by changing the 4th line in ./Cargo.toml from

rust-version = "1.75"

to

rust-version = "1.74"

FYI: There is one more thing: OpenSSL headers are missing for MIPS, but this is currently being fixed somewhere else, see
aws/aws-lc#2143

I didn't create a patch or similar since only 2 lines of code need to be changed (and since I don't really know the proper way of doing this).

@photovoltex
Copy link
Member

  1. AtomicU64: MIPS and MIPSEL [and PowerPC (?)] don't support this, since they are 32 bit. However, there is a crate that provides shims for these platforms. When it detects it is running on unsupported platforms, it fallbacks to the shim implementation, using crossbeam Mutex. For supported platforms, there should be no change.

Feel free to open a PR with these changes. Sounds like nothing major and it seems somewhere crossbeam-utils is already in use, so it might not make a big difference as dependency.

  1. Rust Version: librespot v0.6. defaults to Rust version 1.75. However, in this version both MIPS and MIPSEL were moved to Tier 3. librespot v0.6 still builds fine with Rust version 1.74 -- so I suggest sticking to this version for a bit longer. I know, sounds like a big decision, but this will keep librespot viable for OpenWRT routers for a longer period of time.

We recently bumped the MSRV to 1.81 because of some dependency and an CI tools requirements. Which means that downgrading would come with some rollbacks of crate versions and a different fix for our CI. Does rust-version > 1.74 block compiling all together, or what exactly is the current state of things there?

@roderickvd
Copy link
Member

First of all thanks for opening my eyes to who and why is using librespot on MIPS 😆

Just to throw it out there, in CamilaDSP style we could also introduce a pub type ProcessingFormat that could be an alias to either 32 or 64 bit.

@humaita-github
Copy link
Contributor Author

Hi @photovoltex , hi @roderickvd ,

thank you for the quick reply.

> Feel free to open a PR with these changes.
Will do.

> Does rust-version > 1.74 block compiling all together, or what exactly is the current state of things there?
AFAIK it blocks compiling all together (at least I haven't found a way to compile a Tier 3 rust target).

> CamilaDSP style we could also introduce a pub type ProcessingFormat that could be an alias to either 32 or 64 bit.
I am open for that (but I wouldn't know hot to do something like that myself.

@photovoltex
Copy link
Member

photovoltex commented Jan 29, 2025

AFAIK it blocks compiling all together (at least I haven't found a way to compile a Tier 3 rust target).

Ugh, what a bummer. Well I did a look into the work that needs to be done:

  • dropping to 1.75 is pretty straight forward, by just reverting the related commit
    • the CI needs to be fixed as cargo-hack required 1.81
  • dropping to 1.75 is the actual problem

@starypatyk
Copy link
Contributor

FYI - I suggested to remove MIPS target from the Docker image used to cross-compile at #1299. At that time I had issues even with 1.73.

@photovoltex
Copy link
Member

Wouldn't that mean 0.5 also had problems to compile under MIPS? Which was the last version that did compile under MIPS @humaita-github?

@humaita-github
Copy link
Contributor Author

Hi, yes, version 0.5 has the same problem. I just used to patch it locally on my machine, with

sed -i '1d' ./playback/src/mixer/softmixer.rs
sed -i '1s/^/use atomic_shim::AtomicU64;\nuse std::sync::atomic::{Ordering};\n/' ./playback/src/mixer/softmixer.rs
echo -e '\n[dependencies.atomic-shim]\natomic-shim = "*"\n' >> playback/Cargo.toml

And this is more or less what I submitted as a PR 3 days ago.

Previous versions (e.g. 0.42) have the same issue. I think AtomicU64 was introduced with commit fe2d5ca7c654cd5981969ae880ccd69e6d1066d3 in 2021 -- before I started using librespot.

@photovoltex
Copy link
Member

I'm referring to the rust-version downgrade that you suggested so that we could compile for MIPS again. If it's, as @starypatyk pointed out, and even 1.73 will not compile, I would see this as difficult problem to solve.

@humaita-github
Copy link
Contributor Author

humaita-github commented Feb 1, 2025

Hi, I have no issues compiling versions 0.42 and 0.50 with rust 1.74 on MIPS and MIPSEL. And as mentioned already, version 0.60 compiles fine with rust 1.74 even if it requires 1.75, you can just patch the Cargo.toml` file:

sed -i 's/rust-version = \"1.75\"/rust-version = \"1.74\"/' Cargo.toml

Compiling version 0.60 for MIPS is a bit more tricky, since openssl is missing a the MIPS headers. For now you can fix it manually, and this has already been fixed for upcoming versions, see the link in my first message.

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

No branches or pull requests

4 participants