-
-
Notifications
You must be signed in to change notification settings - Fork 470
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
support for musl environment #619
Conversation
602407c
to
45f2cc7
Compare
The script that generates this out is this one here: https://github.com/mitsuhiko/rye/blob/main/rye/find-downloads.py I would like to avoid the term "toolchain" here as this term is already used to refer to the python installations itself. I'm not sure what a good term is, but toolchain probably not. |
Rust uses the term |
This appears to be a common structure for target triples: https://docs.rs/target-lexicon/latest/target_lexicon/struct.Triple.html
What this refers to is in fact called |
I'll change it to |
efb8627
to
db63433
Compare
rebased |
rebased again |
Playing with this still. Pretty determined to merge but I need to figure out how this actually plays out in practice still. |
bff21bc
to
d76c72f
Compare
I'm temporarily holding on until I have the test system in place. Refs #687 |
I am adding tests for this. There is a problem that currently makes using Indygreg's python3 musl packages unusable for rye:
There are patches for this in indygregs repo, but they don't affected the bundled wheel which ensurepip uses during bootstrapping. Standard alpine musl python allows dynamic loading and hence is not affected. Putting this on hold until it's resolved upstream, or someone has a good idea how to go about it. |
@dsp it would be interesting to know if |
1b510d5
to
264a4c7
Compare
827a652
to
c6c3909
Compare
Okay, I hope this is finally ready. I updated the description. Manually tested on Alpine Linux, but not tested on a GNU system with musl installed. |
6cc3f41
to
0a88940
Compare
I would like to push out the current main branch of rye as a release, and then schedule this to go into the release after. The current changes are mostly bugfixes. |
@mitsuhiko Thank you! Looking forward to having it in! I'll rebase it one more time today. Note that likely the merge will fail if you update uv releases or python releases in between. You would have to regenerate them. |
Linux and in rare cases windows binaries can be built with different environments. At the moment rye assumes we will be always using a gnu environment on linux. This is not true for distributions like Alpine, which use musl instead of glibc. Indygreg offers musl builds, but we don't pull them in just yet. 1. We introduce the notion of a "environment", which can either be unset (None) or set to a string. 2. We set the environment string to Some("gnu") for all existing linux downloads 3. We set the environment string to None for all others 4. We modified match_versions to correctly resolve environment or fallback to the default environment (Some("gnu") for linux, None for all others). 5. We added tests.
We are using the target environment to select the requested cpython version. Since `std::env::consts` does not offer a way to select the target os on runtime, we are having to find a suitable way. This implies that a rye version build for musl will pull a musl toolchain by default and a rye version for gnu will will pull a gnu toolchain. In general this should work. On a fully musl system such as alpine, you wouldn't have a system that is compatible with gnu anyway and on a GNU system you would just always pull a musl toolchain which will work.
Alpine Linux builds will fail for a `static-ssl`. Instead we must link against system openssl. We now introduce a feature set that allows to link against system ssl using `--no-default-features --features system-ssl`. For a musl system, you also must specify RUSTFLAGS="-C target-feature=-crt-static". The alternative approach is to use using a `[target.'cfg(target_env="musl")'.dependencies]` specification, that selects features based on the `target_env`. However since we are currently using the Cargo resolver 1, this does not work. We would need to switch to resolver 2. In general the feature selection is more versatile since we ask users to select the appropriate set for their platform.
Thanks @dsp for working on this |
olps, this one doesnt make it in 0.33.0 release :( |
If someone wants to pick it up, rebase and check why the test is failing, please go ahead. I still think this is valuable but won't have time to work on it. Since I am personally not running Alpine, it's not too relevant for me (although a bit sad since I poured quite a bit of time into it) |
I also assume we have it wait for @mitsuhiko to be back. I think it's quite a big and scary feature, so I totally see why it is not merged currently while @charliermarsh is helping out with more straight forward PRs. |
Since there is no more traction since a while I am going to close it out. |
uv seems to have support for musl environment, so I hope it will carry the torch. |
In theory we could always use the uv musl builds which would simplify some things. (We already use them always for ARM Linux.) Do we also need to change the deployment pipeline to ship a musl build of Rye? |
I think there are a few pieces to the puzzle if i remember correctly:
I think the PR dealt with basically 1 and 2, but didn't care about Rye support for musl just yet. My position was a bit like: musl rare enough that we should just disable auto-update and have it |
This is an experimental pull request aimed to support environments.
Problem
Linux and in rare cases windows binaries can be built with different environments. At the moment rye assumes we will be always using a gnu environment on linux. This is not true for distributions like Alpine, which use musl instead of glibc. Hence, rye currently does not support Alpine Linux.
Approach
This PR introduces the notion of an environment to our internal handling of python versions and python version requests. It extends the version matching to include environments, and modifies our download link creators for uv and cypthon builds to include the environment. Lastly, it changes how we link libcurl to make builds for Alpine linux working.
Once the PR is merged, we can build and use rye on alpine.
Notable, there are some caveats to the current implementation. I decided to do this in multiple PRs to not overload the PR with more.
Status of implementation
default_toolchain
based on thetarget_env
, so based on the target triple rye was build for. This is deliberate, as we have no easy way to find the target_env at runtime (e.g. a system that provides both gnu and musl, is completely valid on Linux).Caveats
Missing CI integration
There is currently not CI integration for Alpine linux or one that links against musl on Ubuntu. However, we did manually test it.
Python Storage Paths
We currently still save python into
[RYE_HOME]/py/[email protected]
. This can lead to problems where a user would have a both a musl and a gnu version. It is something that we should support, particularly when we allow users to more easily select their environments within a project. However it is out of scope of the current PR.User selected environments
Users cannot easily select a python version for a specific environment. For example
rye pin cpython-linux-musl
doesn't work. we should make this work in the future.