Skip to content

Commit

Permalink
Merge #776
Browse files Browse the repository at this point in the history
776: Automatically creates PR when no_atomic.rs needs to be updated r=taiki-e a=taiki-e

follow-up #698

Co-authored-by: Taiki Endo <te316e89@gmail.com>
  • Loading branch information
bors[bot] and taiki-e committed Jan 23, 2022
2 parents 8d0080d + 4d02994 commit 85d0bdc
Show file tree
Hide file tree
Showing 17 changed files with 160 additions and 126 deletions.
39 changes: 35 additions & 4 deletions .github/workflows/ci.yml
Expand Up @@ -100,17 +100,40 @@ jobs:
run: ./ci/dependencies.sh

# When this job failed, run ci/no_atomic.sh and commit result changes.
# TODO(taiki-e): Ideally, this should be automated using a bot that creates
# PR when failed, but there is no bandwidth to implement it
# right now...
codegen:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- uses: actions/checkout@v2
- name: Install Rust
run: rustup update nightly && rustup default nightly
- run: ci/no_atomic.sh
- run: git diff --exit-code
- run: git add -N . && git diff --exit-code
if: github.event_name != 'schedule' && !(github.event_name == 'push' && github.ref == 'refs/heads/main')
- id: diff
run: |
git config user.name "Taiki Endo"
git config user.email "te316e89@gmail.com"
git add -N .
if ! git diff --exit-code; then
git add .
git commit -m "Update no_atomic.rs"
echo "::set-output name=success::false"
fi
if: github.event_name == 'schedule' || github.event_name == 'push' && github.ref == 'refs/heads/main'
- uses: taiki-e/create-pull-request@v3
with:
title: Update no_atomic.rs
body: |
Auto-generated by [create-pull-request][1]
[Please close and immediately reopen this pull request to run CI.][2]
[1]: https://github.com/peter-evans/create-pull-request
[2]: https://github.com/peter-evans/create-pull-request/blob/main/docs/concepts-guidelines.md#workarounds-to-trigger-further-workflow-runs
branch: update-no-atomic-sh
if: (github.event_name == 'schedule' || github.event_name == 'push' && github.ref == 'refs/heads/main') && steps.diff.outputs.success == 'false'

# Check formatting.
rustfmt:
Expand Down Expand Up @@ -172,6 +195,14 @@ jobs:
- name: docs
run: ./ci/docs.sh

shellcheck:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install shellcheck
uses: taiki-e/install-action@shellcheck
- run: shellcheck $(git ls-files '*.sh')

# This job doesn't actually test anything, but they're used to tell bors the
# build completed, as there is no practical way to detect when a workflow is
# successful listening to webhooks only.
Expand Down
4 changes: 2 additions & 2 deletions ci/check-features.sh
@@ -1,7 +1,7 @@
#!/bin/bash

set -euxo pipefail
IFS=$'\n\t'
cd "$(dirname "$0")"/..
set -ex

if [[ "$RUST_VERSION" != "nightly"* ]]; then
# On MSRV, features other than nightly should work.
Expand Down
4 changes: 2 additions & 2 deletions ci/clippy.sh
@@ -1,7 +1,7 @@
#!/bin/bash

set -euxo pipefail
IFS=$'\n\t'
cd "$(dirname "$0")"/..
set -ex

rustup component add clippy

Expand Down
4 changes: 2 additions & 2 deletions ci/crossbeam-epoch-loom.sh
@@ -1,7 +1,7 @@
#!/bin/bash

set -euxo pipefail
IFS=$'\n\t'
cd "$(dirname "$0")"/../crossbeam-epoch
set -ex

export RUSTFLAGS="-D warnings --cfg crossbeam_loom --cfg crossbeam_sanitize"

Expand Down
7 changes: 2 additions & 5 deletions ci/dependencies.sh
@@ -1,11 +1,10 @@
#!/bin/bash

set -euxo pipefail
IFS=$'\n\t'
cd "$(dirname "$0")"/..
set -ex

cargo tree
cargo tree --duplicate
cargo tree --duplicate || exit 1

# Check minimal versions.
# Remove dev-dependencies from Cargo.toml to prevent the next `cargo update`
Expand All @@ -15,5 +14,3 @@ cargo hack --remove-dev-deps --workspace
cargo update -Zminimal-versions
cargo tree
cargo hack check --all --all-features --exclude benchmarks

exit 0
4 changes: 2 additions & 2 deletions ci/docs.sh
@@ -1,7 +1,7 @@
#!/bin/bash

set -euxo pipefail
IFS=$'\n\t'
cd "$(dirname "$0")"/..
set -ex

export RUSTDOCFLAGS="-D warnings"

Expand Down
4 changes: 2 additions & 2 deletions ci/miri.sh
@@ -1,7 +1,7 @@
#!/bin/bash

set -euxo pipefail
IFS=$'\n\t'
cd "$(dirname "$0")"/..
set -ex

MIRIFLAGS="-Zmiri-tag-raw-pointers" \
cargo miri test \
Expand Down
102 changes: 53 additions & 49 deletions ci/no_atomic.sh
@@ -1,65 +1,69 @@
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'
cd "$(dirname "$0")"/..

# Update the list of targets that do not support atomic/CAS operations.
#
# Usage:
# ./ci/no_atomic.sh

set -euo pipefail
IFS=$'\n\t'

cd "$(cd "$(dirname "$0")" && pwd)"/..

file="no_atomic.rs"

{
echo "// This file is @generated by $(basename "$0")."
echo "// It is not intended for manual editing."
echo ""
} >"$file"

echo "const NO_ATOMIC_CAS: &[&str] = &[" >>"$file"
no_atomic_cas=()
no_atomic_64=()
no_atomic=()
for target in $(rustc --print target-list); do
res=$(rustc --print target-spec-json -Z unstable-options --target "$target" \
| jq -r "select(.\"atomic-cas\" == false)")
[[ -z "$res" ]] || echo " \"$target\"," >>"$file"
target_spec=$(rustc --print target-spec-json -Z unstable-options --target "${target}")
res=$(jq <<<"${target_spec}" -r 'select(."atomic-cas" == false)')
[[ -z "${res}" ]] || no_atomic_cas+=("${target}")
max_atomic_width=$(jq <<<"${target_spec}" -r '."max-atomic-width"')
case "${max_atomic_width}" in
# It is not clear exactly what `"max-atomic-width" == null` means, but they
# actually seem to have the same max-atomic-width as the target-pointer-width.
# The targets currently included in this group are "mipsel-sony-psp",
# "thumbv4t-none-eabi", "thumbv6m-none-eabi", all of which are
# `"target-pointer-width" == "32"`, so assuming them `"max-atomic-width" == 32`
# for now.
32 | null) no_atomic_64+=("${target}") ;;
# `"max-atomic-width" == 0` means that atomic is not supported at all.
0)
no_atomic_64+=("${target}")
no_atomic+=("${target}")
;;
64 | 128) ;;
# There is no `"max-atomic-width" == 16` or `"max-atomic-width" == 8` targets.
*) exit 1 ;;
esac
done
echo "];" >>"$file"

{
# Only crossbeam-utils actually uses this const.
echo "#[allow(dead_code)]"
echo "const NO_ATOMIC_64: &[&str] = &["
} >>"$file"
for target in $(rustc --print target-list); do
res=$(rustc --print target-spec-json -Z unstable-options --target "$target" \
| jq -r "select(.\"max-atomic-width\" == 32)")
[[ -z "$res" ]] || echo " \"$target\"," >>"$file"
done
# It is not clear exactly what `"max-atomic-width" == null` means, but they
# actually seem to have the same max-atomic-width as the target-pointer-width.
# The targets currently included in this group are "mipsel-sony-psp",
# "thumbv4t-none-eabi", "thumbv6m-none-eabi", all of which are
# `"target-pointer-width" == "32"`, so assuming them `"max-atomic-width" == 32`
# for now.
for target in $(rustc --print target-list); do
res=$(rustc --print target-spec-json -Z unstable-options --target "$target" \
| jq -r "select(.\"max-atomic-width\" == null)")
[[ -z "$res" ]] || echo " \"$target\"," >>"$file"
cat >"${file}" <<EOF
// This file is @generated by $(basename "$0").
// It is not intended for manual editing.
const NO_ATOMIC_CAS: &[&str] = &[
EOF
for target in "${no_atomic_cas[@]}"; do
echo " \"${target}\"," >>"${file}"
done
echo "];" >>"$file"
cat >>"${file}" <<EOF
];
# There is no `"max-atomic-width" == 16` or `"max-atomic-width" == 8` targets.
#[allow(dead_code)] // Only crossbeam-utils uses this.
const NO_ATOMIC_64: &[&str] = &[
EOF
for target in "${no_atomic_64[@]}"; do
echo " \"${target}\"," >>"${file}"
done
cat >>"${file}" <<EOF
];
# `"max-atomic-width" == 0` means that atomic is not supported at all.
{
# Only crossbeam-utils actually uses this const.
echo "#[allow(dead_code)]"
echo "const NO_ATOMIC: &[&str] = &["
} >>"$file"
for target in $(rustc --print target-list); do
res=$(rustc --print target-spec-json -Z unstable-options --target "$target" \
| jq -r "select(.\"max-atomic-width\" == 0)")
[[ -z "$res" ]] || echo " \"$target\"," >>"$file"
#[allow(dead_code)] // Only crossbeam-utils uses this.
const NO_ATOMIC: &[&str] = &[
EOF
for target in "${no_atomic[@]}"; do
echo " \"${target}\"," >>"${file}"
done
echo "];" >>"$file"
cat >>"${file}" <<EOF
];
EOF
4 changes: 2 additions & 2 deletions ci/rustfmt.sh
@@ -1,7 +1,7 @@
#!/bin/bash

set -euxo pipefail
IFS=$'\n\t'
cd "$(dirname "$0")"/..
set -ex

rustup component add rustfmt

Expand Down
6 changes: 3 additions & 3 deletions ci/san.sh
@@ -1,7 +1,7 @@
#!/bin/bash

set -euxo pipefail
IFS=$'\n\t'
cd "$(dirname "$0")"/..
set -ex

if [[ "$OSTYPE" != "linux"* ]]; then
exit 0
Expand Down Expand Up @@ -45,7 +45,7 @@ RUSTFLAGS="-Dwarnings -Zsanitizer=memory --cfg crossbeam_sanitize" \
cargo test -Zbuild-std --all --release --target x86_64-unknown-linux-gnu --tests --exclude benchmarks -- --test-threads=1

# Run thread sanitizer
export TSAN_OPTIONS="suppressions=$(pwd)/ci/tsan"
cargo clean
TSAN_OPTIONS="suppressions=$(pwd)/ci/tsan" \
RUSTFLAGS="-Dwarnings -Zsanitizer=thread --cfg crossbeam_sanitize" \
cargo test -Zbuild-std --all --release --target x86_64-unknown-linux-gnu --tests --exclude benchmarks -- --test-threads=1
6 changes: 3 additions & 3 deletions ci/test.sh
@@ -1,11 +1,11 @@
#!/bin/bash

set -euxo pipefail
IFS=$'\n\t'
cd "$(dirname "$0")"/..
set -ex

export RUSTFLAGS="-D warnings"

if [[ -n "$RUST_TARGET" ]]; then
if [[ -n "${RUST_TARGET:-}" ]]; then
# If RUST_TARGET is specified, use cross for testing.
cross test --all --target "$RUST_TARGET" --exclude benchmarks -- --test-threads=1

Expand Down
6 changes: 3 additions & 3 deletions crossbeam-channel/benchmarks/run.sh
@@ -1,12 +1,12 @@
#!/bin/bash

set -euxo pipefail
IFS=$'\n\t'
cd "$(dirname "$0")"
set -ex

cargo run --release --bin chan | tee chan.txt
cargo run --release --bin crossbeam-channel | tee crossbeam-channel.txt
cargo run --release --bin futures-channel | tee futures-channel.txt
cargo run --release --bin mpsc | tee mpsc.txt
go run go.go | tee go.txt

./plot.py *.txt
./plot.py ./*.txt
19 changes: 9 additions & 10 deletions crossbeam-epoch/build.rs
@@ -1,9 +1,3 @@
#![warn(rust_2018_idioms)]

use std::env;

include!("no_atomic.rs");

// The rustc-cfg listed below are considered public API, but it is *unstable*
// and outside of the normal semver guarantees:
//
Expand All @@ -13,10 +7,15 @@ include!("no_atomic.rs");
// need to enable it manually when building for custom targets or using
// non-cargo build systems that don't run the build script.
//
// With the exceptions mentioned above, the rustc-cfg strings below are
// *not* public API. Please let us know by opening a GitHub issue if your build
// environment requires some way to enable these cfgs other than by executing
// our build script.
// With the exceptions mentioned above, the rustc-cfg emitted by the build
// script are *not* public API.

#![warn(rust_2018_idioms)]

use std::env;

include!("no_atomic.rs");

fn main() {
let target = match env::var("TARGET") {
Ok(target) => target,
Expand Down
19 changes: 9 additions & 10 deletions crossbeam-queue/build.rs
@@ -1,9 +1,3 @@
#![warn(rust_2018_idioms)]

use std::env;

include!("no_atomic.rs");

// The rustc-cfg listed below are considered public API, but it is *unstable*
// and outside of the normal semver guarantees:
//
Expand All @@ -13,10 +7,15 @@ include!("no_atomic.rs");
// need to enable it manually when building for custom targets or using
// non-cargo build systems that don't run the build script.
//
// With the exceptions mentioned above, the rustc-cfg strings below are
// *not* public API. Please let us know by opening a GitHub issue if your build
// environment requires some way to enable these cfgs other than by executing
// our build script.
// With the exceptions mentioned above, the rustc-cfg emitted by the build
// script are *not* public API.

#![warn(rust_2018_idioms)]

use std::env;

include!("no_atomic.rs");

fn main() {
let target = match env::var("TARGET") {
Ok(target) => target,
Expand Down
19 changes: 9 additions & 10 deletions crossbeam-skiplist/build.rs
@@ -1,9 +1,3 @@
#![warn(rust_2018_idioms)]

use std::env;

include!("no_atomic.rs");

// The rustc-cfg listed below are considered public API, but it is *unstable*
// and outside of the normal semver guarantees:
//
Expand All @@ -13,10 +7,15 @@ include!("no_atomic.rs");
// need to enable it manually when building for custom targets or using
// non-cargo build systems that don't run the build script.
//
// With the exceptions mentioned above, the rustc-cfg strings below are
// *not* public API. Please let us know by opening a GitHub issue if your build
// environment requires some way to enable these cfgs other than by executing
// our build script.
// With the exceptions mentioned above, the rustc-cfg emitted by the build
// script are *not* public API.

#![warn(rust_2018_idioms)]

use std::env;

include!("no_atomic.rs");

fn main() {
let target = match env::var("TARGET") {
Ok(target) => target,
Expand Down

0 comments on commit 85d0bdc

Please sign in to comment.