Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Clean up codegen
Browse files Browse the repository at this point in the history
taiki-e committed Jan 15, 2025
1 parent 67ac8d1 commit 53c8409
Showing 10 changed files with 25 additions and 22 deletions.
2 changes: 0 additions & 2 deletions .cspell.json
Original file line number Diff line number Diff line change
@@ -49,8 +49,6 @@
],
"ignorePaths": [
"target-specs/**",
"tests/helper/src/gen/**",
"tools/codegen/patches/**",
"**/*.ld"
]
}
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
* text=auto eol=lf
.github/.cspell/rust-dependencies.txt linguist-generated
tests/helper/src/gen/** linguist-generated
src/gen/** linguist-generated
1 change: 0 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -793,7 +793,6 @@ jobs:
steps:
- uses: taiki-e/checkout-action@v1
- uses: taiki-e/github-actions/install-rust@nightly
- run: tools/no_atomic.sh
- run: tools/gen.sh
- id: diff
run: tools/ci/gen.sh
2 changes: 1 addition & 1 deletion DEVELOPMENT.md
Original file line number Diff line number Diff line change
@@ -10,11 +10,11 @@
portable-atomic/
├── bench/ -- simple benchmarks
├── build.rs -- build script
├── no_atomic.rs -- definitions of statics used by build script (auto-generated)
├── version.rs -- rustc version detection code used by build script
├── portable-atomic-util/ -- crate that defines synchronization primitives built with portable-atomic
├── src/
│ ├── cfgs.rs -- definitions of cfg_{has,no}_* macros
│ ├── gen/ -- code generated by tools/gen.sh
│ ├── imp/
│ │ ├── atomic128/ -- 128-bit atomic implementations on 64-bit architectures (mainly by asm)
│ │ ├── atomic64/ -- 64-bit atomic implementations on 32-bit architectures (mainly by asm)
13 changes: 7 additions & 6 deletions build.rs
Original file line number Diff line number Diff line change
@@ -8,13 +8,14 @@
mod version;
use self::version::{rustc_version, Version};

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

include!("no_atomic.rs");
use std::{env, str};

fn main() {
println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rerun-if-changed=no_atomic.rs");
println!("cargo:rerun-if-changed=src/gen/build.rs");
println!("cargo:rerun-if-changed=version.rs");

#[cfg(feature = "unsafe-assume-single-core")]
@@ -191,18 +192,18 @@ fn main() {
} else {
println!("cargo:rustc-cfg=portable_atomic_no_cfg_target_has_atomic");
let target = &*convert_custom_linux_target(target);
if NO_ATOMIC_CAS.contains(&target) {
if generated::NO_ATOMIC_CAS.contains(&target) {
println!("cargo:rustc-cfg=portable_atomic_no_atomic_cas");
}
if NO_ATOMIC_64.contains(&target) {
if generated::NO_ATOMIC_64.contains(&target) {
println!("cargo:rustc-cfg=portable_atomic_no_atomic_64");
} else {
// Otherwise, assuming `"max-atomic-width" == 64` or `"max-atomic-width" == 128`.
}
}
}
// We don't need to use convert_custom_linux_target here because all linux targets have atomics.
if NO_ATOMIC.contains(&target) {
if generated::NO_ATOMIC.contains(&target) {
println!("cargo:rustc-cfg=portable_atomic_no_atomic_load_store");
}

6 changes: 3 additions & 3 deletions no_atomic.rs → src/gen/build.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tools/ci/gen.sh
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@ git config user.name 'Taiki Endo'
git config user.email 'te316e89@gmail.com'

has_update=''
for path in no_atomic.rs src/gen/*; do
for path in src/gen/*; do
git add -N "${path}"
if ! git diff --exit-code -- "${path}"; then
git add "${path}"
2 changes: 2 additions & 0 deletions tools/gen.sh
Original file line number Diff line number Diff line change
@@ -12,4 +12,6 @@ cd -- "$(dirname -- "$0")"/..

set -x

./tools/no_atomic.sh

./tools/target_spec.sh
11 changes: 7 additions & 4 deletions tools/no_atomic.sh
Original file line number Diff line number Diff line change
@@ -10,6 +10,8 @@ cd -- "$(dirname -- "$0")"/..
#
# USAGE:
# ./tools/no_atomic.sh
#
# This script is intended to be called by gen.sh, but can be called separately.

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

file=no_atomic.rs
file=src/gen/build.rs
mkdir -p -- "$(dirname -- "${file}")"

# We don't refer to NO_ATOMIC_CAS and NO_ATOMIC_64 in nightly-2022-02-11+
# because feature(cfg_target_has_atomic) stabilized. So, we get the list
@@ -77,19 +80,19 @@ cat >|"${file}" <<EOF
// Note: This is the list as of nightly-2022-02-10. We don't refer to this in
// nightly-2022-02-11+ because feature(cfg_target_has_atomic) stabilized.
#[rustfmt::skip]
static NO_ATOMIC_CAS: &[&str] = &[
pub(crate) static NO_ATOMIC_CAS: &[&str] = &[
${no_atomic_cas[*]}
];
// Note: This is the list as of nightly-2022-02-10. We don't refer to this in
// nightly-2022-02-11+ because feature(cfg_target_has_atomic) stabilized.
#[rustfmt::skip]
static NO_ATOMIC_64: &[&str] = &[
pub(crate) static NO_ATOMIC_64: &[&str] = &[
${no_atomic_64[*]}
];
#[rustfmt::skip]
static NO_ATOMIC: &[&str] = &[
pub(crate) static NO_ATOMIC: &[&str] = &[
${no_atomic}
];
EOF
6 changes: 3 additions & 3 deletions tools/target_spec.sh
Original file line number Diff line number Diff line change
@@ -13,12 +13,12 @@ cd -- "$(dirname -- "$0")"/..
#
# This script is intended to be called by gen.sh, but can be called separately.

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

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

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

0 comments on commit 53c8409

Please sign in to comment.