Skip to content

Commit 8ae0abd

Browse files
committed
upgrade to edition 2024
1 parent 6ed4abf commit 8ae0abd

File tree

9 files changed

+36
-30
lines changed

9 files changed

+36
-30
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ description = "Wrapper crate for SPIRV-Tools"
1010
repository = "https://github.com/rust-gpu/spirv-tools-rs"
1111
version = "0.12.2"
1212
authors = ["Embark <[email protected]>"]
13-
edition = "2021"
13+
edition = "2024"
1414
license = "MIT OR Apache-2.0"
1515
readme = "README.md"
1616
documentation = "https://docs.rs/spirv-tools"

spirv-tools-sys/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description = "Wrapper crate for SPIRV-Tools"
44
repository = "https://github.com/rust-gpu/spirv-tools-rs"
55
version = "0.12.2"
66
authors = ["Embark <[email protected]>"]
7-
edition = "2021"
7+
edition = "2024"
88
# This is the same license for the underlying SPIRV-Tools code
99
license = "Apache-2.0"
1010
documentation = "https://docs.rs/spirv-tools-sys"

spirv-tools-sys/src/assembler.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub enum DisassembleOptions {
3131
Comment = 0x80,
3232
}
3333

34-
extern "C" {
34+
unsafe extern "C" {
3535
/// Encodes the given SPIR-V assembly text to its binary representation. The
3636
/// length parameter specifies the number of bytes for text. Encoded binary will
3737
/// be stored into *binary. Any error will be written into *diagnostic if

spirv-tools-sys/src/diagnostics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ pub type MessageCallback = extern "C" fn(
4242
*mut std::ffi::c_void, // context we use for mapping
4343
);
4444

45-
extern "C" {
45+
unsafe extern "C" {
4646
/// Destroys a diagnostic object. This is a no-op if diagnostic is a null
4747
/// pointer.
4848
#[link_name = "spvDiagnosticDestroy"]

spirv-tools-sys/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![allow(unsafe_code)]
2+
13
#[cfg(not(any(feature = "use-installed-tools", feature = "use-compiled-tools")))]
24
compile_error!("Enable at least one of `use-compiled-tools` or `use-installed-tools` features");
35

spirv-tools-sys/src/opt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ pub enum Passes {
491491
WrapOpKill,
492492
}
493493

494-
extern "C" {
494+
unsafe extern "C" {
495495
pub fn optimizer_create(env: crate::shared::TargetEnv) -> *mut Optimizer;
496496
pub fn optimizer_destroy(opt: *mut Optimizer);
497497

spirv-tools-sys/src/shared.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ pub struct ToolContext {
271271
_unused: [u8; 0],
272272
}
273273

274-
extern "C" {
274+
unsafe extern "C" {
275275
/// Creates a context object for most of the SPIRV-Tools API.
276276
/// Returns null if env is invalid.
277277
///

spirv-tools-sys/src/val.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub enum ValidatorLimits {
1919
IdBound,
2020
}
2121

22-
extern "C" {
22+
unsafe extern "C" {
2323
/// Validates a SPIR-V binary for correctness. Any errors will be written into
2424
/// *diagnostic if diagnostic is non-null, otherwise the context's message
2525
/// consumer will be used.

src/error.rs

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -52,23 +52,25 @@ impl Diagnostic {
5252
pub(crate) unsafe fn from_diag(
5353
diag: *mut diagnostics::Diagnostic,
5454
) -> Result<Self, shared::SpirvResult> {
55-
if diag.is_null() {
56-
return Err(shared::SpirvResult::Success);
57-
}
55+
unsafe {
56+
if diag.is_null() {
57+
return Err(shared::SpirvResult::Success);
58+
}
5859

59-
let (message, notes) = Message::message_and_notes_from_cstr((*diag).error);
60+
let (message, notes) = Message::message_and_notes_from_cstr((*diag).error);
6061

61-
let res = Self {
62-
line: (*diag).position.line,
63-
column: (*diag).position.column,
64-
index: (*diag).position.index,
65-
message,
66-
notes,
67-
is_text: (*diag).is_text_source,
68-
};
62+
let res = Self {
63+
line: (*diag).position.line,
64+
column: (*diag).position.column,
65+
index: (*diag).position.index,
66+
message,
67+
notes,
68+
is_text: (*diag).is_text_source,
69+
};
6970

70-
diagnostics::diagnostic_destroy(diag);
71-
Ok(res)
71+
diagnostics::diagnostic_destroy(diag);
72+
Ok(res)
73+
}
7274
}
7375
}
7476

@@ -126,15 +128,17 @@ impl Message {
126128

127129
#[cfg(feature = "use-compiled-tools")]
128130
unsafe fn message_and_notes_from_cstr(msg: *const std::os::raw::c_char) -> (String, String) {
129-
let full_message = std::ffi::CStr::from_ptr(msg).to_string_lossy();
130-
131-
if let Some(ind) = full_message.find('\n') {
132-
(
133-
full_message[..ind].to_owned(),
134-
full_message[ind + 1..].to_owned(),
135-
)
136-
} else {
137-
(full_message.into_owned(), String::new())
131+
unsafe {
132+
let full_message = std::ffi::CStr::from_ptr(msg).to_string_lossy();
133+
134+
if let Some(ind) = full_message.find('\n') {
135+
(
136+
full_message[..ind].to_owned(),
137+
full_message[ind + 1..].to_owned(),
138+
)
139+
} else {
140+
(full_message.into_owned(), String::new())
141+
}
138142
}
139143
}
140144

0 commit comments

Comments
 (0)