rust icon indicating copy to clipboard operation
rust copied to clipboard

Add x86_64-unknown-linux-none target

Open morr0ne opened this issue 1 month ago • 25 comments

Adds a freestanding linux binary with no libc dependency. This is useful for writing programs written only in rust. It is also essential for writing low level stuff like libc or a dynamic linker.

Tier 3 policy:

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.)

I will be the designed maintainer for this target

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.

The target triple is consistent with other targets

Target names should not introduce undue confusion or ambiguity unless absolutely necessary to maintain ecosystem compatibility. For example, if the name of the target makes people extremely likely to form incorrect beliefs about what it targets, the name should be changed or augmented to disambiguate it. If possible, use only letters, numbers, dashes and underscores for the name. Periods (.) are known to cause issues in Cargo.

There is no confusion with other targets since it explicitly adds "none" at the end instead of omitting the environment

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 does not introduce any unusual requirement

The target must not introduce license incompatibilities.

There are no license incompatibilities

Anything added to the Rust repository must be under the standard Rust license (MIT OR Apache-2.0).

Everything added is under that license

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.

There are no 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.

There is no proprietary dependencies

"onerous" here is an intentionally subjective term. At a minimum, "onerous" legal/licensing terms include but are not limited to: non-disclosure requirements, non-compete requirements, contributor license agreements (CLAs) or equivalent, "non-commercial"/"research-only"/etc terms, requirements conditional on the employer or employment of any particular Rust developers, revocable terms, any requirements that create liability for the Rust project or its developers or users, or any requirements that adversely affect the livelihood or prospects of the Rust project or its developers or users.

No such terms exist for this target

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.

This requirement does not prevent part or all of this policy from being cited in an explicit contract or work agreement (e.g. to implement or maintain support for a target). This requirement exists to ensure that a developer or team responsible for reviewing and approving a target does not face any legal threats or obligations that would prevent them from freely exercising their judgment in such approval, even if such judgment involves subjective matters or goes beyond the letter of these requirements.

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 target already implements core. It might be possible in the future to add support for alloc and std by leveraging crates such as origin and rustix

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 believe the proper docs are added

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.

Backlinks such as those generated by the issue/PR tracker when linking to an issue or PR are not considered a violation of this policy, within reason. However, such messages (even on a separate repository) must not generate notifications to anyone involved with a PR who has not requested such notifications.

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.

In particular, this may come up when working on closely related targets, such as variations of the same architecture with different features. Avoid introducing unconditional uses of features that another variation of the target may not have; use conditional compilation or runtime detection, as appropriate, to let each target run code supported by that target.

No other targets are effected

Tier 3 targets must be able to produce assembly using at least one of rustc's supported backends from any host target.

The same backends used by other linux targets work without issues

morr0ne avatar May 11 '24 19:05 morr0ne

r? compiler-team

morr0ne avatar May 11 '24 19:05 morr0ne

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @GuillaumeGomez (or someone else) some time within the next two weeks.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

rustbot avatar May 11 '24 19:05 rustbot

Some changes occurred in src/doc/rustc/src/platform-support

cc @Nilstrieb

These commits modify compiler targets. (See the Target Tier Policy.)

rustbot avatar May 11 '24 19:05 rustbot

There are merge commits (commits with multiple parents) in your changes. We have a no merge policy so these commits will need to be removed for this pull request to be merged.

You can start a rebase with the following commands:

$ # rebase
$ git pull --rebase https://github.com/rust-lang/rust.git master
$ git push --force-with-lease

The following commits are merge commits:

  • 238e86af1adbee31033ab2978af12bd093de1550

rustbot avatar May 11 '24 19:05 rustbot

r? nielstrieb

GuillaumeGomez avatar May 11 '24 19:05 GuillaumeGomez

Failed to set assignee to nielstrieb: invalid assignee

Note: Only org members with at least the repository "read" role, users with write permissions, or people who have commented on the PR may be assigned.

rustbot avatar May 11 '24 19:05 rustbot

r? nilstrieb

GuillaumeGomez avatar May 11 '24 19:05 GuillaumeGomez

Arf didn't see that the reviewer was already changed... Putting back estebank.

r? estebank

GuillaumeGomez avatar May 11 '24 19:05 GuillaumeGomez

The job mingw-check-tidy failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
Getting action download info
Download action repository 'msys2/[email protected]' (SHA:cc11e9188b693c2b100158c3322424c4cc1dadea)
Download action repository 'actions/checkout@v4' (SHA:0ad4b8fadaa221de15dcec353f45205ec38ea70b)
Download action repository 'actions/upload-artifact@v4' (SHA:65462800fd760344b1a7b4382951275a0abb4808)
Complete job name: PR - mingw-check-tidy
git config --global core.autocrlf false
shell: /usr/bin/bash --noprofile --norc -e -o pipefail {0}
---
COPY scripts/sccache.sh /scripts/
RUN sh /scripts/sccache.sh

COPY host-x86_64/mingw-check/reuse-requirements.txt /tmp/
RUN pip3 install --no-deps --no-cache-dir --require-hashes -r /tmp/reuse-requirements.txt \
    && pip3 install virtualenv
COPY host-x86_64/mingw-check/validate-toolstate.sh /scripts/
COPY host-x86_64/mingw-check/validate-error-codes.sh /scripts/

# NOTE: intentionally uses python2 for x.py so we can test it still works.
# NOTE: intentionally uses python2 for x.py so we can test it still works.
# validate-toolstate only runs in our CI, so it's ok for it to only support python3.
ENV SCRIPT TIDY_PRINT_DIFF=1 python2.7 ../x.py test \
           --stage 0 src/tools/tidy tidyselftest --extra-checks=py:lint
# This file is autogenerated by pip-compile with Python 3.10
# by the following command:
#
#    pip-compile --allow-unsafe --generate-hashes reuse-requirements.in
---

#12 [5/8] COPY host-x86_64/mingw-check/reuse-requirements.txt /tmp/
#12 DONE 0.0s

#13 [6/8] RUN pip3 install --no-deps --no-cache-dir --require-hashes -r /tmp/reuse-requirements.txt     && pip3 install virtualenv
#13 0.438   Downloading binaryornot-0.4.4-py2.py3-none-any.whl (9.0 kB)
#13 0.457 Collecting boolean-py==4.0
#13 0.464   Downloading boolean.py-4.0-py3-none-any.whl (25 kB)
#13 0.482 Collecting chardet==5.1.0
---
#13 3.638 Building wheels for collected packages: reuse
#13 3.639   Building wheel for reuse (pyproject.toml): started
#13 3.959   Building wheel for reuse (pyproject.toml): finished with status 'done'
#13 3.960   Created wheel for reuse: filename=reuse-1.1.0-cp310-cp310-manylinux_2_35_x86_64.whl size=181117 sha256=f5f58750481f69515c2c0d1d503daf565e2565c370d07fc6aeb95fe3498b4269
#13 3.960   Stored in directory: /tmp/pip-ephem-wheel-cache-fo6v5to1/wheels/c2/3c/b9/1120c2ab4bd82694f7e6f0537dc5b9a085c13e2c69a8d0c76d
#13 3.962 Installing collected packages: boolean-py, binaryornot, setuptools, reuse, python-debian, markupsafe, license-expression, jinja2, chardet
#13 3.984   Attempting uninstall: setuptools
#13 3.985     Found existing installation: setuptools 59.6.0
#13 3.986     Not uninstalling setuptools at /usr/lib/python3/dist-packages, outside environment /usr
---
#13 5.234   Downloading virtualenv-20.26.1-py3-none-any.whl (3.9 MB)
#13 5.409      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 3.9/3.9 MB 22.7 MB/s eta 0:00:00
#13 5.465 Collecting filelock<4,>=3.12.2
#13 5.473   Downloading filelock-3.14.0-py3-none-any.whl (12 kB)
#13 5.493 Collecting distlib<1,>=0.3.7
#13 5.503   Downloading distlib-0.3.8-py2.py3-none-any.whl (468 kB)
#13 5.515      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 468.9/468.9 KB 46.8 MB/s eta 0:00:00
#13 5.547 Collecting platformdirs<5,>=3.9.1
#13 5.554   Downloading platformdirs-4.2.1-py3-none-any.whl (17 kB)
#13 5.640 Installing collected packages: distlib, platformdirs, filelock, virtualenv
#13 5.824 Successfully installed distlib-0.3.8 filelock-3.14.0 platformdirs-4.2.1 virtualenv-20.26.1
#13 DONE 5.9s

#14 [7/8] COPY host-x86_64/mingw-check/validate-toolstate.sh /scripts/
#14 DONE 0.0s
---
DirectMap4k:      233408 kB
DirectMap2M:     8155136 kB
DirectMap1G:    10485760 kB
##[endgroup]
Executing TIDY_PRINT_DIFF=1 python2.7 ../x.py test            --stage 0 src/tools/tidy tidyselftest --extra-checks=py:lint
+ TIDY_PRINT_DIFF=1 python2.7 ../x.py test --stage 0 src/tools/tidy tidyselftest --extra-checks=py:lint
    Finished `dev` profile [unoptimized] target(s) in 0.03s
##[endgroup]
downloading https://ci-artifacts.rust-lang.org/rustc-builds-alt/3349155ac082ed9034404428c8402e42a165d3d8/rust-dev-nightly-x86_64-unknown-linux-gnu.tar.xz
extracting /checkout/obj/build/cache/llvm-3349155ac082ed9034404428c8402e42a165d3d8-true/rust-dev-nightly-x86_64-unknown-linux-gnu.tar.xz to /checkout/obj/build/x86_64-unknown-linux-gnu/ci-llvm
---
    Finished `release` profile [optimized] target(s) in 26.11s
##[endgroup]
fmt check
tidy check
tidy error: tests/assembly/targets/: missing assembly test for x86_64_unknown_linux_none
removing old virtual environment
removing old virtual environment
creating virtual environment at '/checkout/obj/build/venv' using 'python3.10'
Requirement already satisfied: pip in ./build/venv/lib/python3.10/site-packages (24.0)
Collecting black==23.3.0 (from -r /checkout/src/tools/tidy/config/requirements.txt (line 7))
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.7/1.7 MB 47.7 MB/s eta 0:00:00
Collecting click==8.1.3 (from -r /checkout/src/tools/tidy/config/requirements.txt (line 34))
  Downloading click-8.1.3-py3-none-any.whl (96 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 96.6/96.6 kB 37.2 MB/s eta 0:00:00
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 96.6/96.6 kB 37.2 MB/s eta 0:00:00
Collecting importlib-metadata==6.7.0 (from -r /checkout/src/tools/tidy/config/requirements.txt (line 38))
  Downloading importlib_metadata-6.7.0-py3-none-any.whl (22 kB)
Collecting mypy-extensions==1.0.0 (from -r /checkout/src/tools/tidy/config/requirements.txt (line 42))
  Downloading mypy_extensions-1.0.0-py3-none-any.whl (4.7 kB)
Collecting packaging==23.1 (from -r /checkout/src/tools/tidy/config/requirements.txt (line 46))
  Downloading packaging-23.1-py3-none-any.whl (48 kB)
Collecting pathspec==0.11.1 (from -r /checkout/src/tools/tidy/config/requirements.txt (line 50))
  Downloading pathspec-0.11.1-py3-none-any.whl (29 kB)
Collecting platformdirs==3.6.0 (from -r /checkout/src/tools/tidy/config/requirements.txt (line 54))
  Downloading platformdirs-3.6.0-py3-none-any.whl (16 kB)
  Downloading platformdirs-3.6.0-py3-none-any.whl (16 kB)
Collecting ruff==0.0.272 (from -r /checkout/src/tools/tidy/config/requirements.txt (line 58))
  Downloading ruff-0.0.272-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (5.9 MB)
Collecting tomli==2.0.1 (from -r /checkout/src/tools/tidy/config/requirements.txt (line 77))
  Downloading tomli-2.0.1-py3-none-any.whl (12 kB)
Collecting typed-ast==1.5.4 (from -r /checkout/src/tools/tidy/config/requirements.txt (line 81))
  Downloading typed_ast-1.5.4-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (877 kB)
  Downloading typed_ast-1.5.4-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (877 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 877.7/877.7 kB 135.6 MB/s eta 0:00:00
Collecting typing-extensions==4.6.3 (from -r /checkout/src/tools/tidy/config/requirements.txt (line 107))
  Downloading typing_extensions-4.6.3-py3-none-any.whl (31 kB)
Collecting zipp==3.15.0 (from -r /checkout/src/tools/tidy/config/requirements.txt (line 114))
  Downloading zipp-3.15.0-py3-none-any.whl (6.8 kB)
Installing collected packages: zipp, typing-extensions, typed-ast, tomli, ruff, platformdirs, pathspec, packaging, mypy-extensions, click, importlib-metadata, black
Successfully installed black-23.3.0 click-8.1.3 importlib-metadata-6.7.0 mypy-extensions-1.0.0 packaging-23.1 pathspec-0.11.1 platformdirs-3.6.0 ruff-0.0.272 tomli-2.0.1 typed-ast-1.5.4 typing-extensions-4.6.3 zipp-3.15.0
some tidy checks failed
Build completed unsuccessfully in 0:00:58
  local time: Sat May 11 19:18:59 UTC 2024
  network time: Sat, 11 May 2024 19:18:59 GMT

rust-log-analyzer avatar May 11 '24 19:05 rust-log-analyzer

Removed the merge commit, sorry about that

morr0ne avatar May 11 '24 19:05 morr0ne

The job mingw-check-tidy failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
Getting action download info
Download action repository 'msys2/[email protected]' (SHA:cc11e9188b693c2b100158c3322424c4cc1dadea)
Download action repository 'actions/checkout@v4' (SHA:0ad4b8fadaa221de15dcec353f45205ec38ea70b)
Download action repository 'actions/upload-artifact@v4' (SHA:65462800fd760344b1a7b4382951275a0abb4808)
Complete job name: PR - mingw-check-tidy
git config --global core.autocrlf false
shell: /usr/bin/bash --noprofile --norc -e -o pipefail {0}
---
COPY scripts/sccache.sh /scripts/
RUN sh /scripts/sccache.sh

COPY host-x86_64/mingw-check/reuse-requirements.txt /tmp/
RUN pip3 install --no-deps --no-cache-dir --require-hashes -r /tmp/reuse-requirements.txt \
    && pip3 install virtualenv
COPY host-x86_64/mingw-check/validate-toolstate.sh /scripts/
COPY host-x86_64/mingw-check/validate-error-codes.sh /scripts/

# NOTE: intentionally uses python2 for x.py so we can test it still works.
# NOTE: intentionally uses python2 for x.py so we can test it still works.
# validate-toolstate only runs in our CI, so it's ok for it to only support python3.
ENV SCRIPT TIDY_PRINT_DIFF=1 python2.7 ../x.py test \
           --stage 0 src/tools/tidy tidyselftest --extra-checks=py:lint
# This file is autogenerated by pip-compile with Python 3.10
# by the following command:
#
#    pip-compile --allow-unsafe --generate-hashes reuse-requirements.in
---

#12 [5/8] COPY host-x86_64/mingw-check/reuse-requirements.txt /tmp/
#12 DONE 0.0s

#13 [6/8] RUN pip3 install --no-deps --no-cache-dir --require-hashes -r /tmp/reuse-requirements.txt     && pip3 install virtualenv
#13 0.424   Downloading binaryornot-0.4.4-py2.py3-none-any.whl (9.0 kB)
#13 0.439 Collecting boolean-py==4.0
#13 0.442   Downloading boolean.py-4.0-py3-none-any.whl (25 kB)
#13 0.454 Collecting chardet==5.1.0
---
#13 3.471 Building wheels for collected packages: reuse
#13 3.472   Building wheel for reuse (pyproject.toml): started
#13 3.796   Building wheel for reuse (pyproject.toml): finished with status 'done'
#13 3.797   Created wheel for reuse: filename=reuse-1.1.0-cp310-cp310-manylinux_2_35_x86_64.whl size=181117 sha256=f5f58750481f69515c2c0d1d503daf565e2565c370d07fc6aeb95fe3498b4269
#13 3.797   Stored in directory: /tmp/pip-ephem-wheel-cache-k8_loo0q/wheels/c2/3c/b9/1120c2ab4bd82694f7e6f0537dc5b9a085c13e2c69a8d0c76d
#13 3.800 Installing collected packages: boolean-py, binaryornot, setuptools, reuse, python-debian, markupsafe, license-expression, jinja2, chardet
#13 3.822   Attempting uninstall: setuptools
#13 3.823     Found existing installation: setuptools 59.6.0
#13 3.824     Not uninstalling setuptools at /usr/lib/python3/dist-packages, outside environment /usr
---
#13 5.051   Downloading virtualenv-20.26.1-py3-none-any.whl (3.9 MB)
#13 5.102      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 3.9/3.9 MB 80.4 MB/s eta 0:00:00
#13 5.153 Collecting filelock<4,>=3.12.2
#13 5.157   Downloading filelock-3.14.0-py3-none-any.whl (12 kB)
#13 5.186 Collecting platformdirs<5,>=3.9.1
#13 5.189   Downloading platformdirs-4.2.1-py3-none-any.whl (17 kB)
#13 5.205 Collecting distlib<1,>=0.3.7
#13 5.211   Downloading distlib-0.3.8-py2.py3-none-any.whl (468 kB)
#13 5.217      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 468.9/468.9 KB 110.7 MB/s eta 0:00:00
#13 5.303 Installing collected packages: distlib, platformdirs, filelock, virtualenv
#13 5.465 Successfully installed distlib-0.3.8 filelock-3.14.0 platformdirs-4.2.1 virtualenv-20.26.1
#13 DONE 5.5s

#14 [7/8] COPY host-x86_64/mingw-check/validate-toolstate.sh /scripts/
#14 DONE 0.0s
---
DirectMap4k:      200640 kB
DirectMap2M:     6090752 kB
DirectMap1G:    12582912 kB
##[endgroup]
Executing TIDY_PRINT_DIFF=1 python2.7 ../x.py test            --stage 0 src/tools/tidy tidyselftest --extra-checks=py:lint
+ TIDY_PRINT_DIFF=1 python2.7 ../x.py test --stage 0 src/tools/tidy tidyselftest --extra-checks=py:lint
    Finished `dev` profile [unoptimized] target(s) in 0.03s
##[endgroup]
downloading https://ci-artifacts.rust-lang.org/rustc-builds-alt/3349155ac082ed9034404428c8402e42a165d3d8/rust-dev-nightly-x86_64-unknown-linux-gnu.tar.xz
extracting /checkout/obj/build/cache/llvm-3349155ac082ed9034404428c8402e42a165d3d8-true/rust-dev-nightly-x86_64-unknown-linux-gnu.tar.xz to /checkout/obj/build/x86_64-unknown-linux-gnu/ci-llvm
---
    Finished `release` profile [optimized] target(s) in 26.04s
##[endgroup]
fmt check
tidy check
tidy error: tests/assembly/targets/: missing assembly test for x86_64_unknown_linux_none
removing old virtual environment
removing old virtual environment
creating virtual environment at '/checkout/obj/build/venv' using 'python3.10'
Requirement already satisfied: pip in ./build/venv/lib/python3.10/site-packages (24.0)
Collecting black==23.3.0 (from -r /checkout/src/tools/tidy/config/requirements.txt (line 7))
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.7/1.7 MB 51.2 MB/s eta 0:00:00
Collecting click==8.1.3 (from -r /checkout/src/tools/tidy/config/requirements.txt (line 34))
  Downloading click-8.1.3-py3-none-any.whl (96 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 96.6/96.6 kB 37.4 MB/s eta 0:00:00
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 96.6/96.6 kB 37.4 MB/s eta 0:00:00
Collecting importlib-metadata==6.7.0 (from -r /checkout/src/tools/tidy/config/requirements.txt (line 38))
  Downloading importlib_metadata-6.7.0-py3-none-any.whl (22 kB)
Collecting mypy-extensions==1.0.0 (from -r /checkout/src/tools/tidy/config/requirements.txt (line 42))
  Downloading mypy_extensions-1.0.0-py3-none-any.whl (4.7 kB)
Collecting packaging==23.1 (from -r /checkout/src/tools/tidy/config/requirements.txt (line 46))
  Downloading packaging-23.1-py3-none-any.whl (48 kB)
Collecting pathspec==0.11.1 (from -r /checkout/src/tools/tidy/config/requirements.txt (line 50))
  Downloading pathspec-0.11.1-py3-none-any.whl (29 kB)
Collecting platformdirs==3.6.0 (from -r /checkout/src/tools/tidy/config/requirements.txt (line 54))
  Downloading platformdirs-3.6.0-py3-none-any.whl (16 kB)
  Downloading platformdirs-3.6.0-py3-none-any.whl (16 kB)
Collecting ruff==0.0.272 (from -r /checkout/src/tools/tidy/config/requirements.txt (line 58))
  Downloading ruff-0.0.272-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (5.9 MB)
Collecting tomli==2.0.1 (from -r /checkout/src/tools/tidy/config/requirements.txt (line 77))
  Downloading tomli-2.0.1-py3-none-any.whl (12 kB)
Collecting typed-ast==1.5.4 (from -r /checkout/src/tools/tidy/config/requirements.txt (line 81))
  Downloading typed_ast-1.5.4-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (877 kB)
  Downloading typed_ast-1.5.4-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (877 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 877.7/877.7 kB 133.4 MB/s eta 0:00:00
Collecting typing-extensions==4.6.3 (from -r /checkout/src/tools/tidy/config/requirements.txt (line 107))
  Downloading typing_extensions-4.6.3-py3-none-any.whl (31 kB)
Collecting zipp==3.15.0 (from -r /checkout/src/tools/tidy/config/requirements.txt (line 114))
  Downloading zipp-3.15.0-py3-none-any.whl (6.8 kB)
Installing collected packages: zipp, typing-extensions, typed-ast, tomli, ruff, platformdirs, pathspec, packaging, mypy-extensions, click, importlib-metadata, black
Successfully installed black-23.3.0 click-8.1.3 importlib-metadata-6.7.0 mypy-extensions-1.0.0 packaging-23.1 pathspec-0.11.1 platformdirs-3.6.0 ruff-0.0.272 tomli-2.0.1 typed-ast-1.5.4 typing-extensions-4.6.3 zipp-3.15.0
some tidy checks failed
Build completed unsuccessfully in 0:00:59
  local time: Sat May 11 19:43:21 UTC 2024
  network time: Sat, 11 May 2024 19:43:21 GMT

rust-log-analyzer avatar May 11 '24 19:05 rust-log-analyzer

@morr0ne could you more fully explain the intended distinction between this target and the x86_64-unknown-none and x86_86-unknown-linux-gnu (with #![no_std]) targets?

workingjubilee avatar May 11 '24 21:05 workingjubilee

The target already implements core. It might be possible in the future to add support for alloc and std by leveraging crates such as origin and rustix

More particularly, I believe it should be clear from day 0 what the stdlib impls are supposed to be. It is not required that those implementations should be done, and it is fully possible for those to vary in details on the journey to implementation, but I believe it makes it much harder to follow platform support processes if "I intend to" is hedged into "might be possible maybe someday or not".

workingjubilee avatar May 11 '24 21:05 workingjubilee

@morr0ne could you more fully explain the intended distinction between this target and the x86_64-unknown-none and x86_86-unknown-linux-gnu (with #![no_std]) targets?

The existing *-gnu targets make the assumption that the target system is running a gnu environment, which in pratice means assuming glibc and the corresponding linker are present. This new target is intended for targets that make zero assumption about the environment beside the underlining kernel (linux) conventions. The intended use cases for this targets are mainly 2 at the moment:

  • Writing fully rust binaries that do not depend on libc
  • Writing low level code such a libc implementation itself

I have been using this target in my own projects for months at this point and the benefit is clear. Without this target there are workarounds to achieve the same goals but they piggyback off the existing gnu targets. This way we have a target that clearly states that we are running without a libc

More particularly, I believe it should be clear from day 0 what the stdlib impls are supposed to be. It is not required that those implementations should be done, and it is fully possible for those to vary in details on the journey to implementation, but I believe it makes it much harder to follow platform support processes if "I intend to" is hedged into "might be possible maybe someday or not".

Maybe I could have worded it better. Having std and alloc for this target is 100% possible, I have zero doubts about that. The "might" stems from me not knowing if that is within the scope of rust since that would require shipping an allocator with std. I can't confidently say "this target will support std and alloc" because I don't know if the rust projects wants such support for an enviroment-less target. What I can say is that if there's consensus and interest, it is possible to implement std and alloc

morr0ne avatar May 11 '24 21:05 morr0ne

To further expand on my previous comment. The *-gnu targets assume the compiled binary will run on a GNU/Linux system. This new target is meant to target only Linux itself.

morr0ne avatar May 11 '24 21:05 morr0ne

Maybe I could have worded it better. Having std and alloc for this target is 100% possible, I have zero doubts about that. The "might" stems from me not knowing if that is within the scope of rust since that would require shipping an allocator with std. I can't confidently say "this target will support std and alloc" because I don't know if the rust projects wants such support for an environment-less target. What I can say is that if there's consensus and interest, it is possible to implement std and alloc

Aha, okay! So you would be be happy to have this target with such implementations but also would be reasonably content without such implementations. Thank you, that clarifies the intent.

workingjubilee avatar May 11 '24 22:05 workingjubilee

I believe n order for this to land, beyond any policy questions that may need to be addressed, you will want to edit ./tests/assembly/targets/targets-elf.rs so that it has a new entry for this platform that resembles these:

https://github.com/rust-lang/rust/blob/78a77512702ab786f6f9345872d36d852454612c/tests/assembly/targets/targets-elf.rs#L546-L557

workingjubilee avatar May 11 '24 22:05 workingjubilee

Aha, okay! So you would be be happy to have this target with such implementations but also would be reasonably content without such implementations. Thank you, that clarifies the intent.

Yes exactly

I believe n order for this to land, beyond any policy questions that may need to be addressed, you will want to edit ./tests/assembly/targets/targets-elf.rs so that it has a new entry for this platform that resembles these:

I did see the ci is failing because of missing test. Perhaps I missed it in somewhere but I didn't see it documented in the guide I was following.

morr0ne avatar May 11 '24 23:05 morr0ne

Can you mention which guide you were following? We have a "do you emit the binary we were expecting" test for targets, even tier 3 ones, ever since a target once started to silently fail to produce the correct kind of binary overnight.

workingjubilee avatar May 11 '24 23:05 workingjubilee

Can you mention which guide you were following?

I used this documentation when I originally wrote the target: https://rustc-dev-guide.rust-lang.org/building/new-target.html And this one to open the pr: https://doc.rust-lang.org/nightly/rustc/target-tier-policy.html#adding-a-new-target

morr0ne avatar May 11 '24 23:05 morr0ne

It's mentioned in the latter:

Tier 3 targets must be able to produce assembly using at least one of rustc's supported backends from any host target.

But the directive to update the test in question can be added to the rustc-dev-guide.

workingjubilee avatar May 12 '24 03:05 workingjubilee

@morr0ne Is there a particular Linux version you believe this should target? It can harmonize with the existing targets, or use a higher minimum version.

As with the previous question, I am mostly attempting to capture a general intention rather than demanding you have a strong ideal. It may, for instance, allow the target to have more-compatible software with the systems you do support.

Of course, the Linux UAPI is pretty stable, fortunately, so you can also simply gracefully fallback.

workingjubilee avatar May 12 '24 19:05 workingjubilee

At the moment I can't really say I have strong requirements for a version. To actually be useful without a libc it definitely needs to rely on more modern versions of the kernel, at least compared to the existing *-gnu targets. It is hard to pin-point a specific version however and I am happy to leave it somewhat unspecified, at least until there is a clear path forward to implement std and alloc.

Generally speaking this target can be assumed to be somewhat bleeding edge. At the moment I work with the latest stable release of the kernel so it would be hard to notice if something is broken on older kernels

morr0ne avatar May 12 '24 20:05 morr0ne

@Nilstrieb do you want to snipe this review? I won't be around for a few days and this seems out of my wheelhouse. @workingjubilee thank you for taking on digging deeper on this!

estebank avatar May 13 '24 05:05 estebank

At the moment I can't really say I have strong requirements for a version. To actually be useful without a libc it definitely needs to rely on more modern versions of the kernel, at least compared to the existing *-gnu targets. It is hard to pin-point a specific version however and I am happy to leave it somewhat unspecified, at least until there is a clear path forward to implement std and alloc.

It would be good to document that an unknown kernel version, which is known to be greater than 3.19, because this affects whether getrandom can be used.

On Linux, it is normally required to route all direct syscall calls through libc's syscall(2). Without a libc for this target, does this mean that we're supposed to issue syscalls directly, without any coordination from the runtime system? And further, are we guaranteed that the process will never be linked to any libc that requires syscalls to be routed through it? I think this is important to specify because there's no point in having target_os=linux without the ability to actually use Linux features.

In particular, how would we ask the OS to allocate memory for us to implement a heap?

What is the minimum CPU feature set for this target? Since we cannot use (IIUC) libstd's std::arch::is_x86_feature_detected, are we allowed to use the results of CPUID + xgetbv to dynamically determine which CPU features are available?

briansmith avatar May 14 '24 01:05 briansmith

Some background discussion at https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/Direct.20syscalls.20on.20Linux, more in the vein of a std support. Having this target will be awesome.

tgross35 avatar May 14 '24 07:05 tgross35

It would be good to document that an unknown kernel version, which is known to be greater than 3.19, because this affects whether getrandom can be used.

It could be documented as such. But unless we have std we actually have no guarantee of such version. We might find out we actually can use a lower version, although unlikely.

On Linux, it is normally required to route all direct syscall calls through libc's syscall(2). Without a libc for this target, does this mean that we're supposed to issue syscalls directly, without any coordination from the runtime system?

Linux actually is the only mainstream os/kernel that allows us to make syscall directly. The userspace abi is stable and there is no standard libc. In a sense, there is no "runtime system" to coordinate with. There are many ways to make such syscalls but I believe the best solution is rustix, which I linked above.

And further, are we guaranteed that the process will never be linked to any libc that requires syscalls to be routed through it?

The point of this target is exactly to guarantee no libc is linked. Linux doesn't forces you to link to a libc implementation and even if that were the case, there is no issue calling direct syscalls even if linking to libc. There is no requirement to make syscalls from libc on linux, regardless of the target environment.

I think this is important to specify because there's no point in having target_os=linux without the ability to actually use Linux features.

The point of the target is to guarantee that we are running on top of the linux kernel. How syscalls are then made is up to the user in a no_std environments or up to std, however it decides to implement such calls.

In particular, how would we ask the OS to allocate memory for us to implement a heap?

We can ask the os via syscalls the same way the libc implementation does. Unlike other OSes, libc is not special on linux. There is nothing libc can do that we cannot do ourselves by calling direct syscalls or reading special virtual filesystems like /proc

What is the minimum CPU feature set for this target? Since we cannot use (IIUC) libstd's std::arch::is_x86_feature_detected, are we allowed to use the results of CPUID + xgetbv to dynamically determine which CPU features are available?

I do not know how std::arch::is_x86_feature_detected is implemented but I assume it is calling some libc function that can be replaced by our own implementation

morr0ne avatar May 14 '24 08:05 morr0ne

There is no requirement to make syscalls from libc on linux, regardless of the target environment.

This is not entirely true, libcs generally do not appreciate you calling some syscalls directly without talking to them first. This is of course a non-issue when the libc is not in the address space at all, but when it is linked in some other way, that can lead to problems (one example being the forking syscalls). I assume that's what the person meant.

Adding this target as a tier 3 no_std target makes sense. Any library implementation for this target should go to the libs team first to decide whether this is something that is desired in the first place.

Given that the target won't really rely on Linux kernel features for now, documenting the minimum version doesn't make that much sense imo - it's as low as anyone wants (though you can write something there if you feel like it). It would of course also need to be specified when adding a library implementation or relying on features.

Nilstrieb avatar May 14 '24 08:05 Nilstrieb

This is not entirely true, libcs generally do not appreciate you calling some syscalls directly without talking to them first. This is of course a non-issue when the libc is not in the address space at all, but when it is linked in some other way, that can lead to problems (one example being the forking syscalls). I assume that's what the person meant.

Maybe I missunderstood what they meant. Regardless this is a non issue since libc will not be linked in any way for this target.

Adding this target as a tier 3 no_std target makes sense. Any library implementation for this target should go to the libs team first to decide whether this is something that is desired in the first place.

That was exactly my thought process. Adding this as a tier 3 makes this easy to merge without issues and any library implementation can be properly discussed at a later point.

Given that the target won't really rely on Linux kernel features for now, documenting the minimum version doesn't make that much sense imo - it's as low as anyone wants (though you can write something there if you feel like it). It would of course also need to be specified when adding a library implementation or relying on features.

I fully agree with this and is exactly why I did not add a version in the documentation.

morr0ne avatar May 14 '24 08:05 morr0ne

In that case, this is good to merge.

I will approve this PR, adding a new tier 3 no_std target for bare Linux without libc. It does not commit to a rustix (or other)-based implementation of the standard library for bare Linux in the future (this should be discussed with the libs team first). As a tier 3 target, no builds are available and -Zbuild-std should be used. As usual, targets do not come with stability guarantees and may be removed in the future, especially tier 3 targets.

@bors r+

Nilstrieb avatar May 14 '24 09:05 Nilstrieb