Skip to content

Commit

Permalink
Merge branch 'main' into NobodyXu-patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
NobodyXu authored Jun 30, 2024
2 parents 39355ca + fe9ccd1 commit dca6149
Show file tree
Hide file tree
Showing 23 changed files with 1,053 additions and 654 deletions.
30 changes: 21 additions & 9 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
name: Release-plz

permissions:
pull-requests: write
contents: write

on:
push:
tags:
- '*'
branches:
- main

jobs:
publish:
release-plz:
name: Release-plz
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Publish to crates.io
run: |
cargo publish
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Run release-plz
uses: MarcoIeni/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
5 changes: 5 additions & 0 deletions .github/workflows/regenerate-target-info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,13 @@ jobs:
- name: Install rust
run: |
rustup toolchain install stable nightly --no-self-update --profile minimal
- name: Create lockfile
run: cargo update

- uses: Swatinem/rust-cache@v2
with:
cache-all-crates: 'true'
- name: Regenerate target info
run: cargo run -p gen-target-info

Expand Down
51 changes: 51 additions & 0 deletions .github/workflows/regenerate-windows-sys.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Regenerate windows sys bindings

on:
workflow_dispatch: # Allow running on-demand
schedule:
- cron: '0 3 * * 5'

jobs:
regenerate:
name: Regenerate windows sys bindings & Open Pull Request if necessary
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
persist-credentials: true

- name: Generate branch name
run: |
git checkout -b regenerate-windows-sys-${{ github.run_id }}
- name: Create lockfile
run: cargo update

- uses: Swatinem/rust-cache@v2
with:
cache-all-crates: 'true'

- name: Regenerate windows sys bindings
run: cargo run -p gen-windows-sys-binding

- name: Detect changes
id: changes
run:
# This output boolean tells us if the dependencies have actually changed
echo "count=$(git status --porcelain=v1 | wc -l)" >> $GITHUB_OUTPUT

- name: Commit and push changes
# Only push if changes exist
if: steps.changes.outputs.count > 0
run: |
git config user.name github-actions
git config user.email [email protected]
git commit -am "Regenerate windows sys bindings"
git push origin HEAD
- name: Open pull request if needed
if: steps.changes.outputs.count > 0
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh pr create --base main --title "Regenerate windows sys bindings" --body "Automatically regenerated in CI"
36 changes: 36 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Changelog
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

## [1.0.102](https://github.com/rust-lang/cc-rs/compare/cc-v1.0.101...cc-v1.0.102) - 2024-06-29

### Other
- Fix invalid wasi targets compatibility ([#1105](https://github.com/rust-lang/cc-rs/pull/1105))
- Speedup regenerate-target-info and regenerate-windows-sys ([#1110](https://github.com/rust-lang/cc-rs/pull/1110))

## [1.0.101](https://github.com/rust-lang/cc-rs/compare/cc-v1.0.100...cc-v1.0.101) - 2024-06-25

### Other
- Use `Build::getenv` instead of `env::var*` in anywhere that makes sense ([#1103](https://github.com/rust-lang/cc-rs/pull/1103))

## [1.0.100](https://github.com/rust-lang/cc-rs/compare/cc-v1.0.99...cc-v1.0.100) - 2024-06-23

### Other
- Update publish.yml to use release-plz ([#1101](https://github.com/rust-lang/cc-rs/pull/1101))
- Accpet `OsStr` instead of `str` for flags ([#1100](https://github.com/rust-lang/cc-rs/pull/1100))
- Use `dep:` syntax to avoid implicit features. ([#1099](https://github.com/rust-lang/cc-rs/pull/1099))
- Minor clippy fixes. ([#1098](https://github.com/rust-lang/cc-rs/pull/1098))
- Fix WASI compilation for C++ ([#1083](https://github.com/rust-lang/cc-rs/pull/1083))
- Regenerate windows sys bindings ([#1096](https://github.com/rust-lang/cc-rs/pull/1096))
- Rename regenerate-windows-sys to regenerate-windows-sys.yml ([#1095](https://github.com/rust-lang/cc-rs/pull/1095))
- Create regenerate-windows-sys.yml ([#1094](https://github.com/rust-lang/cc-rs/pull/1094))
- Update windows-bindgen requirement from 0.56 to 0.57 ([#1091](https://github.com/rust-lang/cc-rs/pull/1091))
- Eagerly close tempfile to fix [#1082](https://github.com/rust-lang/cc-rs/pull/1082) ([#1087](https://github.com/rust-lang/cc-rs/pull/1087))
- Output msvc.exe in the output directory ([#1090](https://github.com/rust-lang/cc-rs/pull/1090))
- Fix clippy warnings on Windows ([#1088](https://github.com/rust-lang/cc-rs/pull/1088))
- Don't try to free DLL on drop ([#1089](https://github.com/rust-lang/cc-rs/pull/1089))
- Fix panic safety issue in StderrForwarder ([#1079](https://github.com/rust-lang/cc-rs/pull/1079))
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cc"
version = "1.0.98"
version = "1.0.102"
authors = ["Alex Crichton <[email protected]>"]
license = "MIT OR Apache-2.0"
repository = "https://github.com/rust-lang/cc-rs"
Expand Down Expand Up @@ -29,7 +29,7 @@ once_cell = { version = "1.19", optional = true }
libc = { version = "0.2.62", default-features = false, optional = true }

[features]
parallel = ["libc", "jobserver", "once_cell"]
parallel = ["dep:libc", "dep:jobserver", "dep:once_cell"]

[dev-dependencies]
tempfile = "3"
Expand Down
4 changes: 4 additions & 0 deletions clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
disallowed-methods = [
{ path = "std::env::var_os", reason = "Please use Build::getenv" },
{ path = "std::env::var", reason = "Please use Build::getenv" },
]
4 changes: 3 additions & 1 deletion dev-tools/cc-test/build.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(clippy::disallowed_methods)]

use std::env;
use std::fs;
use std::path::{Path, PathBuf};
Expand Down Expand Up @@ -169,7 +171,7 @@ fn main() {
#[track_caller]
fn run_forked_capture_output(out: &Path, action: &str) {
let program = env::current_exe().unwrap();
let output = Command::new(&program).arg(action).output().unwrap();
let output = Command::new(program).arg(action).output().unwrap();
assert!(output.status.success(), "output: {:#?}", output);
// we've captured the output and now we write it to a dedicated directory in the
// build output so our tests can access the output.
Expand Down
2 changes: 1 addition & 1 deletion dev-tools/cc-test/src/NMakefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ $(OUT_DIR)/msvc.o: src/msvc.c
$(CC) $(EXTRA_CFLAGS) -c $(CFLAG_OUTPUT)$@ src/msvc.c -MD

$(OUT_DIR)/msvc.exe: $(OUT_DIR)/msvc2.o
$(CC) $(EXTRA_CFLAGS) $(CFLAG_OUTPUT)$@ $(OUT_DIR)/msvc2.o
$(CC) $(EXTRA_CFLAGS) $(CFLAG_OUTPUT)$@ $(OUT_DIR)/msvc2.o -Fe:$(OUT_DIR)/msvc.exe

$(OUT_DIR)/msvc2.o: src/msvc.c
$(CC) $(EXTRA_CFLAGS) -c $(CFLAG_OUTPUT)$@ src/msvc.c -DMAIN -MD
2 changes: 1 addition & 1 deletion dev-tools/gen-target-info/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fn generate_riscv_arch_mapping(f: &mut File, target_specs: &RustcTargetSpecs) {
.iter()
.filter_map(|(target, target_spec)| {
let arch = target.split_once('-').unwrap().0;
(arch.contains("riscv") && arch != &target_spec.arch)
(arch.contains("riscv") && arch != target_spec.arch)
.then_some((arch, &*target_spec.arch))
})
.collect::<Vec<_>>();
Expand Down
2 changes: 1 addition & 1 deletion dev-tools/gen-windows-sys-binding/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ edition = "2018"
publish = false

[dependencies]
windows-bindgen = "0.56"
windows-bindgen = "0.57"
tempfile = "3"
1 change: 1 addition & 0 deletions src/bin/gcc-shim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
//! It is not intended for users and is not published with the library code to crates.io.
#![cfg_attr(test, allow(dead_code))]
#![allow(clippy::disallowed_methods)]

use std::env;
use std::fs::File;
Expand Down
50 changes: 26 additions & 24 deletions src/command_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pub(crate) struct CargoOutput {

impl CargoOutput {
pub(crate) fn new() -> Self {
#[allow(clippy::disallowed_methods)]
Self {
metadata: true,
warnings: true,
Expand Down Expand Up @@ -90,7 +91,6 @@ impl StderrForwarder {
}
}

#[allow(clippy::uninit_vec)]
fn forward_available(&mut self) -> bool {
if let Some((stderr, buffer)) = self.inner.as_mut() {
loop {
Expand All @@ -104,7 +104,7 @@ impl StderrForwarder {
let to_reserve = if self.is_non_blocking && !self.bytes_available_failed {
match crate::parallel::stderr::bytes_available(stderr) {
#[cfg(windows)]
Ok(0) => return false,
Ok(0) => break false,
#[cfg(unix)]
Ok(0) => {
// On Unix, depending on the implementation, we may sometimes get 0 in a
Expand All @@ -120,7 +120,7 @@ impl StderrForwarder {
write_warning(&buffer[..]);
}
self.inner = None;
return true;
break true;
}
#[cfg(unix)]
Err(_) => {
Expand All @@ -137,32 +137,21 @@ impl StderrForwarder {
};
buffer.reserve(to_reserve);

// SAFETY: 1) the length is set to the capacity, so we are never using memory beyond
// the underlying buffer and 2) we always call `truncate` below to set the len back
// to the initialized data.
unsafe {
buffer.set_len(buffer.capacity());
}
match stderr.read(&mut buffer[old_data_end..]) {
// Safety: stderr.read only writes to the spare part of the buffer, it never reads from it
match stderr
.read(unsafe { &mut *(buffer.spare_capacity_mut() as *mut _ as *mut [u8]) })
{
Err(err) if err.kind() == std::io::ErrorKind::WouldBlock => {
// No data currently, yield back.
buffer.truncate(old_data_end);
return false;
break false;
}
Err(err) if err.kind() == std::io::ErrorKind::Interrupted => {
// Interrupted, try again.
buffer.truncate(old_data_end);
}
Ok(0) | Err(_) => {
// End of stream: flush remaining data and bail.
if old_data_end > 0 {
write_warning(&buffer[..old_data_end]);
}
self.inner = None;
return true;
continue;
}
Ok(bytes_read) => {
buffer.truncate(old_data_end + bytes_read);
Ok(bytes_read) if bytes_read != 0 => {
// Safety: bytes_read bytes is written to spare part of the buffer
unsafe { buffer.set_len(old_data_end + bytes_read) };
let mut consumed = 0;
for line in buffer.split_inclusive(|&b| b == b'\n') {
// Only forward complete lines, leave the rest in the buffer.
Expand All @@ -173,6 +162,19 @@ impl StderrForwarder {
}
buffer.drain(..consumed);
}
res => {
// End of stream: flush remaining data and bail.
if old_data_end > 0 {
write_warning(&buffer[..old_data_end]);
}
if let Err(err) = res {
write_warning(
format!("Failed to read from child stderr: {err}").as_bytes(),
);
}
self.inner.take();
break true;
}
}
}
} else {
Expand Down Expand Up @@ -397,7 +399,7 @@ pub(crate) struct CmdAddOutputFileArgs {

pub(crate) fn command_add_output_file(cmd: &mut Command, dst: &Path, args: CmdAddOutputFileArgs) {
if args.is_assembler_msvc
|| (args.msvc && !args.clang && !args.gnu && !args.cuda && !(args.is_asm && args.is_arm))
|| !(!args.msvc || args.clang || args.gnu || args.cuda || (args.is_asm && args.is_arm))
{
let mut s = OsString::from("-Fo");
s.push(dst);
Expand Down
Loading

0 comments on commit dca6149

Please sign in to comment.