Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set and test MSRV at 1.82 #350

Merged
merged 1 commit into from
Mar 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ jobs:

strategy:
matrix:
channel: [stable, nightly]
channel: [1.82, stable, nightly]

steps:
- uses: actions/checkout@v4

- name: Setup rust toolchain
uses: dtolnay/rust-toolchain@stable
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.channel }}

Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ exclude = [
"Cargo.lock",
"target/**/*",
]
rust-version = "1.82"

[package.metadata.docs.rs]
targets = [
Expand Down
4 changes: 2 additions & 2 deletions examples/circle/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ fn main() {
device.sample_timestamps(&mut cpu_start, &mut gpu_start);
let counter_sample_buffer = create_counter_sample_buffer(&device);
let destination_buffer = device.new_buffer(
(std::mem::size_of::<u64>() * 4 as usize) as u64,
(size_of::<u64>() * 4 as usize) as u64,
MTLResourceOptions::StorageModeShared,
);
let counter_sampling_point = MTLCounterSamplingPoint::AtStageBoundary;
Expand Down Expand Up @@ -116,7 +116,7 @@ fn main() {

device.new_buffer_with_data(
vertex_data.as_ptr() as *const _,
(vertex_data.len() * mem::size_of::<AAPLVertex>()) as u64,
(vertex_data.len() * size_of::<AAPLVertex>()) as u64,
MTLResourceOptions::CPUCacheModeDefaultCache | MTLResourceOptions::StorageModeManaged,
)
};
Expand Down
4 changes: 2 additions & 2 deletions examples/compute/compute-argument-buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ fn main() {

let buffer = device.new_buffer_with_data(
unsafe { mem::transmute(data.as_ptr()) },
(data.len() * mem::size_of::<u32>()) as u64,
(data.len() * size_of::<u32>()) as u64,
MTLResourceOptions::CPUCacheModeDefaultCache,
);

let sum = {
let data = [0u32];
device.new_buffer_with_data(
unsafe { mem::transmute(data.as_ptr()) },
(data.len() * mem::size_of::<u32>()) as u64,
(data.len() * size_of::<u32>()) as u64,
MTLResourceOptions::CPUCacheModeDefaultCache,
)
};
Expand Down
6 changes: 3 additions & 3 deletions examples/compute/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fn main() {

let counter_sample_buffer = create_counter_sample_buffer(&device);
let destination_buffer = device.new_buffer(
(std::mem::size_of::<u64>() * NUM_SAMPLES as usize) as u64,
(size_of::<u64>() * NUM_SAMPLES as usize) as u64,
MTLResourceOptions::StorageModeShared,
);

Expand Down Expand Up @@ -171,15 +171,15 @@ fn create_input_and_output_buffers(

let buffer = device.new_buffer_with_data(
unsafe { std::mem::transmute(data.as_ptr()) },
(data.len() * std::mem::size_of::<u32>()) as u64,
(data.len() * size_of::<u32>()) as u64,
MTLResourceOptions::CPUCacheModeDefaultCache,
);

let sum = {
let data = [0u32];
device.new_buffer_with_data(
unsafe { std::mem::transmute(data.as_ptr()) },
(data.len() * std::mem::size_of::<u32>()) as u64,
(data.len() * size_of::<u32>()) as u64,
MTLResourceOptions::CPUCacheModeDefaultCache,
)
};
Expand Down
3 changes: 1 addition & 2 deletions examples/headless-render/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use std::mem;
use std::path::PathBuf;

use std::fs::File;
Expand Down Expand Up @@ -144,7 +143,7 @@ fn prepare_pipeline_state(device: &DeviceRef, library: &LibraryRef) -> RenderPip
fn create_vertex_buffer(device: &DeviceRef) -> Buffer {
device.new_buffer_with_data(
VERTEX_ATTRIBS.as_ptr() as *const _,
(VERTEX_ATTRIBS.len() * mem::size_of::<f32>()) as u64,
(VERTEX_ATTRIBS.len() * size_of::<f32>()) as u64,
MTLResourceOptions::CPUCacheModeDefaultCache | MTLResourceOptions::StorageModeManaged,
)
}
Expand Down
13 changes: 6 additions & 7 deletions examples/mps/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use metal::*;
use std::ffi::c_void;
use std::mem;

#[repr(C)]
struct Vertex {
Expand Down Expand Up @@ -39,7 +38,7 @@ fn main() {
},
];

let vertex_stride = mem::size_of::<Vertex>();
let vertex_stride = size_of::<Vertex>();

let indices: [u32; 3] = [0, 1, 2];

Expand All @@ -56,7 +55,7 @@ fn main() {

let index_buffer = device.new_buffer_with_data(
indices.as_ptr() as *const c_void,
(mem::size_of::<u32>() * indices.len()) as u64,
(size_of::<u32>() * indices.len()) as u64,
buffer_opts,
);

Expand All @@ -75,22 +74,22 @@ fn main() {
let ray_intersector =
mps::RayIntersector::from_device(&device).expect("Failed to create ray intersector");

ray_intersector.set_ray_stride(mem::size_of::<Ray>() as u64);
ray_intersector.set_ray_stride(size_of::<Ray>() as u64);
ray_intersector.set_ray_data_type(mps::MPSRayDataType::OriginMinDistanceDirectionMaxDistance);
ray_intersector.set_intersection_stride(mem::size_of::<Intersection>() as u64);
ray_intersector.set_intersection_stride(size_of::<Intersection>() as u64);
ray_intersector.set_intersection_data_type(
mps::MPSIntersectionDataType::DistancePrimitiveIndexCoordinates,
);

// Create a buffer to hold generated rays and intersection results
let ray_count = 1024;
let ray_buffer = device.new_buffer(
(mem::size_of::<Ray>() * ray_count) as u64,
(size_of::<Ray>() * ray_count) as u64,
MTLResourceOptions::StorageModePrivate,
);

let intersection_buffer = device.new_buffer(
(mem::size_of::<Intersection>() * ray_count) as u64,
(size_of::<Intersection>() * ray_count) as u64,
MTLResourceOptions::StorageModePrivate,
);

Expand Down
5 changes: 1 addition & 4 deletions examples/raytracing/geometry.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use std::{
mem::{size_of, transmute},
sync::Arc,
};
use std::{mem::transmute, sync::Arc};

use glam::{
f32::{Mat4, Vec3, Vec4},
Expand Down
16 changes: 4 additions & 12 deletions examples/raytracing/renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use core_graphics_types::{base::CGFloat, geometry::CGSize};
use std::{
collections::BTreeMap,
ffi::c_void,
mem::{size_of, transmute},
mem::transmute,
ops::Index,
sync::{Arc, Condvar, Mutex},
};
Expand Down Expand Up @@ -475,21 +475,13 @@ impl Renderer {
let constants = FunctionConstantValues::new();
let resources_stride = resources_stride * size_of::<u64>() as u32;
constants.set_constant_value_at_index(
&resources_stride as *const u32 as *const c_void,
&raw const resources_stride as *const c_void,
MTLDataType::UInt,
0,
);
let v = true;
constants.set_constant_value_at_index(
&v as *const bool as *const c_void,
MTLDataType::Bool,
1,
);
constants.set_constant_value_at_index(
&v as *const bool as *const c_void,
MTLDataType::Bool,
2,
);
constants.set_constant_value_at_index(&raw const v as *const c_void, MTLDataType::Bool, 1);
constants.set_constant_value_at_index(&raw const v as *const c_void, MTLDataType::Bool, 2);
library.get_function(name, Some(constants)).unwrap()
}

Expand Down
2 changes: 1 addition & 1 deletion examples/raytracing/scene.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{ffi::c_void, mem::size_of, sync::Arc};
use std::{ffi::c_void, sync::Arc};

use glam::{Mat4, Vec3, Vec4};
use rand::{thread_rng, Rng};
Expand Down
4 changes: 2 additions & 2 deletions examples/texture/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ fn main() {
let vertex_data = vertices();
let vertex_buffer = device.new_buffer_with_data(
vertex_data.as_ptr() as *const _,
(vertex_data.len() * std::mem::size_of::<TexturedVertex>()) as u64,
(vertex_data.len() * size_of::<TexturedVertex>()) as u64,
MTLResourceOptions::CPUCacheModeDefaultCache | MTLResourceOptions::StorageModeManaged,
);

Expand Down Expand Up @@ -225,7 +225,7 @@ fn prepare_pipeline_state(device: &Device, library: &Library) -> RenderPipelineS
fn update_viewport_size_buffer(viewport_size_buffer: &Buffer, size: (u32, u32)) {
let contents = viewport_size_buffer.contents();
let viewport_size: [u32; 2] = [size.0, size.1];
let byte_count = (viewport_size.len() * std::mem::size_of::<u32>()) as usize;
let byte_count = (viewport_size.len() * size_of::<u32>()) as usize;

unsafe {
std::ptr::copy(viewport_size.as_ptr(), contents as *mut u32, byte_count);
Expand Down
8 changes: 4 additions & 4 deletions examples/window/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ fn main() {

device.new_buffer_with_data(
vertex_data.as_ptr() as *const _,
(vertex_data.len() * mem::size_of::<f32>()) as u64,
(vertex_data.len() * size_of::<f32>()) as u64,
MTLResourceOptions::CPUCacheModeDefaultCache | MTLResourceOptions::StorageModeManaged,
)
};
Expand All @@ -159,7 +159,7 @@ fn main() {

let clear_rect_buffer = device.new_buffer_with_data(
clear_rect.as_ptr() as *const _,
mem::size_of::<ClearRect>() as u64,
size_of::<ClearRect>() as u64,
MTLResourceOptions::CPUCacheModeDefaultCache | MTLResourceOptions::StorageModeManaged,
);

Expand Down Expand Up @@ -202,13 +202,13 @@ fn main() {
std::ptr::copy(
vertex_data.as_ptr(),
p as *mut f32,
(vertex_data.len() * mem::size_of::<f32>()) as usize,
(vertex_data.len() * size_of::<f32>()) as usize,
);
}

vbuf.did_modify_range(crate::NSRange::new(
0 as u64,
(vertex_data.len() * mem::size_of::<f32>()) as u64,
(vertex_data.len() * size_of::<f32>()) as u64,
));

let drawable = match layer.next_drawable() {
Expand Down
3 changes: 1 addition & 2 deletions src/counters.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::{MTLStorageMode, NSUInteger};
use std::mem;

/// See <https://developer.apple.com/documentation/metal/mtlcountersamplebufferdescriptor>
pub enum MTLCounterSampleBufferDescriptor {}
Expand Down Expand Up @@ -71,7 +70,7 @@ impl CounterSampleBufferRef {

pub fn resolve_counter_range(&self, range: crate::NSRange) -> Vec<NSUInteger> {
let mut data = vec![0 as NSUInteger; range.length as usize];
let total_bytes = range.length * mem::size_of::<NSUInteger>() as u64;
let total_bytes = range.length * size_of::<NSUInteger>() as u64;
unsafe {
let ns_data: *mut crate::Object = msg_send![self, resolveCounterRange: range];
let () = msg_send![ns_data, getBytes: data.as_mut_ptr() length: total_bytes];
Expand Down
9 changes: 2 additions & 7 deletions src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,7 @@ use block::Block;
use log::warn;
use objc::runtime::{NO, YES};

use std::{
ffi::CStr,
os::raw::c_char,
path::Path,
ptr::{self, addr_of_mut},
};
use std::{ffi::CStr, os::raw::c_char, path::Path, ptr};

/// Available on macOS 10.11+, iOS 8.0+, tvOS 9.0+
///
Expand Down Expand Up @@ -1730,7 +1725,7 @@ impl DeviceRef {
let data = dispatch_data_create(
library_data.as_ptr() as *const std::ffi::c_void,
library_data.len() as crate::c_size_t,
addr_of_mut!(_dispatch_main_q),
&raw mut _dispatch_main_q,
DISPATCH_DATA_DESTRUCTOR_DEFAULT,
);

Expand Down
9 changes: 5 additions & 4 deletions src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
// http://opensource.org/licenses/MIT>, at your option. This file may not be
// copied, modified, or distributed except according to those terms.

use std::ffi::CStr;

use super::*;
use block::{Block, RcBlock};
use std::ptr;

#[cfg(feature = "dispatch")]
use dispatch;
Expand Down Expand Up @@ -63,14 +64,14 @@ impl SharedEventRef {
*mut BlockBase<(&SharedEventRef, u64), ()>,
>(block);
(*block).flags |= BLOCK_HAS_SIGNATURE | BLOCK_HAS_COPY_DISPOSE;
(*block).extra = ptr::addr_of!(BLOCK_EXTRA);
(*block).extra = &raw const BLOCK_EXTRA;
let () = msg_send![self, notifyListener:listener atValue:value block:block];
}

extern "C" fn dtor(_: *mut BlockBase<(&SharedEventRef, u64), ()>) {}

const SIGNATURE: &[u8] = b"v16@?0Q8\0";
const SIGNATURE_PTR: *const i8 = &SIGNATURE[0] as *const u8 as *const i8;
const SIGNATURE: &CStr = c"v16@?0Q8";
const SIGNATURE_PTR: *const i8 = SIGNATURE.as_ptr().cast();
static mut BLOCK_EXTRA: BlockExtra<(&SharedEventRef, u64), ()> = BlockExtra {
unknown0: 0 as *mut i32,
unknown1: 0 as *mut i32,
Expand Down