This commit is contained in:
Matěj Volf 2025-04-13 13:25:39 +02:00 committed by GitHub
commit c6b0c6710f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 137 additions and 2 deletions

View File

@ -0,0 +1,14 @@
use crate::spec::{PanicStrategy, RelroLevel, TargetOptions};
pub(crate) fn opts() -> TargetOptions {
TargetOptions {
os: "helenos".into(),
dynamic_linking: true,
has_rpath: true,
relro_level: RelroLevel::Full,
panic_strategy: PanicStrategy::Abort,
..Default::default()
}
}

View File

@ -8,6 +8,7 @@ pub(crate) mod dragonfly;
pub(crate) mod freebsd;
pub(crate) mod fuchsia;
pub(crate) mod haiku;
pub(crate) mod helenos;
pub(crate) mod hermit;
pub(crate) mod hurd;
pub(crate) mod hurd_gnu;

View File

@ -1838,6 +1838,9 @@ supported_targets! {
("i686-unknown-haiku", i686_unknown_haiku),
("x86_64-unknown-haiku", x86_64_unknown_haiku),
("i686-unknown-helenos", i686_unknown_helenos),
("x86_64-unknown-helenos", x86_64_unknown_helenos),
("i686-unknown-hurd-gnu", i686_unknown_hurd_gnu),
("x86_64-unknown-hurd-gnu", x86_64_unknown_hurd_gnu),

View File

@ -0,0 +1,26 @@
use crate::spec::{Cc, LinkerFlavor, Lld, StackProbeType, Target, base};
pub(crate) fn target() -> Target {
let mut base = base::helenos::opts();
base.cpu = "pentium4".into();
base.max_atomic_width = Some(64);
base.stack_probes = StackProbeType::Inline;
base.linker = Some("i686-helenos-gcc".into());
base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m32"]);
Target {
llvm_target: "i686-unknown-helenos".into(),
metadata: crate::spec::TargetMetadata {
description: Some("IA-32 (i686) HelenOS".into()),
tier: Some(3),
host_tools: Some(false),
std: None,
},
pointer_width: 32,
data_layout: "e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-\
i128:128-f64:32:64-f80:32-n8:16:32-S128"
.into(),
arch: "x86".into(),
options: base,
}
}

View File

@ -0,0 +1,26 @@
use crate::spec::{Cc, LinkerFlavor, Lld, StackProbeType, Target, base};
pub(crate) fn target() -> Target {
let mut base = base::helenos::opts();
base.cpu = "x86-64".into();
base.plt_by_default = false;
base.max_atomic_width = Some(64);
base.stack_probes = StackProbeType::Inline;
base.linker = Some("amd64-helenos-gcc".into());
base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m64"]);
Target {
llvm_target: "x86_64-unknown-helenos".into(),
metadata: crate::spec::TargetMetadata {
description: Some("64-bit HelenOS".into()),
tier: Some(3),
host_tools: Some(false),
std: None,
},
pointer_width: 64,
data_layout:
"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128".into(),
arch: "x86_64".into(),
options: base,
}
}

View File

@ -33,6 +33,8 @@ pub struct Finder {
//
// Targets can be removed from this list once they are present in the stage0 compiler (usually by updating the beta compiler of the bootstrap).
const STAGE0_MISSING_TARGETS: &[&str] = &[
"i686-unknown-helenos",
"x86_64-unknown-helenos",
// just a dummy comment so the list doesn't get onelined
];

View File

@ -105,6 +105,7 @@
- [solaris](platform-support/solaris.md)
- [\*-nto-qnx-\*](platform-support/nto-qnx.md)
- [\*-unikraft-linux-musl](platform-support/unikraft-linux-musl.md)
- [\*-unknown-helenos](platform-support/helenos.md)
- [\*-unknown-hermit](platform-support/hermit.md)
- [\*-unknown-freebsd](platform-support/freebsd.md)
- [\*-unknown-netbsd\*](platform-support/netbsd.md)

View File

@ -313,6 +313,7 @@ target | std | host | notes
[`i686-apple-darwin`](platform-support/apple-darwin.md) | ✓ | ✓ | 32-bit macOS (10.12+, Sierra+, Penryn) [^x86_32-floats-return-ABI]
[`i686-pc-nto-qnx700`](platform-support/nto-qnx.md) | * | | 32-bit x86 QNX Neutrino 7.0 RTOS (Pentium 4) [^x86_32-floats-return-ABI]
`i686-unknown-haiku` | ✓ | ✓ | 32-bit Haiku (Pentium 4) [^x86_32-floats-return-ABI]
[`i686-unknown-helenos`](platform-support/helenos.md) | ? | | HelenOS IA-32
[`i686-unknown-hurd-gnu`](platform-support/hurd.md) | ✓ | ✓ | 32-bit GNU/Hurd (Pentium 4) [^x86_32-floats-return-ABI]
[`i686-unknown-netbsd`](platform-support/netbsd.md) | ✓ | ✓ | NetBSD/i386 (Pentium 4) [^x86_32-floats-return-ABI]
[`i686-unknown-openbsd`](platform-support/openbsd.md) | ✓ | ✓ | 32-bit OpenBSD (Pentium 4) [^x86_32-floats-return-ABI]
@ -415,6 +416,7 @@ target | std | host | notes
`x86_64-unknown-dragonfly` | ✓ | ✓ | 64-bit DragonFlyBSD
`x86_64-unknown-haiku` | ✓ | ✓ | 64-bit Haiku
[`x86_64-unknown-hermit`](platform-support/hermit.md) | ✓ | | x86_64 Hermit
[`x86_64-unknown-helenos`](platform-support/helenos.md) | ? | | x86_64 (amd64) HelenOS
[`x86_64-unknown-hurd-gnu`](platform-support/hurd.md) | ✓ | ✓ | 64-bit GNU/Hurd
`x86_64-unknown-l4re-uclibc` | ? | |
[`x86_64-unknown-linux-none`](platform-support/x86_64-unknown-linux-none.md) | * | | 64-bit Linux with no libc

View File

@ -0,0 +1,54 @@
# `*-unknown-helenos`
**Tier: 3**
Targets for [HelenOS](https://www.helenos.org).
These targets allow compiling user-space applications, that you can then copy into your HelenOS ISO image to run them.
Target triplets available so far:
- `x86_64-unknown-helenos`
- `i686-unknown-helenos`
## Target maintainers
- Matěj Volf ([@mvolfik](https://github.com/mvolfik))
## Requirements
These targets only support cross-compilation. The targets will[^helenos-libstd-pending] support libstd, although support of some platform features (filesystem, networking) may be limited.
You need to have a local clone of the HelenOS repository and the HelenOS toolchain set up, no HelenOS-Rust development artifacts are available.
[^helenos-libstd-pending]: libstd is not yet available, because it needs to be done in a separate PR, because compiler support needs to be merged first to allow creating libc bindings
## Building
### HelenOS toolchain setup
For compilation of standard library, you need to build the HelenOS toolchain (because Rust needs to use `*-helenos-gcc` as linker) and shared libraries. See [this HelenOS wiki page](https://www.helenos.org/wiki/UsersGuide/CompilingFromSource#a2.Buildasupportedcross-compiler) for instruction on setting up the build. At the end of step 4 (_Configure and build_), invoke `ninja export-dev` to build the shared libraries.
Then copy these shared libraries from `export-dev/lib` to the path where the compiler automatically searches for them. This will be the directory where you installed the toolchain (for example `~/.local/share/HelenOS/cross/i686-helenos/lib`). You can see this path with this command:
```sh
touch /tmp/test.c
i686-helenos-gcc -v -c /tmp/test.c 2>&1 | grep LIBRARY_PATH
```
### Building the target
When you have the HelenOS toolchain set up and installed in your path, you can build the Rust toolchain using the standard procedure. See [rustc dev guide](https://rustc-dev-guide.rust-lang.org/building/how-to-build-and-run.html).
### Building Rust programs
Use the toolchain that you have built above and run `cargo build --target <arch>-unknown-helenos`.
## Testing
After you build a Rust program for HelenOS, you can put it into the `dist` directory of the HelenOS build, build the ISO image, and then run it either in an emulator, or on real hardware. See HelenOS wiki for further instructions on running the OS.
Running the Rust testsuite has not been attempted yet due to missing host tools and networking code.
## Cross-compilation toolchains and C code
You should be able to cross-compile and link any needed C code using `<arch>-helenos-gcc` that you built above. However, note that clang support is highly lacking. Therefore, to run tools such as `bindgen`, you will need to provide flag `-nostdinc` and manually specify the include paths to HelenOS headers, which you will find in the `export-dev` folder + in the cross-compilation toolchain (e.g. `~/.local/share/HelenOS/cross/lib/gcc/i686-helenos/14.2.0/include`).

View File

@ -241,6 +241,9 @@
//@ revisions: i686_unknown_haiku
//@ [i686_unknown_haiku] compile-flags: --target i686-unknown-haiku
//@ [i686_unknown_haiku] needs-llvm-components: x86
//@ revisions: i686_unknown_helenos
//@ [i686_unknown_helenos] compile-flags: --target i686-unknown-helenos
//@ [i686_unknown_helenos] needs-llvm-components: x86
//@ revisions: i686_unknown_hurd_gnu
//@ [i686_unknown_hurd_gnu] compile-flags: --target i686-unknown-hurd-gnu
//@ [i686_unknown_hurd_gnu] needs-llvm-components: x86
@ -598,6 +601,9 @@
//@ revisions: x86_64_unknown_haiku
//@ [x86_64_unknown_haiku] compile-flags: --target x86_64-unknown-haiku
//@ [x86_64_unknown_haiku] needs-llvm-components: x86
//@ revisions: x86_64_unknown_helenos
//@ [x86_64_unknown_helenos] compile-flags: --target x86_64-unknown-helenos
//@ [x86_64_unknown_helenos] needs-llvm-components: x86
//@ revisions: x86_64_unknown_hurd_gnu
//@ [x86_64_unknown_hurd_gnu] compile-flags: --target x86_64-unknown-hurd-gnu
//@ [x86_64_unknown_hurd_gnu] needs-llvm-components: x86

View File

@ -201,7 +201,7 @@ warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
LL | target_os = "_UNEXPECTED_VALUE",
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: expected values for `target_os` are: `aix`, `amdhsa`, `android`, `cuda`, `cygwin`, `dragonfly`, `emscripten`, `espidf`, `freebsd`, `fuchsia`, `haiku`, `hermit`, `horizon`, `hurd`, `illumos`, `ios`, `l4re`, `linux`, `macos`, `netbsd`, `none`, `nto`, `nuttx`, `openbsd`, `psp`, `psx`, `redox`, `rtems`, `solaris`, `solid_asp3`, `teeos`, `trusty`, `tvos`, `uefi`, `unknown`, `visionos`, `vita`, `vxworks`, `wasi`, `watchos`, `windows`, `xous`, and `zkvm`
= note: expected values for `target_os` are: `aix`, `amdhsa`, `android`, `cuda`, `cygwin`, `dragonfly`, `emscripten`, `espidf`, `freebsd`, `fuchsia`, `haiku`, `helenos`, `hermit`, `horizon`, `hurd`, `illumos`, `ios`, `l4re`, `linux`, `macos`, `netbsd`, `none`, `nto`, `nuttx`, `openbsd`, `psp`, `psx`, `redox`, `rtems`, `solaris`, `solid_asp3`, `teeos`, `trusty`, `tvos`, `uefi`, `unknown`, `visionos`, `vita`, `vxworks`, `wasi`, `watchos`, `windows`, `xous`, and `zkvm`
= note: see <https://doc.rust-lang.org/nightly/rustc/check-cfg.html> for more information about checking conditional configuration
warning: unexpected `cfg` condition value: `_UNEXPECTED_VALUE`
@ -274,7 +274,7 @@ LL | #[cfg(target_os = "linuz")] // testing that we suggest `linux`
| |
| help: there is a expected value with a similar name: `"linux"`
|
= note: expected values for `target_os` are: `aix`, `amdhsa`, `android`, `cuda`, `cygwin`, `dragonfly`, `emscripten`, `espidf`, `freebsd`, `fuchsia`, `haiku`, `hermit`, `horizon`, `hurd`, `illumos`, `ios`, `l4re`, `linux`, `macos`, `netbsd`, `none`, `nto`, `nuttx`, `openbsd`, `psp`, `psx`, `redox`, `rtems`, `solaris`, `solid_asp3`, `teeos`, `trusty`, `tvos`, `uefi`, `unknown`, `visionos`, `vita`, `vxworks`, `wasi`, `watchos`, `windows`, `xous`, and `zkvm`
= note: expected values for `target_os` are: `aix`, `amdhsa`, `android`, `cuda`, `cygwin`, `dragonfly`, `emscripten`, `espidf`, `freebsd`, `fuchsia`, `haiku`, `helenos`, `hermit`, `horizon`, `hurd`, `illumos`, `ios`, `l4re`, `linux`, `macos`, `netbsd`, `none`, `nto`, `nuttx`, `openbsd`, `psp`, `psx`, `redox`, `rtems`, `solaris`, `solid_asp3`, `teeos`, `trusty`, `tvos`, `uefi`, `unknown`, `visionos`, `vita`, `vxworks`, `wasi`, `watchos`, `windows`, `xous`, and `zkvm`
= note: see <https://doc.rust-lang.org/nightly/rustc/check-cfg.html> for more information about checking conditional configuration
warning: 28 warnings emitted