Skip to content

Commit e008f17

Browse files
authored
Merge branch 'alexcrichton:main' into master
2 parents dddc9e5 + fba7fed commit e008f17

File tree

11 files changed

+317
-37
lines changed

11 files changed

+317
-37
lines changed

.github/workflows/main.yml

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,25 @@ jobs:
8787
- run: cargo test ${{ matrix.no_run }} --manifest-path cc-test/Cargo.toml --target ${{ matrix.target }} --features parallel
8888
- run: cargo test ${{ matrix.no_run }} --manifest-path cc-test/Cargo.toml --target ${{ matrix.target }} --release
8989

90+
cuda:
91+
name: Test CUDA support
92+
runs-on: ubuntu-20.04
93+
steps:
94+
- uses: actions/checkout@master
95+
- name: Install cuda-minimal-build-11-4
96+
shell: bash
97+
run: |
98+
# https://developer.nvidia.com/cuda-downloads?target_os=Linux&target_arch=x86_64&Distribution=Ubuntu&target_version=20.04&target_type=deb_network
99+
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/cuda-ubuntu2004.pin
100+
sudo mv cuda-ubuntu2004.pin /etc/apt/preferences.d/cuda-repository-pin-600
101+
sudo apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/7fa2af80.pub
102+
sudo add-apt-repository "deb https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/ /"
103+
sudo apt-get update
104+
sudo apt-get -y install cuda-minimal-build-11-4
105+
- name: Test 'cudart' feature
106+
shell: bash
107+
run: env PATH=/usr/local/cuda/bin:$PATH cargo test --manifest-path cc-test/Cargo.toml --features test_cuda
108+
90109
msrv:
91110
name: MSRV
92111
runs-on: ${{ matrix.os }}
@@ -125,4 +144,4 @@ jobs:
125144
git add .
126145
git -c user.name='ci' -c user.email='ci' commit -m init
127146
git push -f -q https://git:${{ secrets.github_token }}@github.com/${{ github.repository }} HEAD:gh-pages
128-
if: github.event_name == 'push' && github.event.ref == 'refs/heads/master'
147+
if: github.event_name == 'push' && github.event.ref == 'refs/heads/main'

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "cc"
3-
version = "1.0.68"
3+
version = "1.0.73"
44
authors = ["Alex Crichton <alex@alexcrichton.com>"]
55
license = "MIT/Apache-2.0"
66
repository = "https://github.com/alexcrichton/cc-rs"

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ fn main() {
189189
cc::Build::new()
190190
// Switch to CUDA C++ library compilation using NVCC.
191191
.cuda(true)
192+
.cudart("static")
192193
// Generate code for Maxwell (GTX 970, 980, 980 Ti, Titan X).
193194
.flag("-gencode").flag("arch=compute_52,code=sm_52")
194195
// Generate code for Maxwell (Jetson TX1).

cc-test/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ test = false
1111

1212
[build-dependencies]
1313
cc = { path = ".." }
14+
which = "^4.0"
1415

1516
[features]
1617
parallel = ["cc/parallel"]
18+
test_cuda = []

cc-test/build.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,24 @@ fn main() {
3535
.cpp(true)
3636
.compile("baz");
3737

38+
if env::var("CARGO_FEATURE_TEST_CUDA").is_ok() {
39+
// Detect if there is CUDA compiler and engage "cuda" feature.
40+
let nvcc = match env::var("NVCC") {
41+
Ok(var) => which::which(var),
42+
Err(_) => which::which("nvcc"),
43+
};
44+
if nvcc.is_ok() {
45+
cc::Build::new()
46+
.cuda(true)
47+
.cudart("static")
48+
.file("src/cuda.cu")
49+
.compile("libcuda.a");
50+
51+
// Communicate [cfg(feature = "cuda")] to test/all.rs.
52+
println!("cargo:rustc-cfg=feature=\"cuda\"");
53+
}
54+
}
55+
3856
if target.contains("windows") {
3957
cc::Build::new().file("src/windows.c").compile("windows");
4058
}

cc-test/src/armv7.S

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.globl asm
2+
asm:
3+
mov r0, #7
4+
bx lr

cc-test/src/cuda.cu

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#include <cuda.h>
2+
3+
__global__ void kernel() {}
4+
5+
extern "C" void cuda_kernel() { kernel<<<1, 1>>>(); }

cc-test/tests/all.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,14 @@ fn opt_linkage() {
5656
assert_eq!(answer(), 42);
5757
}
5858
}
59+
60+
#[cfg(feature = "cuda")]
61+
#[test]
62+
fn cuda_here() {
63+
extern "C" {
64+
fn cuda_kernel();
65+
}
66+
unsafe {
67+
cuda_kernel();
68+
}
69+
}

0 commit comments

Comments
 (0)