Skip to content

Commit

Permalink
Clean up codegen
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e committed Jan 15, 2025
1 parent 67ac8d1 commit f760203
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 19 deletions.
1 change: 0 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 7 additions & 6 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down Expand Up @@ -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");
}

Expand Down
6 changes: 3 additions & 3 deletions no_atomic.rs → src/gen/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// 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] = &[
"avr-unknown-gnu-atmega328",
"bpfeb-unknown-none",
"bpfel-unknown-none",
Expand All @@ -19,7 +19,7 @@ static NO_ATOMIC_CAS: &[&str] = &[
// 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] = &[
"arm-linux-androideabi",
"armebv7r-none-eabi",
"armebv7r-none-eabihf",
Expand Down Expand Up @@ -69,7 +69,7 @@ static NO_ATOMIC_64: &[&str] = &[
];

#[rustfmt::skip]
static NO_ATOMIC: &[&str] = &[
pub(crate) static NO_ATOMIC: &[&str] = &[
"bpfeb-unknown-none",
"bpfel-unknown-none",
"mipsel-sony-psx",
Expand Down
2 changes: 1 addition & 1 deletion tools/ci/gen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ git config user.name 'Taiki Endo'
git config user.email '[email protected]'

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}"
Expand Down
2 changes: 2 additions & 0 deletions tools/gen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Up @@ -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.
Expand Down

0 comments on commit f760203

Please sign in to comment.