Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into arm64ec
Browse files Browse the repository at this point in the history
  • Loading branch information
dpaoliello committed Dec 13, 2023
2 parents 52a3f46 + bfd68f2 commit 8011161
Show file tree
Hide file tree
Showing 24 changed files with 2,971 additions and 833 deletions.
6 changes: 6 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
version: 2
updates:
- package-ecosystem: "github-actions"
# Workflow files stored in the
# default location of `.github/workflows`
directory: "/"
schedule:
interval: "daily"
- package-ecosystem: cargo
directory: "/"
schedule:
Expand Down
104 changes: 60 additions & 44 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
name: CI
on: [push, pull_request]

env:
CARGO_INCREMENTAL: 0
CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse

jobs:
test:
name: Test
runs-on: ${{ matrix.os }}
strategy:
matrix:
build: [stable, beta, nightly, linux32, macos, aarch64-ios, win32, win64, mingw32, mingw64, windows-2016]
build: [stable, beta, nightly, linux32, macos, aarch64-ios, win32, win64, mingw32, mingw64, windows-2019]
include:
- build: stable
os: ubuntu-latest
Expand Down Expand Up @@ -40,35 +44,37 @@ jobs:
target: aarch64-pc-windows-msvc
no_run: --no-run
- build: win32
os: windows-2016
os: windows-2019
rust: stable-i686-msvc
target: i686-pc-windows-msvc
- build: win64
os: windows-latest
rust: stable
target: x86_64-pc-windows-msvc
- build: mingw32
os: windows-latest
# windows-latest, a.k.a. windows-2022, runner is equipped with
# a newer mingw toolchain, which appears to produce unexecutable
# mixed-language binaries in debug builds. Fall back to
# windows-2019 for now and revisit it later...
os: windows-2019
rust: stable-i686-gnu
target: i686-pc-windows-gnu
- build: mingw64
os: windows-latest
rust: stable-x86_64-gnu
target: x86_64-pc-windows-gnu
- build: windows-2016
os: windows-2016
- build: windows-2019
os: windows-2019
rust: stable-x86_64
target: x86_64-pc-windows-msvc
steps:
- uses: actions/checkout@master
- name: Update Rustup (temporary workaround)
run: rustup self update
shell: bash
if: startsWith(matrix.os, 'windows')
- uses: actions/checkout@v4
- name: Install Rust (rustup)
run: rustup update ${{ matrix.rust }} --no-self-update && rustup default ${{ matrix.rust }}
run: |
set -euxo pipefail
rustup toolchain install ${{ matrix.rust }} --no-self-update --profile minimal --target ${{ matrix.target }}
rustup default ${{ matrix.rust }}
shell: bash
- run: rustup target add ${{ matrix.target }}
- name: Install g++-multilib
run: |
set -e
Expand All @@ -80,68 +86,78 @@ jobs:
sudo apt-get update
sudo apt-get install g++-multilib
if: matrix.build == 'linux32'
- run: cargo build
- run: cargo test ${{ matrix.no_run }}
- run: cargo test ${{ matrix.no_run }} --features parallel
- run: cargo test ${{ matrix.no_run }} --manifest-path cc-test/Cargo.toml --target ${{ matrix.target }}
- run: cargo test ${{ matrix.no_run }} --manifest-path cc-test/Cargo.toml --target ${{ matrix.target }} --features parallel
- run: cargo test ${{ matrix.no_run }} --manifest-path cc-test/Cargo.toml --target ${{ matrix.target }} --release

check-tvos:
name: Test aarch64-apple-tvos
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust (rustup)
run: |
set -euxo pipefail
rustup toolchain install nightly --no-self-update --profile minimal
rustup component add rust-src --toolchain nightly
rustup default nightly
shell: bash
- run: cargo test -Z build-std=std --no-run --target aarch64-apple-tvos
- run: cargo test -Z build-std=std --no-run --features parallel --target aarch64-apple-tvos
- run: cargo test -Z build-std=std --no-run --manifest-path cc-test/Cargo.toml --target aarch64-apple-tvos
- run: cargo test -Z build-std=std --no-run --manifest-path cc-test/Cargo.toml --target aarch64-apple-tvos --features parallel
- run: cargo test -Z build-std=std --no-run --manifest-path cc-test/Cargo.toml --target aarch64-apple-tvos --release

cuda:
name: Test CUDA support
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@master
- name: Install cuda-minimal-build-11-4
- uses: actions/checkout@v4
- name: Install cuda-minimal-build-11-8
shell: bash
run: |
# https://developer.nvidia.com/cuda-downloads?target_os=Linux&target_arch=x86_64&Distribution=Ubuntu&target_version=20.04&target_type=deb_network
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/cuda-ubuntu2004.pin
sudo mv cuda-ubuntu2004.pin /etc/apt/preferences.d/cuda-repository-pin-600
sudo apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/7fa2af80.pub
sudo add-apt-repository "deb https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/ /"
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/cuda-keyring_1.0-1_all.deb
sudo dpkg -i cuda-keyring_1.0-1_all.deb
sudo apt-get update
sudo apt-get -y install cuda-minimal-build-11-4
sudo apt-get -y install cuda-minimal-build-11-8
- name: Test 'cudart' feature
shell: bash
run: env PATH=/usr/local/cuda/bin:$PATH cargo test --manifest-path cc-test/Cargo.toml --features test_cuda
run: |
PATH="/usr/local/cuda/bin:$PATH" cargo test --manifest-path cc-test/Cargo.toml --features test_cuda
msrv:
name: MSRV
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest]
steps:
- uses: actions/checkout@master
- uses: actions/checkout@v4
- name: Install Rust
run: rustup update 1.34.0 --no-self-update && rustup default 1.34.0
run: |
rustup toolchain install 1.53.0 --no-self-update --profile minimal
rustup toolchain install nightly --no-self-update --profile minimal
rustup default 1.53.0
shell: bash
- run: cargo build
- name: Create Cargo.lock with minimal version
run: cargo +nightly update -Zminimal-versions
- name: Cache downloaded crates since 1.53 is really slow in fetching
uses: Swatinem/rust-cache@v2
- run: cargo check --lib
- run: cargo check --lib --all-features

rustfmt:
name: Rustfmt
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: actions/checkout@v4
- name: Install Rust
run: rustup update stable && rustup default stable && rustup component add rustfmt
run: |
rustup toolchain install stable --no-self-update --profile minimal --component rustfmt
rustup default stable
shell: bash
- run: cargo fmt -- --check

publish_docs:
name: Publish Documentation
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Install Rust
run: rustup update stable && rustup default stable
- name: Build documentation
run: cargo doc --no-deps --all-features
- name: Publish documentation
run: |
cd target/doc
git init
git add .
git -c user.name='ci' -c user.email='ci' commit -m init
git push -f -q https://git:${{ secrets.github_token }}@github.com/${{ github.repository }} HEAD:gh-pages
if: github.event_name == 'push' && github.event.ref == 'refs/heads/main'
15 changes: 9 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[package]
name = "cc"
version = "1.0.73"
version = "1.0.84"
authors = ["Alex Crichton <[email protected]>"]
license = "MIT OR Apache-2.0"
repository = "https://github.com/alexcrichton/cc-rs"
homepage = "https://github.com/alexcrichton/cc-rs"
repository = "https://github.com/rust-lang/cc-rs"
homepage = "https://github.com/rust-lang/cc-rs"
documentation = "https://docs.rs/cc"
description = """
A build-time dependency for Cargo build scripts to assist in invoking the native
Expand All @@ -16,12 +16,15 @@ readme = "README.md"
categories = ["development-tools::build-utils"]
exclude = ["/.github"]
edition = "2018"
rust-version = "1.53"

[dependencies]
jobserver = { version = "0.1.16", optional = true }
[target.'cfg(unix)'.dependencies]
# Don't turn on the feature "std" for this, see https://github.com/rust-lang/cargo/issues/4866
# which is still an issue with `resolver = "1"`.
libc = { version = "0.2.62", default-features = false }

[features]
parallel = ["jobserver"]
parallel = []

[dev-dependencies]
tempfile = "3"
36 changes: 23 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ you can call them from Rust by declaring them in
your Rust code like so:

```rust,no_run
extern {
extern "C" {
fn foo_function();
fn bar_function(x: i32) -> i32;
}
Expand Down Expand Up @@ -83,9 +83,17 @@ number of different environment variables.
certain `TARGET`s, it also is assumed to know about other flags (most
common is `-fPIC`).
* `AR` - the `ar` (archiver) executable to use to build the static library.
* `CRATE_CC_NO_DEFAULTS` - the default compiler flags may cause conflicts in some cross compiling scenarios. Setting this variable will disable the generation of default compiler flags.
* `CRATE_CC_NO_DEFAULTS` - the default compiler flags may cause conflicts in
some cross compiling scenarios. Setting this variable
will disable the generation of default compiler
flags.
* `CXX...` - see [C++ Support](#c-support).

Furthermore, projects using this crate may specify custom environment variables
to be inspected, for example via the `Build::try_flags_from_environment`
function. Consult the project’s own documentation or its use of the `cc` crate
for any additional variables it may use.

Each of these variables can also be supplied with certain prefixes and suffixes,
in the following prioritized order:

Expand All @@ -94,7 +102,7 @@ in the following prioritized order:
3. `<build-kind>_<var>` - for example, `HOST_CC` or `TARGET_CFLAGS`
4. `<var>` - a plain `CC`, `AR` as above.

If none of these variables exist, cc-rs uses built-in defaults
If none of these variables exist, cc-rs uses built-in defaults.

In addition to the above optional environment variables, `cc-rs` has some
functions with hard requirements on some variables supplied by [cargo's
Expand Down Expand Up @@ -130,17 +138,17 @@ required varies per platform, but there are three broad categories:
* Unix platforms require `cc` to be the C compiler. This can be found by
installing cc/clang on Linux distributions and Xcode on macOS, for example.
* Windows platforms targeting MSVC (e.g. your target triple ends in `-msvc`)
require `cl.exe` to be available and in `PATH`. This is typically found in
standard Visual Studio installations and the `PATH` can be set up by running
the appropriate developer tools shell.
require Visual Studio to be installed. `cc-rs` attempts to locate it, and
if it fails, `cl.exe` is expected to be available in `PATH`. This can be
set up by running the appropriate developer tools shell.
* Windows platforms targeting MinGW (e.g. your target triple ends in `-gnu`)
require `cc` to be available in `PATH`. We recommend the
[MinGW-w64](http://mingw-w64.org) distribution, which is using the
[Win-builds](http://win-builds.org) installation system.
[MinGW-w64](https://www.mingw-w64.org/) distribution, which is using the
[Win-builds](http://win-builds.org/) installation system.
You may also acquire it via
[MSYS2](https://www.msys2.org/), as explained [here][msys2-help]. Make sure
to install the appropriate architecture corresponding to your installation of
rustc. GCC from older [MinGW](http://www.mingw.org) project is compatible
rustc. GCC from older [MinGW](http://www.mingw.org/) project is compatible
only with 32-bit rust compiler.

[msys2-help]: https://github.com/rust-lang/rust#building-on-windows
Expand All @@ -155,7 +163,7 @@ fn main() {
cc::Build::new()
.cpp(true) // Switch to C++ library compilation.
.file("foo.cpp")
.compile("libfoo.a");
.compile("foo");
}
```

Expand All @@ -170,7 +178,7 @@ The C++ standard library may be linked to the crate target. By default it's `lib
.cpp(true)
.file("foo.cpp")
.cpp_link_stdlib("stdc++") // use libstdc++
.compile("libfoo.a");
.compile("foo");
}
```
2. by setting the `CXXSTDLIB` environment variable.
Expand All @@ -182,7 +190,7 @@ Remember that C++ does name mangling so `extern "C"` might be required to enable
## CUDA C++ support
`cc-rs` also supports compiling CUDA C++ libraries by using the `cuda` method
on `Build` (currently for GNU/Clang toolchains only):
on `Build`:
```rust,no_run
fn main() {
Expand All @@ -200,8 +208,10 @@ fn main() {
.flag("-gencode").flag("arch=compute_60,code=sm_60")
// Generate code for Pascal (Jetson TX2).
.flag("-gencode").flag("arch=compute_62,code=sm_62")
// Generate code in parallel
.flag("-t0")
.file("bar.cu")
.compile("libbar.a");
.compile("bar");
}
```

Expand Down
12 changes: 12 additions & 0 deletions gen-windows-sys-binding/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
name = "gen-windows-sys-binding"
version = "0.0.0"
edition = "2021"
publish = false

[dependencies]
windows-bindgen = "0.49"

# Prevent this from interfering with workspaces
[workspace]
members = ["."]
62 changes: 62 additions & 0 deletions gen-windows-sys-binding/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
//! Adapted from
//! https://github.com/rust-lang/rust/blob/master/src/tools/generate-windows-sys/src/main.rs
use std::{
fs,
io::{self, Write},
};

/// This is printed to the file before the rest of the contents.
const PRELUDE: &str = r#"// This file is autogenerated.
//
// To add bindings, edit windows_sys.lst then run:
//
// ```
// cd generate-windows-sys/
// cargo run
// ```
"#;

const POSTLUDE: &str = r#"
/// Adapted from
/// [`core::ptr::invalid_mut()`](https://doc.rust-lang.org/src/core/ptr/mod.rs.html#600-607).
///
/// This function should actually use `core::mem::transmute` but due to msrv
/// we use `as` casting instead.
///
/// Once msrv is bumped to 1.56, replace this with `core::mem::transmute` since
/// it is const stablised in 1.56
///
/// NOTE that once supports `strict_provenance` we would also have to update
/// this.
const fn invalid_mut<T>(addr: usize) -> *mut T {
addr as *mut T
}
"#;

fn main() -> io::Result<()> {
// Load the list of APIs
let buffer = fs::read_to_string("windows_sys.list")?;
let names: Vec<&str> = buffer
.lines()
.filter_map(|line| {
let line = line.trim();
if line.is_empty() || line.starts_with("//") {
None
} else {
Some(line)
}
})
.collect();

// Write the bindings to windows-sys.rs
let bindings =
windows_bindgen::standalone_std(&names).replace("::core::ptr::invalid_mut", "invalid_mut");

let mut f = fs::File::create("../src/windows_sys.rs")?;
f.write_all(PRELUDE.as_bytes())?;
f.write_all(bindings.as_bytes())?;
f.write_all(POSTLUDE.as_bytes())?;

Ok(())
}
Loading

0 comments on commit 8011161

Please sign in to comment.