Skip to content

Conversation

@mvolfik
Copy link

@mvolfik mvolfik commented Mar 27, 2025

Description

Add support for HelenOS. I would like to get this backported to 0.2, because I also have a stdlib support ready, which depends on libc 0.2. I'll be sending that patch to rust-lang/rust rather soon (this or next week), I hope.

@rustbot label stable-nominated

Sources

All HelenOS source code is at https://github.com/HelenOS/helenos/. There are comments in this patch attributing each section to a specific header file. Files from common/ and abi/ get included in HelenOS libc by the build system there, from uspace/lib we use c, inet and posix, so that's what we link. libstartfiles is HelenOS' version of crt* files, because they don't distribute them along with the compiler toolchain, but instead as a library.

Checklist

  • Relevant tests in libc-test/semver have been updated
  • No placeholder or unstable values like *LAST or *MAX are
    included (see #3131)
  • Tested locally (cd libc-test && cargo test --target mytarget);
    especially relevant for platforms that may not be checked in CI

Tested locally as cargo test (without the --target flag), testing for HelenOS targets will require support here in ctest2, I hope for a tier3 target, it is ok to go without these tests for now?

@rustbot
Copy link
Collaborator

rustbot commented Mar 27, 2025

r? @tgross35

rustbot has assigned @tgross35.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review stable-nominated This PR should be considered for cherry-pick to libc's stable release branch labels Mar 27, 2025
@mvolfik
Copy link
Author

mvolfik commented Mar 27, 2025

Ugh, the only error is missing HelenOS target... I planned to merge the compiler and stdlib support at once. But this makes it seem like I will need to first merge no-std support for HelenOS in compiler, then this libc patch can go through, and only then the stdlib PR makes sense?

@tgross35
Copy link
Contributor

tgross35 commented Apr 1, 2025

Is there a proposal for adding the target to Rust? The changes look pretty reasonable to me, but getting it at least okayed for rustc is a prerequisite for libc changes.

Ugh, the only error is missing HelenOS target... I planned to merge the compiler and stdlib support at once. But this makes it seem like I will need to first merge no-std support for HelenOS in compiler, then this libc patch can go through, and only then the stdlib PR makes sense?

It is usually preferable to do this anyway; the compiler changes are usually pretty easy and can get merged as soon as the proposal is accepted. Then library changes can build up from there and things don't get slowed down by having a large diff to review at once.

@tgross35
Copy link
Contributor

tgross35 commented Apr 2, 2025

Per the above

@rustbot blocked

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Oct 31, 2025
…wiser

add first HelenOS compilation targets

I'm working on adding a HelenOS compilation target for Rust as my bachelor thesis. I understood that the policy for tier 3 targets is quite liberal, so here's my attempt at upstreaming the initial support. I'm quite new to Rust internals, so thanks in advance for all assistance with my stupid questions :)

libstd support is coming, but I understood compiler support must come first before libc bindings can get merged (rust-lang/libc#4355 (comment))

Locally, I also needed to update `cc-rs`, to do two things:

- add [here](https://github.com/rust-lang/cc-rs/blob/59578addda0233c8e9a0b399769cedb538ac8052/src/lib.rs#L3397) the binutils prefixes (`x86_64-unknown-helenos` -> `amd64-helenos`
- add the targets to `generated.rs`

From the "Adding tier 3 target" guide it sound like the latter will happen automatically, the first I need to do manually? I'm not sure if the test suite will pass or fail without it.

I'm also quite unsure about all the target spec configuration flags. I copied the specs from other small OSs with some tweaks and things seems to work now, but I have no idea how to better judge if it's correct.

Finally, I'm also working on support for arm (32-bit and 64), but there I'm currently running into some issues with linking, so I'll send that later, if I figure it out.

---

<details>
<summary>Tier 3 policy "form"</summary>

> A tier 3 target must have a designated developer or developers (the "target maintainers") on record to be CCed when issues arise regarding the target. (The mechanism to track and CC such developers may evolve over time.)

That would be me, I suppose. I agree.

> Targets must use naming consistent with any existing targets; for instance, a target for the same CPU or OS as an existing Rust target should use the same name for that CPU or OS. Targets should normally use the same names and naming conventions as used elsewhere in the broader ecosystem beyond Rust (such as in other toolchains), unless they have a very good reason to diverge. Changing the name of a target can be highly disruptive, especially once the target reaches a higher tier, so getting the name right is important even for a tier 3 target.

I'm using the standard Rust conventions.

> Tier 3 targets may have unusual requirements to build or use, but must not create legal issues or impose onerous legal terms for the Rust project or for Rust developers or users.
> - The target must not introduce license incompatibilities.
> - Anything added to the Rust repository must be under the standard Rust license (MIT OR Apache-2.0).

I am not aware of any legal issues. HelenOS itself is open-source under BSD license. All code contributed in this PR (and later for libstd) is either fully my own or an adaptation of existing code from this repo (some PAL pieces).

> - The target must not cause the Rust tools or libraries built for any other host (even when supporting cross-compilation to the target) to depend on any new dependency less permissive than the Rust licensing policy. This applies whether the dependency is a Rust crate that would require adding new license exceptions (as specified by the tidy tool in the rust-lang/rust repository), or whether the dependency is a native library or binary. In other words, the introduction of the target must not cause a user installing or running a version of Rust or the Rust tools to be subject to any new license requirements.

I am not adding any new dependencies.

> - Compiling, linking, and emitting functional binaries, libraries, or other code for the target (whether hosted on the target itself or cross-compiling from another target) must not depend on proprietary (non-FOSS) libraries. Host tools built for the target itself may depend on the ordinary runtime libraries supplied by the platform and commonly used by other applications built for the target, but those libraries must not be required for code generation for the target; cross-compilation to the target must not require such libraries at all. For instance, rustc built for the target may depend on a common proprietary C runtime library or console output library, but must not depend on a proprietary code generation library or code optimization library. Rust's license permits such combinations, but the Rust project has no interest in maintaining such combinations within the scope of Rust itself, even at tier 3.

The HelenOS build tools consist of open-source patches to GCC and binutils, so I suppose we're fine.

> Neither this policy nor any decisions made regarding targets shall create any binding agreement or estoppel by any party. If any member of an approving Rust team serves as one of the maintainers of a target, or has any legal or employment requirement (explicit or implicit) that might affect their decisions regarding a target, they must recuse themselves from any approval decisions regarding the target's tier status, though they may otherwise participate in discussions.

Understood.

> Tier 3 targets should attempt to implement as much of the standard libraries as possible and appropriate (core for most targets, alloc for targets that can support dynamic memory allocation, std for targets with an operating system or equivalent layer of system-provided functionality), but may leave some code unimplemented (either unavailable or stubbed out as appropriate), whether because the target makes it impossible to implement or challenging to implement. The authors of pull requests are not obligated to avoid calling any portions of the standard library on the basis of a tier 3 target not implementing those portions.

The libstd PR will fully support core+alloc, and enough of std to run interesting programs (stdio, argv and fs) - so we can run tools like [imagecli](https://github.com/theotherphil/imagecli). But yes, major parts of std are missing - pipe, process and net are currently forwarded to `unsupported()`. Some barebones `net` should be possible, but e.g. cloning of the descriptor is unheard of in HelenOS, so it won't be as straightforward as the rest. Also, some places of the `fs` and `thread` module are also quite stubby (but part of it is just because HelenOS has no file permissions, for example). HelenOS is a small, experimental OS, so its own libc is stubbed out as well in some places. I hope this state is acceptable?

> The target must provide documentation for the Rust community explaining how to build for the target, using cross-compilation if possible. If the target supports running binaries, or running tests (even if they do not pass), the documentation must explain how to run such binaries or tests for the target, using emulation if possible or dedicated hardware if necessary.

I hope the guide in doc is sufficient.

> Tier 3 targets must not impose burden on the authors of pull requests, or other developers in the community, to maintain the target. In particular, do not post comments (automated or manual) on a PR that derail or suggest a block on the PR based on a tier 3 target. Do not send automated messages or notifications (via any medium, including via `@)` to a PR author or others involved with a PR regarding a tier 3 target, unless they have opted into such messages.

Understood.

> Patches adding or updating tier 3 targets must not break any existing tier 2 or tier 1 target, and must not knowingly break another tier 3 target without approval of either the compiler team or the maintainers of the other tier 3 target.

Understood.

> Tier 3 targets must be able to produce assembly using at least one of rustc's supported backends from any host target. (Having support in a fork of the backend is not sufficient, it must be upstream.)

Umm, I think this is satisfied? Code generation works with the default LLVM backend, even though it has no idea about HelenOS. And our GCC patch is then used only for linking.

</details>
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Oct 31, 2025
…wiser

add first HelenOS compilation targets

I'm working on adding a HelenOS compilation target for Rust as my bachelor thesis. I understood that the policy for tier 3 targets is quite liberal, so here's my attempt at upstreaming the initial support. I'm quite new to Rust internals, so thanks in advance for all assistance with my stupid questions :)

libstd support is coming, but I understood compiler support must come first before libc bindings can get merged (rust-lang/libc#4355 (comment))

Locally, I also needed to update `cc-rs`, to do two things:

- add [here](https://github.com/rust-lang/cc-rs/blob/59578addda0233c8e9a0b399769cedb538ac8052/src/lib.rs#L3397) the binutils prefixes (`x86_64-unknown-helenos` -> `amd64-helenos`
- add the targets to `generated.rs`

From the "Adding tier 3 target" guide it sound like the latter will happen automatically, the first I need to do manually? I'm not sure if the test suite will pass or fail without it.

I'm also quite unsure about all the target spec configuration flags. I copied the specs from other small OSs with some tweaks and things seems to work now, but I have no idea how to better judge if it's correct.

Finally, I'm also working on support for arm (32-bit and 64), but there I'm currently running into some issues with linking, so I'll send that later, if I figure it out.

---

<details>
<summary>Tier 3 policy "form"</summary>

> A tier 3 target must have a designated developer or developers (the "target maintainers") on record to be CCed when issues arise regarding the target. (The mechanism to track and CC such developers may evolve over time.)

That would be me, I suppose. I agree.

> Targets must use naming consistent with any existing targets; for instance, a target for the same CPU or OS as an existing Rust target should use the same name for that CPU or OS. Targets should normally use the same names and naming conventions as used elsewhere in the broader ecosystem beyond Rust (such as in other toolchains), unless they have a very good reason to diverge. Changing the name of a target can be highly disruptive, especially once the target reaches a higher tier, so getting the name right is important even for a tier 3 target.

I'm using the standard Rust conventions.

> Tier 3 targets may have unusual requirements to build or use, but must not create legal issues or impose onerous legal terms for the Rust project or for Rust developers or users.
> - The target must not introduce license incompatibilities.
> - Anything added to the Rust repository must be under the standard Rust license (MIT OR Apache-2.0).

I am not aware of any legal issues. HelenOS itself is open-source under BSD license. All code contributed in this PR (and later for libstd) is either fully my own or an adaptation of existing code from this repo (some PAL pieces).

> - The target must not cause the Rust tools or libraries built for any other host (even when supporting cross-compilation to the target) to depend on any new dependency less permissive than the Rust licensing policy. This applies whether the dependency is a Rust crate that would require adding new license exceptions (as specified by the tidy tool in the rust-lang/rust repository), or whether the dependency is a native library or binary. In other words, the introduction of the target must not cause a user installing or running a version of Rust or the Rust tools to be subject to any new license requirements.

I am not adding any new dependencies.

> - Compiling, linking, and emitting functional binaries, libraries, or other code for the target (whether hosted on the target itself or cross-compiling from another target) must not depend on proprietary (non-FOSS) libraries. Host tools built for the target itself may depend on the ordinary runtime libraries supplied by the platform and commonly used by other applications built for the target, but those libraries must not be required for code generation for the target; cross-compilation to the target must not require such libraries at all. For instance, rustc built for the target may depend on a common proprietary C runtime library or console output library, but must not depend on a proprietary code generation library or code optimization library. Rust's license permits such combinations, but the Rust project has no interest in maintaining such combinations within the scope of Rust itself, even at tier 3.

The HelenOS build tools consist of open-source patches to GCC and binutils, so I suppose we're fine.

> Neither this policy nor any decisions made regarding targets shall create any binding agreement or estoppel by any party. If any member of an approving Rust team serves as one of the maintainers of a target, or has any legal or employment requirement (explicit or implicit) that might affect their decisions regarding a target, they must recuse themselves from any approval decisions regarding the target's tier status, though they may otherwise participate in discussions.

Understood.

> Tier 3 targets should attempt to implement as much of the standard libraries as possible and appropriate (core for most targets, alloc for targets that can support dynamic memory allocation, std for targets with an operating system or equivalent layer of system-provided functionality), but may leave some code unimplemented (either unavailable or stubbed out as appropriate), whether because the target makes it impossible to implement or challenging to implement. The authors of pull requests are not obligated to avoid calling any portions of the standard library on the basis of a tier 3 target not implementing those portions.

The libstd PR will fully support core+alloc, and enough of std to run interesting programs (stdio, argv and fs) - so we can run tools like [imagecli](https://github.com/theotherphil/imagecli). But yes, major parts of std are missing - pipe, process and net are currently forwarded to `unsupported()`. Some barebones `net` should be possible, but e.g. cloning of the descriptor is unheard of in HelenOS, so it won't be as straightforward as the rest. Also, some places of the `fs` and `thread` module are also quite stubby (but part of it is just because HelenOS has no file permissions, for example). HelenOS is a small, experimental OS, so its own libc is stubbed out as well in some places. I hope this state is acceptable?

> The target must provide documentation for the Rust community explaining how to build for the target, using cross-compilation if possible. If the target supports running binaries, or running tests (even if they do not pass), the documentation must explain how to run such binaries or tests for the target, using emulation if possible or dedicated hardware if necessary.

I hope the guide in doc is sufficient.

> Tier 3 targets must not impose burden on the authors of pull requests, or other developers in the community, to maintain the target. In particular, do not post comments (automated or manual) on a PR that derail or suggest a block on the PR based on a tier 3 target. Do not send automated messages or notifications (via any medium, including via ``@)`` to a PR author or others involved with a PR regarding a tier 3 target, unless they have opted into such messages.

Understood.

> Patches adding or updating tier 3 targets must not break any existing tier 2 or tier 1 target, and must not knowingly break another tier 3 target without approval of either the compiler team or the maintainers of the other tier 3 target.

Understood.

> Tier 3 targets must be able to produce assembly using at least one of rustc's supported backends from any host target. (Having support in a fork of the backend is not sufficient, it must be upstream.)

Umm, I think this is satisfied? Code generation works with the default LLVM backend, even though it has no idea about HelenOS. And our GCC patch is then used only for linking.

</details>
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Oct 31, 2025
…wiser

add first HelenOS compilation targets

I'm working on adding a HelenOS compilation target for Rust as my bachelor thesis. I understood that the policy for tier 3 targets is quite liberal, so here's my attempt at upstreaming the initial support. I'm quite new to Rust internals, so thanks in advance for all assistance with my stupid questions :)

libstd support is coming, but I understood compiler support must come first before libc bindings can get merged (rust-lang/libc#4355 (comment))

Locally, I also needed to update `cc-rs`, to do two things:

- add [here](https://github.com/rust-lang/cc-rs/blob/59578addda0233c8e9a0b399769cedb538ac8052/src/lib.rs#L3397) the binutils prefixes (`x86_64-unknown-helenos` -> `amd64-helenos`
- add the targets to `generated.rs`

From the "Adding tier 3 target" guide it sound like the latter will happen automatically, the first I need to do manually? I'm not sure if the test suite will pass or fail without it.

I'm also quite unsure about all the target spec configuration flags. I copied the specs from other small OSs with some tweaks and things seems to work now, but I have no idea how to better judge if it's correct.

Finally, I'm also working on support for arm (32-bit and 64), but there I'm currently running into some issues with linking, so I'll send that later, if I figure it out.

---

<details>
<summary>Tier 3 policy "form"</summary>

> A tier 3 target must have a designated developer or developers (the "target maintainers") on record to be CCed when issues arise regarding the target. (The mechanism to track and CC such developers may evolve over time.)

That would be me, I suppose. I agree.

> Targets must use naming consistent with any existing targets; for instance, a target for the same CPU or OS as an existing Rust target should use the same name for that CPU or OS. Targets should normally use the same names and naming conventions as used elsewhere in the broader ecosystem beyond Rust (such as in other toolchains), unless they have a very good reason to diverge. Changing the name of a target can be highly disruptive, especially once the target reaches a higher tier, so getting the name right is important even for a tier 3 target.

I'm using the standard Rust conventions.

> Tier 3 targets may have unusual requirements to build or use, but must not create legal issues or impose onerous legal terms for the Rust project or for Rust developers or users.
> - The target must not introduce license incompatibilities.
> - Anything added to the Rust repository must be under the standard Rust license (MIT OR Apache-2.0).

I am not aware of any legal issues. HelenOS itself is open-source under BSD license. All code contributed in this PR (and later for libstd) is either fully my own or an adaptation of existing code from this repo (some PAL pieces).

> - The target must not cause the Rust tools or libraries built for any other host (even when supporting cross-compilation to the target) to depend on any new dependency less permissive than the Rust licensing policy. This applies whether the dependency is a Rust crate that would require adding new license exceptions (as specified by the tidy tool in the rust-lang/rust repository), or whether the dependency is a native library or binary. In other words, the introduction of the target must not cause a user installing or running a version of Rust or the Rust tools to be subject to any new license requirements.

I am not adding any new dependencies.

> - Compiling, linking, and emitting functional binaries, libraries, or other code for the target (whether hosted on the target itself or cross-compiling from another target) must not depend on proprietary (non-FOSS) libraries. Host tools built for the target itself may depend on the ordinary runtime libraries supplied by the platform and commonly used by other applications built for the target, but those libraries must not be required for code generation for the target; cross-compilation to the target must not require such libraries at all. For instance, rustc built for the target may depend on a common proprietary C runtime library or console output library, but must not depend on a proprietary code generation library or code optimization library. Rust's license permits such combinations, but the Rust project has no interest in maintaining such combinations within the scope of Rust itself, even at tier 3.

The HelenOS build tools consist of open-source patches to GCC and binutils, so I suppose we're fine.

> Neither this policy nor any decisions made regarding targets shall create any binding agreement or estoppel by any party. If any member of an approving Rust team serves as one of the maintainers of a target, or has any legal or employment requirement (explicit or implicit) that might affect their decisions regarding a target, they must recuse themselves from any approval decisions regarding the target's tier status, though they may otherwise participate in discussions.

Understood.

> Tier 3 targets should attempt to implement as much of the standard libraries as possible and appropriate (core for most targets, alloc for targets that can support dynamic memory allocation, std for targets with an operating system or equivalent layer of system-provided functionality), but may leave some code unimplemented (either unavailable or stubbed out as appropriate), whether because the target makes it impossible to implement or challenging to implement. The authors of pull requests are not obligated to avoid calling any portions of the standard library on the basis of a tier 3 target not implementing those portions.

The libstd PR will fully support core+alloc, and enough of std to run interesting programs (stdio, argv and fs) - so we can run tools like [imagecli](https://github.com/theotherphil/imagecli). But yes, major parts of std are missing - pipe, process and net are currently forwarded to `unsupported()`. Some barebones `net` should be possible, but e.g. cloning of the descriptor is unheard of in HelenOS, so it won't be as straightforward as the rest. Also, some places of the `fs` and `thread` module are also quite stubby (but part of it is just because HelenOS has no file permissions, for example). HelenOS is a small, experimental OS, so its own libc is stubbed out as well in some places. I hope this state is acceptable?

> The target must provide documentation for the Rust community explaining how to build for the target, using cross-compilation if possible. If the target supports running binaries, or running tests (even if they do not pass), the documentation must explain how to run such binaries or tests for the target, using emulation if possible or dedicated hardware if necessary.

I hope the guide in doc is sufficient.

> Tier 3 targets must not impose burden on the authors of pull requests, or other developers in the community, to maintain the target. In particular, do not post comments (automated or manual) on a PR that derail or suggest a block on the PR based on a tier 3 target. Do not send automated messages or notifications (via any medium, including via ```@)``` to a PR author or others involved with a PR regarding a tier 3 target, unless they have opted into such messages.

Understood.

> Patches adding or updating tier 3 targets must not break any existing tier 2 or tier 1 target, and must not knowingly break another tier 3 target without approval of either the compiler team or the maintainers of the other tier 3 target.

Understood.

> Tier 3 targets must be able to produce assembly using at least one of rustc's supported backends from any host target. (Having support in a fork of the backend is not sufficient, it must be upstream.)

Umm, I think this is satisfied? Code generation works with the default LLVM backend, even though it has no idea about HelenOS. And our GCC patch is then used only for linking.

</details>
Zalathar added a commit to Zalathar/rust that referenced this pull request Nov 1, 2025
…wiser

add first HelenOS compilation targets

I'm working on adding a HelenOS compilation target for Rust as my bachelor thesis. I understood that the policy for tier 3 targets is quite liberal, so here's my attempt at upstreaming the initial support. I'm quite new to Rust internals, so thanks in advance for all assistance with my stupid questions :)

libstd support is coming, but I understood compiler support must come first before libc bindings can get merged (rust-lang/libc#4355 (comment))

Locally, I also needed to update `cc-rs`, to do two things:

- add [here](https://github.com/rust-lang/cc-rs/blob/59578addda0233c8e9a0b399769cedb538ac8052/src/lib.rs#L3397) the binutils prefixes (`x86_64-unknown-helenos` -> `amd64-helenos`
- add the targets to `generated.rs`

From the "Adding tier 3 target" guide it sound like the latter will happen automatically, the first I need to do manually? I'm not sure if the test suite will pass or fail without it.

I'm also quite unsure about all the target spec configuration flags. I copied the specs from other small OSs with some tweaks and things seems to work now, but I have no idea how to better judge if it's correct.

Finally, I'm also working on support for arm (32-bit and 64), but there I'm currently running into some issues with linking, so I'll send that later, if I figure it out.

---

<details>
<summary>Tier 3 policy "form"</summary>

> A tier 3 target must have a designated developer or developers (the "target maintainers") on record to be CCed when issues arise regarding the target. (The mechanism to track and CC such developers may evolve over time.)

That would be me, I suppose. I agree.

> Targets must use naming consistent with any existing targets; for instance, a target for the same CPU or OS as an existing Rust target should use the same name for that CPU or OS. Targets should normally use the same names and naming conventions as used elsewhere in the broader ecosystem beyond Rust (such as in other toolchains), unless they have a very good reason to diverge. Changing the name of a target can be highly disruptive, especially once the target reaches a higher tier, so getting the name right is important even for a tier 3 target.

I'm using the standard Rust conventions.

> Tier 3 targets may have unusual requirements to build or use, but must not create legal issues or impose onerous legal terms for the Rust project or for Rust developers or users.
> - The target must not introduce license incompatibilities.
> - Anything added to the Rust repository must be under the standard Rust license (MIT OR Apache-2.0).

I am not aware of any legal issues. HelenOS itself is open-source under BSD license. All code contributed in this PR (and later for libstd) is either fully my own or an adaptation of existing code from this repo (some PAL pieces).

> - The target must not cause the Rust tools or libraries built for any other host (even when supporting cross-compilation to the target) to depend on any new dependency less permissive than the Rust licensing policy. This applies whether the dependency is a Rust crate that would require adding new license exceptions (as specified by the tidy tool in the rust-lang/rust repository), or whether the dependency is a native library or binary. In other words, the introduction of the target must not cause a user installing or running a version of Rust or the Rust tools to be subject to any new license requirements.

I am not adding any new dependencies.

> - Compiling, linking, and emitting functional binaries, libraries, or other code for the target (whether hosted on the target itself or cross-compiling from another target) must not depend on proprietary (non-FOSS) libraries. Host tools built for the target itself may depend on the ordinary runtime libraries supplied by the platform and commonly used by other applications built for the target, but those libraries must not be required for code generation for the target; cross-compilation to the target must not require such libraries at all. For instance, rustc built for the target may depend on a common proprietary C runtime library or console output library, but must not depend on a proprietary code generation library or code optimization library. Rust's license permits such combinations, but the Rust project has no interest in maintaining such combinations within the scope of Rust itself, even at tier 3.

The HelenOS build tools consist of open-source patches to GCC and binutils, so I suppose we're fine.

> Neither this policy nor any decisions made regarding targets shall create any binding agreement or estoppel by any party. If any member of an approving Rust team serves as one of the maintainers of a target, or has any legal or employment requirement (explicit or implicit) that might affect their decisions regarding a target, they must recuse themselves from any approval decisions regarding the target's tier status, though they may otherwise participate in discussions.

Understood.

> Tier 3 targets should attempt to implement as much of the standard libraries as possible and appropriate (core for most targets, alloc for targets that can support dynamic memory allocation, std for targets with an operating system or equivalent layer of system-provided functionality), but may leave some code unimplemented (either unavailable or stubbed out as appropriate), whether because the target makes it impossible to implement or challenging to implement. The authors of pull requests are not obligated to avoid calling any portions of the standard library on the basis of a tier 3 target not implementing those portions.

The libstd PR will fully support core+alloc, and enough of std to run interesting programs (stdio, argv and fs) - so we can run tools like [imagecli](https://github.com/theotherphil/imagecli). But yes, major parts of std are missing - pipe, process and net are currently forwarded to `unsupported()`. Some barebones `net` should be possible, but e.g. cloning of the descriptor is unheard of in HelenOS, so it won't be as straightforward as the rest. Also, some places of the `fs` and `thread` module are also quite stubby (but part of it is just because HelenOS has no file permissions, for example). HelenOS is a small, experimental OS, so its own libc is stubbed out as well in some places. I hope this state is acceptable?

> The target must provide documentation for the Rust community explaining how to build for the target, using cross-compilation if possible. If the target supports running binaries, or running tests (even if they do not pass), the documentation must explain how to run such binaries or tests for the target, using emulation if possible or dedicated hardware if necessary.

I hope the guide in doc is sufficient.

> Tier 3 targets must not impose burden on the authors of pull requests, or other developers in the community, to maintain the target. In particular, do not post comments (automated or manual) on a PR that derail or suggest a block on the PR based on a tier 3 target. Do not send automated messages or notifications (via any medium, including via ````@)```` to a PR author or others involved with a PR regarding a tier 3 target, unless they have opted into such messages.

Understood.

> Patches adding or updating tier 3 targets must not break any existing tier 2 or tier 1 target, and must not knowingly break another tier 3 target without approval of either the compiler team or the maintainers of the other tier 3 target.

Understood.

> Tier 3 targets must be able to produce assembly using at least one of rustc's supported backends from any host target. (Having support in a fork of the backend is not sufficient, it must be upstream.)

Umm, I think this is satisfied? Code generation works with the default LLVM backend, even though it has no idea about HelenOS. And our GCC patch is then used only for linking.

</details>
Zalathar added a commit to Zalathar/rust that referenced this pull request Nov 1, 2025
…wiser

add first HelenOS compilation targets

I'm working on adding a HelenOS compilation target for Rust as my bachelor thesis. I understood that the policy for tier 3 targets is quite liberal, so here's my attempt at upstreaming the initial support. I'm quite new to Rust internals, so thanks in advance for all assistance with my stupid questions :)

libstd support is coming, but I understood compiler support must come first before libc bindings can get merged (rust-lang/libc#4355 (comment))

Locally, I also needed to update `cc-rs`, to do two things:

- add [here](https://github.com/rust-lang/cc-rs/blob/59578addda0233c8e9a0b399769cedb538ac8052/src/lib.rs#L3397) the binutils prefixes (`x86_64-unknown-helenos` -> `amd64-helenos`
- add the targets to `generated.rs`

From the "Adding tier 3 target" guide it sound like the latter will happen automatically, the first I need to do manually? I'm not sure if the test suite will pass or fail without it.

I'm also quite unsure about all the target spec configuration flags. I copied the specs from other small OSs with some tweaks and things seems to work now, but I have no idea how to better judge if it's correct.

Finally, I'm also working on support for arm (32-bit and 64), but there I'm currently running into some issues with linking, so I'll send that later, if I figure it out.

---

<details>
<summary>Tier 3 policy "form"</summary>

> A tier 3 target must have a designated developer or developers (the "target maintainers") on record to be CCed when issues arise regarding the target. (The mechanism to track and CC such developers may evolve over time.)

That would be me, I suppose. I agree.

> Targets must use naming consistent with any existing targets; for instance, a target for the same CPU or OS as an existing Rust target should use the same name for that CPU or OS. Targets should normally use the same names and naming conventions as used elsewhere in the broader ecosystem beyond Rust (such as in other toolchains), unless they have a very good reason to diverge. Changing the name of a target can be highly disruptive, especially once the target reaches a higher tier, so getting the name right is important even for a tier 3 target.

I'm using the standard Rust conventions.

> Tier 3 targets may have unusual requirements to build or use, but must not create legal issues or impose onerous legal terms for the Rust project or for Rust developers or users.
> - The target must not introduce license incompatibilities.
> - Anything added to the Rust repository must be under the standard Rust license (MIT OR Apache-2.0).

I am not aware of any legal issues. HelenOS itself is open-source under BSD license. All code contributed in this PR (and later for libstd) is either fully my own or an adaptation of existing code from this repo (some PAL pieces).

> - The target must not cause the Rust tools or libraries built for any other host (even when supporting cross-compilation to the target) to depend on any new dependency less permissive than the Rust licensing policy. This applies whether the dependency is a Rust crate that would require adding new license exceptions (as specified by the tidy tool in the rust-lang/rust repository), or whether the dependency is a native library or binary. In other words, the introduction of the target must not cause a user installing or running a version of Rust or the Rust tools to be subject to any new license requirements.

I am not adding any new dependencies.

> - Compiling, linking, and emitting functional binaries, libraries, or other code for the target (whether hosted on the target itself or cross-compiling from another target) must not depend on proprietary (non-FOSS) libraries. Host tools built for the target itself may depend on the ordinary runtime libraries supplied by the platform and commonly used by other applications built for the target, but those libraries must not be required for code generation for the target; cross-compilation to the target must not require such libraries at all. For instance, rustc built for the target may depend on a common proprietary C runtime library or console output library, but must not depend on a proprietary code generation library or code optimization library. Rust's license permits such combinations, but the Rust project has no interest in maintaining such combinations within the scope of Rust itself, even at tier 3.

The HelenOS build tools consist of open-source patches to GCC and binutils, so I suppose we're fine.

> Neither this policy nor any decisions made regarding targets shall create any binding agreement or estoppel by any party. If any member of an approving Rust team serves as one of the maintainers of a target, or has any legal or employment requirement (explicit or implicit) that might affect their decisions regarding a target, they must recuse themselves from any approval decisions regarding the target's tier status, though they may otherwise participate in discussions.

Understood.

> Tier 3 targets should attempt to implement as much of the standard libraries as possible and appropriate (core for most targets, alloc for targets that can support dynamic memory allocation, std for targets with an operating system or equivalent layer of system-provided functionality), but may leave some code unimplemented (either unavailable or stubbed out as appropriate), whether because the target makes it impossible to implement or challenging to implement. The authors of pull requests are not obligated to avoid calling any portions of the standard library on the basis of a tier 3 target not implementing those portions.

The libstd PR will fully support core+alloc, and enough of std to run interesting programs (stdio, argv and fs) - so we can run tools like [imagecli](https://github.com/theotherphil/imagecli). But yes, major parts of std are missing - pipe, process and net are currently forwarded to `unsupported()`. Some barebones `net` should be possible, but e.g. cloning of the descriptor is unheard of in HelenOS, so it won't be as straightforward as the rest. Also, some places of the `fs` and `thread` module are also quite stubby (but part of it is just because HelenOS has no file permissions, for example). HelenOS is a small, experimental OS, so its own libc is stubbed out as well in some places. I hope this state is acceptable?

> The target must provide documentation for the Rust community explaining how to build for the target, using cross-compilation if possible. If the target supports running binaries, or running tests (even if they do not pass), the documentation must explain how to run such binaries or tests for the target, using emulation if possible or dedicated hardware if necessary.

I hope the guide in doc is sufficient.

> Tier 3 targets must not impose burden on the authors of pull requests, or other developers in the community, to maintain the target. In particular, do not post comments (automated or manual) on a PR that derail or suggest a block on the PR based on a tier 3 target. Do not send automated messages or notifications (via any medium, including via `````@)````` to a PR author or others involved with a PR regarding a tier 3 target, unless they have opted into such messages.

Understood.

> Patches adding or updating tier 3 targets must not break any existing tier 2 or tier 1 target, and must not knowingly break another tier 3 target without approval of either the compiler team or the maintainers of the other tier 3 target.

Understood.

> Tier 3 targets must be able to produce assembly using at least one of rustc's supported backends from any host target. (Having support in a fork of the backend is not sufficient, it must be upstream.)

Umm, I think this is satisfied? Code generation works with the default LLVM backend, even though it has no idea about HelenOS. And our GCC patch is then used only for linking.

</details>
Zalathar added a commit to Zalathar/rust that referenced this pull request Nov 1, 2025
…wiser

add first HelenOS compilation targets

I'm working on adding a HelenOS compilation target for Rust as my bachelor thesis. I understood that the policy for tier 3 targets is quite liberal, so here's my attempt at upstreaming the initial support. I'm quite new to Rust internals, so thanks in advance for all assistance with my stupid questions :)

libstd support is coming, but I understood compiler support must come first before libc bindings can get merged (rust-lang/libc#4355 (comment))

Locally, I also needed to update `cc-rs`, to do two things:

- add [here](https://github.com/rust-lang/cc-rs/blob/59578addda0233c8e9a0b399769cedb538ac8052/src/lib.rs#L3397) the binutils prefixes (`x86_64-unknown-helenos` -> `amd64-helenos`
- add the targets to `generated.rs`

From the "Adding tier 3 target" guide it sound like the latter will happen automatically, the first I need to do manually? I'm not sure if the test suite will pass or fail without it.

I'm also quite unsure about all the target spec configuration flags. I copied the specs from other small OSs with some tweaks and things seems to work now, but I have no idea how to better judge if it's correct.

Finally, I'm also working on support for arm (32-bit and 64), but there I'm currently running into some issues with linking, so I'll send that later, if I figure it out.

---

<details>
<summary>Tier 3 policy "form"</summary>

> A tier 3 target must have a designated developer or developers (the "target maintainers") on record to be CCed when issues arise regarding the target. (The mechanism to track and CC such developers may evolve over time.)

That would be me, I suppose. I agree.

> Targets must use naming consistent with any existing targets; for instance, a target for the same CPU or OS as an existing Rust target should use the same name for that CPU or OS. Targets should normally use the same names and naming conventions as used elsewhere in the broader ecosystem beyond Rust (such as in other toolchains), unless they have a very good reason to diverge. Changing the name of a target can be highly disruptive, especially once the target reaches a higher tier, so getting the name right is important even for a tier 3 target.

I'm using the standard Rust conventions.

> Tier 3 targets may have unusual requirements to build or use, but must not create legal issues or impose onerous legal terms for the Rust project or for Rust developers or users.
> - The target must not introduce license incompatibilities.
> - Anything added to the Rust repository must be under the standard Rust license (MIT OR Apache-2.0).

I am not aware of any legal issues. HelenOS itself is open-source under BSD license. All code contributed in this PR (and later for libstd) is either fully my own or an adaptation of existing code from this repo (some PAL pieces).

> - The target must not cause the Rust tools or libraries built for any other host (even when supporting cross-compilation to the target) to depend on any new dependency less permissive than the Rust licensing policy. This applies whether the dependency is a Rust crate that would require adding new license exceptions (as specified by the tidy tool in the rust-lang/rust repository), or whether the dependency is a native library or binary. In other words, the introduction of the target must not cause a user installing or running a version of Rust or the Rust tools to be subject to any new license requirements.

I am not adding any new dependencies.

> - Compiling, linking, and emitting functional binaries, libraries, or other code for the target (whether hosted on the target itself or cross-compiling from another target) must not depend on proprietary (non-FOSS) libraries. Host tools built for the target itself may depend on the ordinary runtime libraries supplied by the platform and commonly used by other applications built for the target, but those libraries must not be required for code generation for the target; cross-compilation to the target must not require such libraries at all. For instance, rustc built for the target may depend on a common proprietary C runtime library or console output library, but must not depend on a proprietary code generation library or code optimization library. Rust's license permits such combinations, but the Rust project has no interest in maintaining such combinations within the scope of Rust itself, even at tier 3.

The HelenOS build tools consist of open-source patches to GCC and binutils, so I suppose we're fine.

> Neither this policy nor any decisions made regarding targets shall create any binding agreement or estoppel by any party. If any member of an approving Rust team serves as one of the maintainers of a target, or has any legal or employment requirement (explicit or implicit) that might affect their decisions regarding a target, they must recuse themselves from any approval decisions regarding the target's tier status, though they may otherwise participate in discussions.

Understood.

> Tier 3 targets should attempt to implement as much of the standard libraries as possible and appropriate (core for most targets, alloc for targets that can support dynamic memory allocation, std for targets with an operating system or equivalent layer of system-provided functionality), but may leave some code unimplemented (either unavailable or stubbed out as appropriate), whether because the target makes it impossible to implement or challenging to implement. The authors of pull requests are not obligated to avoid calling any portions of the standard library on the basis of a tier 3 target not implementing those portions.

The libstd PR will fully support core+alloc, and enough of std to run interesting programs (stdio, argv and fs) - so we can run tools like [imagecli](https://github.com/theotherphil/imagecli). But yes, major parts of std are missing - pipe, process and net are currently forwarded to `unsupported()`. Some barebones `net` should be possible, but e.g. cloning of the descriptor is unheard of in HelenOS, so it won't be as straightforward as the rest. Also, some places of the `fs` and `thread` module are also quite stubby (but part of it is just because HelenOS has no file permissions, for example). HelenOS is a small, experimental OS, so its own libc is stubbed out as well in some places. I hope this state is acceptable?

> The target must provide documentation for the Rust community explaining how to build for the target, using cross-compilation if possible. If the target supports running binaries, or running tests (even if they do not pass), the documentation must explain how to run such binaries or tests for the target, using emulation if possible or dedicated hardware if necessary.

I hope the guide in doc is sufficient.

> Tier 3 targets must not impose burden on the authors of pull requests, or other developers in the community, to maintain the target. In particular, do not post comments (automated or manual) on a PR that derail or suggest a block on the PR based on a tier 3 target. Do not send automated messages or notifications (via any medium, including via ``````@)`````` to a PR author or others involved with a PR regarding a tier 3 target, unless they have opted into such messages.

Understood.

> Patches adding or updating tier 3 targets must not break any existing tier 2 or tier 1 target, and must not knowingly break another tier 3 target without approval of either the compiler team or the maintainers of the other tier 3 target.

Understood.

> Tier 3 targets must be able to produce assembly using at least one of rustc's supported backends from any host target. (Having support in a fork of the backend is not sufficient, it must be upstream.)

Umm, I think this is satisfied? Code generation works with the default LLVM backend, even though it has no idea about HelenOS. And our GCC patch is then used only for linking.

</details>
rust-timer added a commit to rust-lang/rust that referenced this pull request Nov 1, 2025
Rollup merge of #139310 - mvolfik:helenos-compiler, r=wesleywiser

add first HelenOS compilation targets

I'm working on adding a HelenOS compilation target for Rust as my bachelor thesis. I understood that the policy for tier 3 targets is quite liberal, so here's my attempt at upstreaming the initial support. I'm quite new to Rust internals, so thanks in advance for all assistance with my stupid questions :)

libstd support is coming, but I understood compiler support must come first before libc bindings can get merged (rust-lang/libc#4355 (comment))

Locally, I also needed to update `cc-rs`, to do two things:

- add [here](https://github.com/rust-lang/cc-rs/blob/59578addda0233c8e9a0b399769cedb538ac8052/src/lib.rs#L3397) the binutils prefixes (`x86_64-unknown-helenos` -> `amd64-helenos`
- add the targets to `generated.rs`

From the "Adding tier 3 target" guide it sound like the latter will happen automatically, the first I need to do manually? I'm not sure if the test suite will pass or fail without it.

I'm also quite unsure about all the target spec configuration flags. I copied the specs from other small OSs with some tweaks and things seems to work now, but I have no idea how to better judge if it's correct.

Finally, I'm also working on support for arm (32-bit and 64), but there I'm currently running into some issues with linking, so I'll send that later, if I figure it out.

---

<details>
<summary>Tier 3 policy "form"</summary>

> A tier 3 target must have a designated developer or developers (the "target maintainers") on record to be CCed when issues arise regarding the target. (The mechanism to track and CC such developers may evolve over time.)

That would be me, I suppose. I agree.

> Targets must use naming consistent with any existing targets; for instance, a target for the same CPU or OS as an existing Rust target should use the same name for that CPU or OS. Targets should normally use the same names and naming conventions as used elsewhere in the broader ecosystem beyond Rust (such as in other toolchains), unless they have a very good reason to diverge. Changing the name of a target can be highly disruptive, especially once the target reaches a higher tier, so getting the name right is important even for a tier 3 target.

I'm using the standard Rust conventions.

> Tier 3 targets may have unusual requirements to build or use, but must not create legal issues or impose onerous legal terms for the Rust project or for Rust developers or users.
> - The target must not introduce license incompatibilities.
> - Anything added to the Rust repository must be under the standard Rust license (MIT OR Apache-2.0).

I am not aware of any legal issues. HelenOS itself is open-source under BSD license. All code contributed in this PR (and later for libstd) is either fully my own or an adaptation of existing code from this repo (some PAL pieces).

> - The target must not cause the Rust tools or libraries built for any other host (even when supporting cross-compilation to the target) to depend on any new dependency less permissive than the Rust licensing policy. This applies whether the dependency is a Rust crate that would require adding new license exceptions (as specified by the tidy tool in the rust-lang/rust repository), or whether the dependency is a native library or binary. In other words, the introduction of the target must not cause a user installing or running a version of Rust or the Rust tools to be subject to any new license requirements.

I am not adding any new dependencies.

> - Compiling, linking, and emitting functional binaries, libraries, or other code for the target (whether hosted on the target itself or cross-compiling from another target) must not depend on proprietary (non-FOSS) libraries. Host tools built for the target itself may depend on the ordinary runtime libraries supplied by the platform and commonly used by other applications built for the target, but those libraries must not be required for code generation for the target; cross-compilation to the target must not require such libraries at all. For instance, rustc built for the target may depend on a common proprietary C runtime library or console output library, but must not depend on a proprietary code generation library or code optimization library. Rust's license permits such combinations, but the Rust project has no interest in maintaining such combinations within the scope of Rust itself, even at tier 3.

The HelenOS build tools consist of open-source patches to GCC and binutils, so I suppose we're fine.

> Neither this policy nor any decisions made regarding targets shall create any binding agreement or estoppel by any party. If any member of an approving Rust team serves as one of the maintainers of a target, or has any legal or employment requirement (explicit or implicit) that might affect their decisions regarding a target, they must recuse themselves from any approval decisions regarding the target's tier status, though they may otherwise participate in discussions.

Understood.

> Tier 3 targets should attempt to implement as much of the standard libraries as possible and appropriate (core for most targets, alloc for targets that can support dynamic memory allocation, std for targets with an operating system or equivalent layer of system-provided functionality), but may leave some code unimplemented (either unavailable or stubbed out as appropriate), whether because the target makes it impossible to implement or challenging to implement. The authors of pull requests are not obligated to avoid calling any portions of the standard library on the basis of a tier 3 target not implementing those portions.

The libstd PR will fully support core+alloc, and enough of std to run interesting programs (stdio, argv and fs) - so we can run tools like [imagecli](https://github.com/theotherphil/imagecli). But yes, major parts of std are missing - pipe, process and net are currently forwarded to `unsupported()`. Some barebones `net` should be possible, but e.g. cloning of the descriptor is unheard of in HelenOS, so it won't be as straightforward as the rest. Also, some places of the `fs` and `thread` module are also quite stubby (but part of it is just because HelenOS has no file permissions, for example). HelenOS is a small, experimental OS, so its own libc is stubbed out as well in some places. I hope this state is acceptable?

> The target must provide documentation for the Rust community explaining how to build for the target, using cross-compilation if possible. If the target supports running binaries, or running tests (even if they do not pass), the documentation must explain how to run such binaries or tests for the target, using emulation if possible or dedicated hardware if necessary.

I hope the guide in doc is sufficient.

> Tier 3 targets must not impose burden on the authors of pull requests, or other developers in the community, to maintain the target. In particular, do not post comments (automated or manual) on a PR that derail or suggest a block on the PR based on a tier 3 target. Do not send automated messages or notifications (via any medium, including via ```@)``` to a PR author or others involved with a PR regarding a tier 3 target, unless they have opted into such messages.

Understood.

> Patches adding or updating tier 3 targets must not break any existing tier 2 or tier 1 target, and must not knowingly break another tier 3 target without approval of either the compiler team or the maintainers of the other tier 3 target.

Understood.

> Tier 3 targets must be able to produce assembly using at least one of rustc's supported backends from any host target. (Having support in a fork of the backend is not sufficient, it must be upstream.)

Umm, I think this is satisfied? Code generation works with the default LLVM backend, even though it has no idea about HelenOS. And our GCC patch is then used only for linking.

</details>
@tgross35
Copy link
Contributor

tgross35 commented Nov 2, 2025

Compiler support merged, so

@rustbot author

Note that we now also have the src/new module which is meant to mirror the header structure that a user can #include. If you're up for moving the HelenOS-specific bits there then that would be ideal (though not strictly necessary). The POSIX APIs could stay since they are going to get commonized separately.

@rustbot
Copy link
Collaborator

rustbot commented Nov 2, 2025

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@rustbot
Copy link
Collaborator

rustbot commented Nov 4, 2025

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@mvolfik mvolfik force-pushed the helenos-main branch 3 times, most recently from 6d219f9 to db3d144 Compare November 4, 2025 22:42
@mvolfik
Copy link
Author

mvolfik commented Nov 4, 2025

hm, seems like musl website is down, which causes the CI to fail :(

in the meantime, @tgross35 - I could rewrite this for the new structure, but I'm not exactly sure how - most of the systems have the new folders still empty, so I can't really use them as example.

Also, I'm not adding only HelenOS libc - some of the functionality required for standard library interfaces is also in libinet and libposix, + some definitions used in libc come from a bit weird locations in the HelenOS source tree, abi/include and common/include.1 Do you have any advice how this should be reflected for this project? (Or is it even right to include these other, albeit essential, libraries in the libc crate?)


1 These bits are somehow shared between the kernel and userspace libraries. During build of HelenOS, they get included alongside libc headers for distribution. For reference, I'm attaching a build of the HelenOS development files used for cross-compiling, afaik these artifacts aren't available from HelenOS CI
helenos-development-files.tar.gz

@tgross35
Copy link
Contributor

tgross35 commented Nov 4, 2025

hm, seems like musl website is down, which causes the CI to fail :(

Coincidentally I was working on getting a mirror set up, but currently can't because I can't download the source :)

in the meantime, @tgross35 - I could rewrite this for the new structure, but I'm not exactly sure how - most of the systems have the new folders still empty, so I can't really use them as example.

Also, I'm not adding only HelenOS libc - some of the functionality required for standard library interfaces is also in libinet and libposix, + some definitions used in libc come from a bit weird locations in the HelenOS source tree, abi/include and common/include.1 Do you have any advice how this should be reflected for this project? (Or is it even right to include these other, albeit essential, libraries in the libc crate?)

First off it's pretty new, so if anything feels too weird then feel free to leave it as-is and I'll clean it up when things are more established.

For structure the main thing is we'd like to make things a bit like what is #includeable. So if the user can #include <sys/socket> then there should be a sys::socket module, and we reexport it here

libc/src/new/mod.rs

Lines 172 to 204 in 83bd32f

cfg_if! {
if #[cfg(target_os = "android")] {
pub use sys::socket::*;
} else if #[cfg(target_os = "linux")] {
pub use linux::can::bcm::*;
pub use linux::can::j1939::*;
pub use linux::can::raw::*;
pub use linux::can::*;
pub use linux::keyctl::*;
#[cfg(target_env = "gnu")]
pub use net::route::*;
} else if #[cfg(target_vendor = "apple")] {
pub use signal::*;
} else if #[cfg(target_os = "netbsd")] {
pub use net::if_::*;
pub use sys::ipc::*;
pub use sys::statvfs::*;
pub use sys::time::*;
pub use sys::timex::*;
pub use sys::types::*;
pub use utmp_::*;
pub use utmpx_::*;
} else if #[cfg(target_os = "openbsd")] {
pub use sys::ipc::*;
}
}
// Per-env headers we export
cfg_if! {
if #[cfg(any(target_env = "musl", target_env = "ohos"))] {
pub use sys::socket::*;
}
}
.

The secondary thing is to match the source structure. And then reexport that in a way that matches the #includes, kind of echoing what the build system is doing. I can explain a bit more but I did that with glibc https://github.com/rust-lang/libc/blob/83bd32f8ac10bf20bba9509b06de5f242ca7c6ad/src/new/glibc/mod.rs, the nonpublic modules are source directories that don't exist in the final build (not available to #include from). Apple is another example, there are a few different repos that it pulls from.

Again, don't worry if this doesn't really work out - it's all pretty new :)

I can look a little closer at the specific API later, but libposix seems fine. However, is libinet needed for networking? (I'm not familiar with it)

@mvolfik
Copy link
Author

mvolfik commented Nov 5, 2025

yeah, there's no sockets in libc, all networking is done in libinet. This is kinda the helenos philosophy, to push as much from the system "core", and instead have everything as smaller libraries (it's a microkernel system, afterall). I'll try to do some restructuring

@mvolfik
Copy link
Author

mvolfik commented Nov 5, 2025

hmm, I hoped I would test this restructured patch with my rust stdlib patch, but I realized this isn't the 0.2 branch supported by libc.. and backporting this for 0.2 seems like quite a rewrite. What is the best path forward? Maybe make libstd depend on libc github master branch (for HelenOS only, obviously)?

and musl is down again :( it worked for me this morning >:(

@mvolfik
Copy link
Author

mvolfik commented Nov 5, 2025

aha, using different version of libc for HelenOS only is not possible anyways :( rust-lang/cargo#7753 so it's either 1) release 1.0 and force std onto it, 2) backport this, 3) or just wait.

backporting is quite complicated - the macros are named differently, the new structure is not there, and I'm not sure what else I'll run into even if I resolve these two..

@mvolfik mvolfik force-pushed the helenos-main branch 2 times, most recently from 6ac4616 to c5eb27f Compare November 5, 2025 18:18
@mvolfik
Copy link
Author

mvolfik commented Nov 5, 2025

hm, almost won the CI roulette this time. Is the segfault on freebsd something caused by me?

@tgross35
Copy link
Contributor

tgross35 commented Nov 5, 2025

yeah, there's no sockets in libc, all networking is done in libinet. This is kinda the helenos philosophy, to push as much from the system "core", and instead have everything as smaller libraries (it's a microkernel system, afterall). I'll try to do some restructuring

That makes sense, I think it is fine to include.

As a note though, we've been leaning away from adding #[link(name = "...")] in libc and instead preferring that this is done by the libraries that use them (e.g. std will do this) to avoid unconditionally pulling in dependencies that might not be used. And give them some better control.

hmm, I hoped I would test this restructured patch with my rust stdlib patch, but I realized this isn't the 0.2 branch supported by libc.. and backporting this for 0.2 seems like quite a rewrite. What is the best path forward? Maybe make libstd depend on libc github master branch (for HelenOS only, obviously)?

Backporting shouldn't be a problem, is your libc-0.2 branch up to date? I do backports in batches so there were a hundred or so commits that landed there in the past few days, including much of the new structure.

(Don't worry about backporting yourself unless you need to test, I'll take care of it in the next batch)

and musl is down again :( it worked for me this morning >:(

Once rust-lang/ci-mirrors#16 merges we'll have the mirrors, assuming it can actually download. If you rebase in a couple of hours hopefully I'll have a patch.

hm, almost won the CI roulette this time. Is the segfault on freebsd something caused by me?

Nope, FreeBSD-13 has a fun spurious segfault :) It's an optional job, I wish GH would display this better.

@mvolfik
Copy link
Author

mvolfik commented Nov 5, 2025

Backporting shouldn't be a problem, is your libc-0.2 branch up to date

ah, my upstream/libc-0.2 was up to date, but I was cherrypicking over the local libc-0.2 :D thanks for the nudge

all tested and should be ready for merge from my side. Could you please point me where in the stdlib I should add the #[link()] attributes to produce correct builds? Thanks for all the assistance!

@mvolfik
Copy link
Author

mvolfik commented Nov 20, 2025

@tgross35 do you have this in your backlog? I just wanted to check, I believed I addressed everything from your review, would be great to get this merged so I can continue with merging stdlib support :)

@tgross35
Copy link
Contributor

Oh hey sorry, I forgot this one was waiting on me. I'll try to get to it soon

Copy link
Contributor

@tgross35 tgross35 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks awesome, thank you making everything so well organized and providing links. I just have a few small requests.


extern "C" {
pub fn fibril_create_generic(
func: extern "C" fn(*mut c_void) -> errno_t,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Callbacks should take an unsafe extern "C" fn

pub fn readdir(dir: *mut DIR) -> *mut dirent;
pub fn closedir(dir: *mut DIR) -> c_int;
pub fn rewinddir(dir: *mut DIR);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit, extra space

Comment on lines +13 to +23
s! {
pub struct fibril_mutex_t {
pub oi: fibril_owner_info_t,
pub counter: c_int,
pub waiters: list_t,
}

pub struct fibril_condvar_t {
pub waiters: list_t,
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you also want rwlock for use in RwLock? Noblocking of course, I'm not sure whether you plan to use these APIs or the fallback in std anyway.

Comment on lines +6 to +10
use crate::{
c_void,
errno_t,
size_t,
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional nit: use crate::prelude::* is a bit preferred to import the ints since most refactoring assumes they are in scope, and it brings a few other useful things.

(Applies to a few of these files)

f! {
pub fn fibril_mutex_initialize(fm: *mut fibril_mutex_t) -> () {
let fm = &mut *fm;
fm.oi.owned_by = core::ptr::null_mut();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: If you use the prelude, core::ptr will be in scope

Comment on lines +26 to +31
pub fn fibril_mutex_initialize(fm: *mut fibril_mutex_t) -> () {
let fm = &mut *fm;
fm.oi.owned_by = core::ptr::null_mut();
fm.counter = 1;
list_initialize(&mut fm.waiters);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/HelenOS/helenos/blob/144fafda7cb6d43dfda1c93b8e46b8d51635e0c2/uspace/lib/c/include/fibril_synch.h#L55-L66 seems to effectively return a definition. Any reason not to do similar here and directly return a fibril_mutex_t, rather than using a pointer?

You may want to uppercase to match the definitions too.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I now see it has a self-referential list. I guess this is about as good as it gets, unfortunately.

Comment on lines +26 to +27
pub fn fibril_mutex_initialize(fm: *mut fibril_mutex_t) -> () {
let fm = &mut *fm;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe take a &mut fibril_mutex_t as the arg and make the function safe? Allows the caller to avoid a bit of unsafe if they have a known good reference.

Comment on lines +14 to +21
pub connected: extern "C" fn(conn: *mut tcp_conn_t),
pub conn_failed: extern "C" fn(conn: *mut tcp_conn_t),
pub conn_reset: extern "C" fn(conn: *mut tcp_conn_t),
pub data_avail: extern "C" fn(conn: *mut tcp_conn_t),
pub urg_data: extern "C" fn(conn: *mut tcp_conn_t),
}
pub struct tcp_listen_cb_t {
pub new_conn: extern "C" fn(listener: *mut tcp_listener_t, conn: *mut tcp_conn_t),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These callbacks should be unsafe

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

Labels

S-waiting-on-author stable-nominated This PR should be considered for cherry-pick to libc's stable release branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants