rust icon indicating copy to clipboard operation
rust copied to clipboard

Add support for custom JSON targets when using build-std.

Open c272 opened this issue 5 months ago • 12 comments

Currently, when building with build-std, some library build scripts check properties of the target by inspecting the target triple at env::TARGET, which is simply set to the filename of the JSON file when using JSON target files.

This patch alters these build scripts to use env::CARGO_CFG_* to fetch target information instead, allowing JSON target files describing platforms without restricted_std to build correctly when using -Z build-std. There are some weak assertions here (for example, nintendo && newlib), however this seems at least a marginal improvement on the existing solution.

Fixes https://github.com/rust-lang/wg-cargo-std-aware/issues/60.

c272 avatar Jan 22 '24 11:01 c272

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @Mark-Simulacrum (or someone else) soon.

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 Jan 22 '24 11:01 rustbot

To make sure I understand the problem this is solving, you have custom target spec JSON not named after the triplet for the target? E.g., it looks to me like making the file x86_64-linux-special-gnu.json would probably also make all of these build scripts work?

(Doesn't make this change a bad one but want to make sure I understand the problem)

Mark-Simulacrum avatar Jan 23 '24 00:01 Mark-Simulacrum

@Mark-Simulacrum Yes, renaming the JSON target file to include "linux" in the filename would allow the target to build (in the linked issue, the author is using mytarget.json, so none of the clauses match). The current behaviour seems a bit imprecise, for example you could currently name a target file "contour" or something similarly unrelated and catch the "nto" clause unknowingly, or have a valid target with a different filename that doesn't compile as above.

c272 avatar Jan 23 '24 09:01 c272

:umbrella: The latest upstream changes (presumably #117958) made this pull request unmergeable. Please resolve the merge conflicts.

bors avatar Jan 23 '24 12:01 bors

@bors r+ rollup

This looks good to me. Thanks!

Mark-Simulacrum avatar Jan 27 '24 18:01 Mark-Simulacrum

:pushpin: Commit 797cf5927872459a00ca3a2758216c8aa89cef2b has been approved by Mark-Simulacrum

It is now in the queue for this repository.

bors avatar Jan 27 '24 18:01 bors

@bors rollup=iffy

Mark-Simulacrum avatar Jan 28 '24 14:01 Mark-Simulacrum

:hourglass: Testing commit 797cf5927872459a00ca3a2758216c8aa89cef2b with merge 0d38e40343c59c824f06b49af91b1997055aa255...

bors avatar Jan 29 '24 11:01 bors

@bors r- Still need to fix the typo, apologies.

c272 avatar Jan 29 '24 11:01 c272

The job dist-android failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
[RUSTC-TIMING] object test:false 4.482
error: `futex_condvar::Condvar::new` is not yet stable as a const fn
   --> library/std/src/sync/condvar.rs:127:26
    |
127 |         Condvar { inner: sys::Condvar::new() }
    |
    = help: const-stable functions can only call other const-stable functions

error: `futex_mutex::Mutex::new` is not yet stable as a const fn
error: `futex_mutex::Mutex::new` is not yet stable as a const fn
   --> library/std/src/sync/mutex.rs:230:24
    |
230 |         Mutex { inner: sys::Mutex::new(), poison: poison::Flag::new(), data: UnsafeCell::new(t) }
    |
    = help: const-stable functions can only call other const-stable functions

error: `sys_common::once::futex::Once::new` is not yet stable as a const fn
error: `sys_common::once::futex::Once::new` is not yet stable as a const fn
  --> library/std/src/sync/once.rs:76:23
   |
76 |         Once { inner: sys::Once::new() }
   |                       ^^^^^^^^^^^^^^^^
   |
   = help: const-stable functions can only call other const-stable functions

error: `futex_rwlock::RwLock::new` is not yet stable as a const fn
    |
    |
161 |         RwLock { inner: sys::RwLock::new(), poison: poison::Flag::new(), data: UnsafeCell::new(t) }
    |
    = help: const-stable functions can only call other const-stable functions

[RUSTC-TIMING] std test:false 2.677

rust-log-analyzer avatar Jan 29 '24 11:01 rust-log-analyzer

:broken_heart: Test failed - checks-actions

bors avatar Jan 29 '24 11:01 bors

Fixed the typo, and the new patch should also fix the test failures - all linux-android targets report their OS as android and not linux, which I overlooked.

c272 avatar Jan 29 '24 14:01 c272

@bors r+

Mark-Simulacrum avatar Feb 11 '24 01:02 Mark-Simulacrum

:pushpin: Commit 1ecb08409d17f08a2a52013b99fd969018e404dd has been approved by Mark-Simulacrum

It is now in the queue for this repository.

bors avatar Feb 11 '24 01:02 bors

:hourglass: Testing commit 1ecb08409d17f08a2a52013b99fd969018e404dd with merge 0cbef48150e1fab161b5fd147b57ceb3f9272a52...

bors avatar Feb 11 '24 02:02 bors

:sunny: Test successful - checks-actions Approved by: Mark-Simulacrum Pushing 0cbef48150e1fab161b5fd147b57ceb3f9272a52 to master...

bors avatar Feb 11 '24 04:02 bors

Finished benchmarking commit (0cbef48150e1fab161b5fd147b57ceb3f9272a52): comparison URL.

Overall result: no relevant changes - no action needed

@rustbot label: -perf-regression

Instruction count

This benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
4.4% [4.4%, 4.4%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Cycles

This benchmark run did not return any relevant results for this metric.

Binary size

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
0.1% [0.1%, 0.1%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Bootstrap: 666.058s -> 668.04s (0.30%) Artifact size: 308.32 MiB -> 308.26 MiB (-0.02%)

rust-timer avatar Feb 11 '24 07:02 rust-timer