Skip to content

Commit 0b5d2cf

Browse files
authored
CI: Also test and lint Metal (MacOS/iOS) code (#215)
* CI: Also test and lint Metal (MacOS/iOS) code * Make Metal code compile * Force objc_exception to at least `0.1.2` * Force `libc` to at least `0.2` * metal: Fix `clippy::useless-vec`
1 parent a23af73 commit 0b5d2cf

4 files changed

Lines changed: 38 additions & 16 deletions

File tree

.github/workflows/ci.yml

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ jobs:
88
strategy:
99
matrix:
1010
include:
11-
- os: ubuntu-latest
12-
features: vulkan
13-
- os: windows-latest
14-
features: vulkan,d3d12
11+
- os: ubuntu-latest
12+
features: vulkan
13+
- os: windows-latest
14+
features: vulkan,d3d12
15+
- os: macos-latest
16+
features: vulkan,metal
1517
runs-on: ${{ matrix.os }}
1618
steps:
1719
- uses: actions/checkout@v4
@@ -23,10 +25,12 @@ jobs:
2325
strategy:
2426
matrix:
2527
include:
26-
- os: ubuntu-latest
27-
features: vulkan,visualizer
28-
- os: windows-latest
29-
features: vulkan,visualizer,d3d12,public-winapi
28+
- os: ubuntu-latest
29+
features: vulkan,visualizer
30+
- os: windows-latest
31+
features: vulkan,visualizer,d3d12,public-winapi
32+
- os: macos-latest
33+
features: vulkan,visualizer,metal
3034
runs-on: ${{ matrix.os }}
3135
steps:
3236
- uses: actions/checkout@v4
@@ -48,10 +52,12 @@ jobs:
4852
strategy:
4953
matrix:
5054
include:
51-
- os: ubuntu-latest
52-
features: vulkan,visualizer
53-
- os: windows-latest
54-
features: vulkan,visualizer,d3d12,public-winapi
55+
- os: ubuntu-latest
56+
features: vulkan,visualizer
57+
- os: windows-latest
58+
features: vulkan,visualizer,d3d12,public-winapi
59+
- os: macos-latest
60+
features: vulkan,visualizer,metal
5561
runs-on: ${{ matrix.os }}
5662
steps:
5763
- uses: actions/checkout@v4
@@ -62,13 +68,27 @@ jobs:
6268
uses: dtolnay/rust-toolchain@nightly
6369
- name: Generate lockfile with minimal dependency versions
6470
run: cargo +nightly generate-lockfile -Zminimal-versions
71+
- name: Bump `libc 0.1` version to `0.2` via `malloc_buf 0.0.6`
72+
if: ${{ runner.os == 'macOS' }}
73+
run: |
74+
# The 7-year-unmaintained malloc_buf (depended on via metal-rs->objc)
75+
# only allows using libc 0.2 since the 0.0.6 release, which is necessary
76+
# since the libc 0.1 range no longer compiles. Fortunately objc which
77+
# is also unmaintained for 4 years depends on malloc_buf >=0.0,<0.1.0,
78+
# allowing the 0.0.6 release to be used (but not the 1.0.0 release).
79+
cargo update -p malloc_buf --precise 0.0.6
80+
# Force 0.1.2, as older versions use the broken `gcc` crate
81+
cargo update -p objc_exception --precise 0.1.2
6582
- name: Cargo clippy with minimal-versions
6683
run: cargo +stable clippy --workspace --all-targets --features ${{ matrix.features }} --no-default-features -- -D warnings
6784

6885
doc:
6986
name: Build documentation
70-
# Windows supports the entire feature surface
71-
runs-on: windows-latest
87+
strategy:
88+
matrix:
89+
# Rely on Windows and Mac to also compile the Vulkan portion (via --all-features)
90+
os: [windows-latest, macos-latest]
91+
runs-on: ${{ matrix.os }}
7292
env:
7393
RUSTDOCFLAGS: -Dwarnings
7494
steps:

examples/metal-buffer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ fn main() {
7777
{
7878
let empty_array = metal::Array::from_slice(&[]);
7979
let acc_desc = metal::PrimitiveAccelerationStructureDescriptor::descriptor();
80-
acc_desc.set_geometry_descriptors(&empty_array);
80+
acc_desc.set_geometry_descriptors(empty_array);
8181
let sizes = device.acceleration_structure_sizes_with_descriptor(&acc_desc);
8282
let allocation_desc = AllocationCreateDesc::acceleration_structure_with_size(
8383
&device,

src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@
161161
//! ```no_run
162162
//! # #[cfg(feature = "metal")]
163163
//! # fn main() {
164+
//! # use std::sync::Arc;
164165
//! use gpu_allocator::metal::*;
165166
//!
166167
//! # let device = Arc::new(metal::Device::system_default().unwrap());
@@ -178,6 +179,7 @@
178179
//! ```no_run
179180
//! # #[cfg(feature = "metal")]
180181
//! # fn main() {
182+
//! # use std::sync::Arc;
181183
//! use gpu_allocator::metal::*;
182184
//! use gpu_allocator::MemoryLocation;
183185
//! # let device = Arc::new(metal::Device::system_default().unwrap());

src/metal/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ impl Allocator {
374374
}
375375

376376
pub fn new(desc: &AllocatorCreateDesc) -> Result<Self> {
377-
let heap_types = vec![
377+
let heap_types = [
378378
(MemoryLocation::GpuOnly, {
379379
let heap_desc = metal::HeapDescriptor::new();
380380
heap_desc.set_cpu_cache_mode(metal::MTLCPUCacheMode::DefaultCache);

0 commit comments

Comments
 (0)