Skip to content

Commit 378f6cd

Browse files
committed
Clean up codegen
1 parent 67ac8d1 commit 378f6cd

File tree

10 files changed

+26
-26
lines changed

10 files changed

+26
-26
lines changed

.cspell.json

+1-6
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,5 @@
4747
"dictionaries": ["bash", "rust"]
4848
}
4949
],
50-
"ignorePaths": [
51-
"target-specs/**",
52-
"tests/helper/src/gen/**",
53-
"tools/codegen/patches/**",
54-
"**/*.ld"
55-
]
50+
"ignorePaths": ["target-specs/**", "**/*.ld"]
5651
}

.gitattributes

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
* text=auto eol=lf
22
.github/.cspell/rust-dependencies.txt linguist-generated
3-
tests/helper/src/gen/** linguist-generated
3+
src/gen/** linguist-generated

.github/workflows/ci.yml

-1
Original file line numberDiff line numberDiff line change
@@ -793,7 +793,6 @@ jobs:
793793
steps:
794794
- uses: taiki-e/checkout-action@v1
795795
- uses: taiki-e/github-actions/install-rust@nightly
796-
- run: tools/no_atomic.sh
797796
- run: tools/gen.sh
798797
- id: diff
799798
run: tools/ci/gen.sh

DEVELOPMENT.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
portable-atomic/
1111
├── bench/ -- simple benchmarks
1212
├── build.rs -- build script
13-
├── no_atomic.rs -- definitions of statics used by build script (auto-generated)
1413
├── version.rs -- rustc version detection code used by build script
1514
├── portable-atomic-util/ -- crate that defines synchronization primitives built with portable-atomic
1615
├── src/
1716
│ ├── cfgs.rs -- definitions of cfg_{has,no}_* macros
17+
│ ├── gen/ -- code generated by tools/gen.sh
1818
│ ├── imp/
1919
│ │ ├── atomic128/ -- 128-bit atomic implementations on 64-bit architectures (mainly by asm)
2020
│ │ ├── atomic64/ -- 64-bit atomic implementations on 32-bit architectures (mainly by asm)

build.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@
88
mod version;
99
use self::version::{rustc_version, Version};
1010

11-
use std::{env, str};
11+
#[path = "src/gen/build.rs"]
12+
mod generated;
1213

13-
include!("no_atomic.rs");
14+
use std::{env, str};
1415

1516
fn main() {
1617
println!("cargo:rerun-if-changed=build.rs");
17-
println!("cargo:rerun-if-changed=no_atomic.rs");
18+
println!("cargo:rerun-if-changed=src/gen/build.rs");
1819
println!("cargo:rerun-if-changed=version.rs");
1920

2021
#[cfg(feature = "unsafe-assume-single-core")]
@@ -191,18 +192,18 @@ fn main() {
191192
} else {
192193
println!("cargo:rustc-cfg=portable_atomic_no_cfg_target_has_atomic");
193194
let target = &*convert_custom_linux_target(target);
194-
if NO_ATOMIC_CAS.contains(&target) {
195+
if generated::NO_ATOMIC_CAS.contains(&target) {
195196
println!("cargo:rustc-cfg=portable_atomic_no_atomic_cas");
196197
}
197-
if NO_ATOMIC_64.contains(&target) {
198+
if generated::NO_ATOMIC_64.contains(&target) {
198199
println!("cargo:rustc-cfg=portable_atomic_no_atomic_64");
199200
} else {
200201
// Otherwise, assuming `"max-atomic-width" == 64` or `"max-atomic-width" == 128`.
201202
}
202203
}
203204
}
204205
// We don't need to use convert_custom_linux_target here because all linux targets have atomics.
205-
if NO_ATOMIC.contains(&target) {
206+
if generated::NO_ATOMIC.contains(&target) {
206207
println!("cargo:rustc-cfg=portable_atomic_no_atomic_load_store");
207208
}
208209

no_atomic.rs src/gen/build.rs

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tools/ci/gen.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ git config user.name 'Taiki Endo'
1818
git config user.email '[email protected]'
1919

2020
has_update=''
21-
for path in no_atomic.rs src/gen/*; do
21+
for path in src/gen/*; do
2222
git add -N "${path}"
2323
if ! git diff --exit-code -- "${path}"; then
2424
git add "${path}"

tools/gen.sh

+2
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,6 @@ cd -- "$(dirname -- "$0")"/..
1212

1313
set -x
1414

15+
./tools/no_atomic.sh
16+
1517
./tools/target_spec.sh

tools/no_atomic.sh

+7-4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ cd -- "$(dirname -- "$0")"/..
1010
#
1111
# USAGE:
1212
# ./tools/no_atomic.sh
13+
#
14+
# This script is intended to be called by gen.sh, but can be called separately.
1315

1416
retry() {
1517
for i in {1..10}; do
@@ -26,7 +28,8 @@ bail() {
2628
exit 1
2729
}
2830

29-
file=no_atomic.rs
31+
file=src/gen/build.rs
32+
mkdir -p -- "$(dirname -- "${file}")"
3033

3134
# We don't refer to NO_ATOMIC_CAS and NO_ATOMIC_64 in nightly-2022-02-11+
3235
# because feature(cfg_target_has_atomic) stabilized. So, we get the list
@@ -77,19 +80,19 @@ cat >|"${file}" <<EOF
7780
// Note: This is the list as of nightly-2022-02-10. We don't refer to this in
7881
// nightly-2022-02-11+ because feature(cfg_target_has_atomic) stabilized.
7982
#[rustfmt::skip]
80-
static NO_ATOMIC_CAS: &[&str] = &[
83+
pub(crate) static NO_ATOMIC_CAS: &[&str] = &[
8184
${no_atomic_cas[*]}
8285
];
8386
8487
// Note: This is the list as of nightly-2022-02-10. We don't refer to this in
8588
// nightly-2022-02-11+ because feature(cfg_target_has_atomic) stabilized.
8689
#[rustfmt::skip]
87-
static NO_ATOMIC_64: &[&str] = &[
90+
pub(crate) static NO_ATOMIC_64: &[&str] = &[
8891
${no_atomic_64[*]}
8992
];
9093
9194
#[rustfmt::skip]
92-
static NO_ATOMIC: &[&str] = &[
95+
pub(crate) static NO_ATOMIC: &[&str] = &[
9396
${no_atomic}
9497
];
9598
EOF

tools/target_spec.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ cd -- "$(dirname -- "$0")"/..
1313
#
1414
# This script is intended to be called by gen.sh, but can be called separately.
1515

16-
utils_file=src/gen/utils.rs
17-
mkdir -p -- "$(dirname -- "${utils_file}")"
16+
file=src/gen/utils.rs
17+
mkdir -p -- "$(dirname -- "${file}")"
1818

1919
known_64_bit_arch=($(rustc -Z unstable-options --print all-target-specs-json | jq -r '. | to_entries[].value | if ."target-pointer-width" == "64" then .arch else empty end' | LC_ALL=C sort -u))
2020

21-
cat >|"${utils_file}" <<EOF
21+
cat >|"${file}" <<EOF
2222
// SPDX-License-Identifier: Apache-2.0 OR MIT
2323
// This file is @generated by ${0##*/}.
2424
// It is not intended for manual editing.

0 commit comments

Comments
 (0)