rust-lang / rustup

The Rust toolchain installer
https://rust-lang.github.io/rustup/
Apache License 2.0
6.04k stars 879 forks source link

OpenBSD support #2168

Open 0x4d6165 opened 4 years ago

0x4d6165 commented 4 years ago

I would absolutely love it if rustup had OpenBSD support. We're still pretty similar to NetBSD and rust is available on OpenBSD so it shouldn't be too difficult to port.

rbtcollins commented 4 years ago

So - start by building rustup yourself - if that works, and that channel metadata for rust distributions has everything you need, then this ticket becomes 'please make rustup binaries available for download'. If it doesn't build / run properly, we can help you with that, and if the channel metadata or the rust distributions are missing things we can steer you in the right direction.

0x4d6165 commented 4 years ago

Hmm tried running cargo run --release and got

error: Pre-checks for host and toolchain failed: Provided host 'x86_64-unknown-openbsd' couldn't be converted to partial triple
If you are unsure of suitable values, the 'stable' toolchain is the default.
Valid host triples look something like: x86_64-unknown-openbsd
rbtcollins commented 4 years ago

Ok, so thats the starting point - you'll need to teach the host triple detection about openbsd. I don't have the source handy just now, but as you said NetBSD was similar I suggest grepping for NetBSD in the source.

kinnison commented 4 years ago

OpenBSD is all tier 3 at this time, which means the required dockers for rustup to build will not be available since they are not produced for tier 3 platforms as I understand it. If I'm wrong then in theory we could add support to our CI to test these platforms at least, even if we're not ready to release yet.

mneumann commented 4 years ago

@kinnison I use DragonFly, which is not supported as well. You should still be able to install rustup locally!

Clone rustup source and run (if it fails to build, see my branch):

cargo run -- --default-host x86_64-unknown-freebsd -y

This will download and install the FreeBSD binaries. We don't need them, but rustup can't just install itself without downloading anything. IMHO, would be great if this would be fixed in rustup.

If you would now run $HOME/.cargo/bin/rustc, you would run the FreeBSD binaries... not good. That's why we have to tell rustup about the rust toolchain from ports (I assume this is in /usr/local on OpenBSD):

$HOME/.cargo/bin/rustup toolchain link ports-toolchain /usr/local
$HOME/.cargo/bin/rustup default ports-toolchain

If you now run $HOME/.cargo/bin/rustc, you run the OpenBSD rustc.

If you can, don't install rustc etc. into /usr/local. Install it into some directory which is not in your PATH.

Hope this helps! Good luck!

mneumann commented 4 years ago

@kinnison If you want to use rustup for cross-compilation: "rustup target add ..." does not work when the ports-toolchain is activated. The workaround is to switch to the freebsd toolchain, install the target, and switch back.

reynoldsbd commented 3 years ago

Using @mneumann's guidance, I was able to get rustup to build and install on OpenBSD. Thanks!

Unfortunately, the binary fails immediately due to rust-lang/rust#60560. I am going to reach out to the OpenBSD port maintainer to try and find a solution here. In the meantime, one can work around by setting a shell alias to rustup's absolute path:

$ alias rustup=$HOME/.cargo/bin/rustup

@kinnison regarding OpenBSD being tier-3, are you aware of any ongoing conversations to change that? I would love to get involved here :)

semarie commented 3 years ago

OpenBSD is a 3-tier platform for several reasons:

rogerxxxx commented 3 years ago

Be aware. Rust bootstrap requires SSE2, most Pentium3 (i686) and earlier CPU's do not have SSE2 CPU register, resulting in segmentation faults. Can workaround this by building the rust bootstrap yourself, while most distributions now rely upon rust prebuilts SSE2 bootstraps. I've yet to see any explanation within the past year as to this requirement.

shaneutt commented 3 years ago

I'm interested in potentially working on this, can someone help me put together a TODO list of what it will take to get OpenBSD support added?

semarie commented 3 years ago

@shaneutt the first steps would be:

next, there are unsupported things like @reynoldsbd mentioned (env::current_exe for example).

workingjubilee commented 3 years ago

@rustbot label: +O-bsd

shaneutt commented 3 years ago

I did end up digging into this, but I've had to drop it due to other life priorities. The patches to llvm/libc are the bigger painpoints there in terms of the amount of time that needs to be dedicated to this.

hargoniX commented 2 years ago

I'd like to look into this as well, @shaneutt did you end up pushing some results into some repository? Or could you share your insights into the problem in general maybe?

shaneutt commented 2 years ago

I'd like to look into this as well, @shaneutt did you end up pushing some results into some repository? Or could you share your insights into the problem in general maybe?

I only made it as far as coming to understand how the FreeBSD support was added as a frame of reference. I can recommend you doing the same, but beyond that I have nothing meaningful to contribute.

xmawja commented 2 years ago

i found this script may help you out.

grinsingularity commented 1 year ago

I use OpenBSD v7.2 and trying to build https://github.com/mimblewimble/grin

hargoniX commented 1 year ago

It seems people are making progress with respect to OpenBSD in Github CI: https://github.com/mario-campos/emulate could this be used to properly compile rustc binaries in the CI for our purposes?

shaneutt commented 1 year ago

It seems people are making progress with respect to OpenBSD in Github CI: https://github.com/mario-campos/emulate could this be used to properly compile rustc binaries in the CI for our purposes?

So this seems really cool, but as I understand it the bigger barrier to entry for official support are the fairly large sized things pointed out in https://github.com/rust-lang/rustup/issues/2168#issuecomment-815507459.

That said, maybe "unofficial support" is something we could aim for? If I'm understanding things correctly, we might be able to use something like this to create an unofficial rustup repository and generate and host OpenBSD Rust builds as an interim solution?

workingjubilee commented 1 year ago

-Zbuild-std now works for some targets, so that could be used as an initial basis once the compiler issues are sorted.

sbourdeauducq commented 6 months ago

Note that many of the limitations of the Rust compiler from the OpenBSD ports (or any other "stable" Rust package) are arbitrary and self-inflicted, and can often be worked around by setting the magic environment variable RUSTC_BOOTSTRAP=1. This is much faster than trying to get rustup to work.

sbourdeauducq commented 6 months ago

Example building an ARM MCU embedded project with rustc from OpenBSD ports:

  1. get rid of another arbitrary, frustrating check in cargo-xbuild:
    
    diff --git a/src/lib.rs b/src/lib.rs
    index 204ad8f..9c61e39 100644
    --- a/src/lib.rs
    +++ b/src/lib.rs
    @@ -157,28 +157,11 @@ pub fn build(args: Args, command_name: &str, crate_config: Option<Config>) -> Re
         })
     })?;

Of course none of this would be necessary if the Rust policy was to treat users like adults.