Skip to content

Commit 7b89b36

Browse files
authored
Merge pull request #19 from aosoft/aosoft/fix-repo
Repo fixes: macOS build, Apple/Metal support, edition 2024, CI
2 parents 3710d5f + a6e194a commit 7b89b36

20 files changed

Lines changed: 196 additions & 89 deletions

File tree

.github/workflows/ci.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: CI
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches: [master]
7+
8+
env:
9+
CARGO_TERM_COLOR: always
10+
RUSTFLAGS: -D warnings
11+
12+
jobs:
13+
test:
14+
name: ${{ matrix.os }}
15+
runs-on: ${{ matrix.os }}
16+
strategy:
17+
fail-fast: false
18+
matrix:
19+
os: [ubuntu-latest, windows-latest, macos-latest]
20+
21+
steps:
22+
- uses: actions/checkout@v4
23+
24+
- name: Install Rust toolchain
25+
uses: dtolnay/rust-toolchain@stable
26+
with:
27+
components: clippy
28+
29+
- uses: Swatinem/rust-cache@v2
30+
31+
- name: Clippy
32+
run: cargo clippy --workspace --all-targets
33+
34+
- name: Build
35+
run: cargo build --workspace --all-targets
36+
37+
- name: Test
38+
run: cargo test --workspace

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ members = [
66
"unity-native-plugin-sample",
77
"unity-native-plugin-sample-profiler",
88
]
9-
resolver = "2"
9+
resolver = "3"
1010

README.md

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ Unity Native Plugin API for Rust
55

66
## Notice
77

8-
* WIP
9-
* Currently supports D3D11, D3D12, Vulkan
8+
* Currently supports D3D11, D3D12, Vulkan, Metal
109
* API is not stable.
1110

1211
## How to use
@@ -19,16 +18,13 @@ unity-native-plugin = { version = "*", features = ["d3d11"] }
1918
# * Support features
2019
# * d3d11 - IUnityGraphicsD3D11
2120
# * d3d12 - IUnityGraphicsD3D12
21+
# * vulkan - IUnityGraphicsVulkan
22+
# * metal - IUnityGraphicsMetal
2223
# * profiler - IUnityProfiler
2324
# * profiler_callbacks - IUnityProfilerCallbacks
2425
```
2526

26-
* If you use Vulkan, define "unity-native-plugin-vulkan" in your dependencies.
27-
```cargo
28-
[dependencies]
29-
unity-native-plugin = "*"
30-
unity-native-plugin-vulkan = "*"
31-
```
27+
* Vulkan support has been integrated into `unity-native-plugin`. No separate crate needs to be added to your dependencies.
3228

3329
* Use a macro in lib.rs to define your entry points. Without this definition, UnityInterfaces cannot be used.
3430
```rust

unity-native-plugin-sample-profiler/src/lib.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,17 @@ fn plugin_load(interfaces: &unity_native_plugin::interface::UnityInterfaces) {
7575
}
7676
};
7777
let pid = 1;
78-
let tid: NonZeroU64 = unsafe { std::mem::transmute(std::thread::current().id()) };
78+
let tid: NonZeroU64 = unsafe {
79+
std::mem::transmute::<std::thread::ThreadId, NonZeroU64>(
80+
std::thread::current().id(),
81+
)
82+
};
7983
let ts = Instant::now();
8084
let dt = ts - start_ts;
8185
let cat = desc.desc.category_id();
8286
let cat: BuiltinProfilerCategory =
8387
if cat <= BuiltinProfilerCategory::VirtualTexturing as u16 {
84-
unsafe { std::mem::transmute(cat) }
88+
unsafe { std::mem::transmute::<u16, BuiltinProfilerCategory>(cat) }
8589
} else {
8690
BuiltinProfilerCategory::Other
8791
};

unity-native-plugin-sample/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ pub extern "system" fn GetFillTextureCallback() -> extern "system" fn(c_int, *mu
106106

107107
#[cfg(windows)]
108108
#[test]
109+
#[ignore = "Requires Desktop"]
109110
fn test() {
110111
let instant = std::time::Instant::now();
111112
unity_native_plugin_tester::d3d11::test_plugin_d3d11(

unity-native-plugin-sample/src/vulkan.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,29 @@ pub fn fill_texture(unity_texture: *mut c_void, x: f32, y: f32, z: f32, w: f32)
5252

5353
let pfn = unwrap_pfn(vk_instance.get_instance_proc_addr(c"vkGetDeviceProcAddr".as_ptr()));
5454
let vk_get_device_proc_addr: vk::PFN_vkGetDeviceProcAddr = match pfn {
55-
Some(f) => std::mem::transmute(f),
55+
Some(f) => std::mem::transmute::<
56+
unsafe extern "system" fn(),
57+
unsafe extern "system" fn(
58+
vk::Device,
59+
*const std::os::raw::c_char,
60+
) -> Option<unsafe extern "system" fn()>,
61+
>(f),
5662
None => return,
5763
};
5864

5965
let pfn = vk_get_device_proc_addr(vk_instance.device(), c"vkCmdClearColorImage".as_ptr());
6066
let vk_cmd_clear_color_image: vk::PFN_vkCmdClearColorImage = match pfn {
61-
Some(f) => std::mem::transmute(f),
67+
Some(f) => std::mem::transmute::<
68+
unsafe extern "system" fn(),
69+
unsafe extern "system" fn(
70+
vk::CommandBuffer,
71+
vk::Image,
72+
vk::ImageLayout,
73+
*const vk::ClearColorValue,
74+
u32,
75+
*const vk::ImageSubresourceRange,
76+
),
77+
>(f),
6278
None => return,
6379
};
6480

unity-native-plugin-sys/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
#![allow(non_upper_case_globals)]
22
#![allow(non_camel_case_types)]
33
#![allow(non_snake_case)]
4+
#![allow(clippy::all)]
5+
#![allow(clippy::pedantic)]
6+
#![allow(unnecessary_transmutes)]
7+
#![allow(unsafe_op_in_unsafe_fn)]
48
include!("plugin_api.rs");
59

610
include!("metal.rs");

unity-native-plugin-tester/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ d3d12 = []
2727
[dependencies]
2828
unity-native-plugin-sys = { version = "0.9.0", path = "../unity-native-plugin-sys" }
2929
unity-native-plugin = { version = "0.9.0", path = "../unity-native-plugin", features = ["d3d11", "d3d12"] }
30+
31+
[target.'cfg(windows)'.dependencies]
3032
winapi = { version = "0.3.9", features = ["winuser", "dxgi", "d3d11", "dxgiformat", "dxgitype", "d3dcommon"] }
3133
winit = "0.23.0"
3234
wio = "0.2.2"

unity-native-plugin-tester/src/graphics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ impl crate::interface::UnityInterfaceBase for TesterContextGraphics {
3030
}
3131

3232
fn get_unity_interface(&self) -> *mut IUnityInterface {
33-
unsafe { std::mem::transmute::<_, _>(&self.interfaces) }
33+
&self.interfaces as *const IUnityGraphics as *mut IUnityInterface
3434
}
3535
}
3636

unity-native-plugin-tester/src/interface.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ impl Debug for TesterContextInterfaces {
3636
unsafe impl Send for TesterContextInterfaces {}
3737
unsafe impl Sync for TesterContextInterfaces {}
3838

39+
impl Default for TesterContextInterfaces {
40+
fn default() -> Self {
41+
Self::new()
42+
}
43+
}
44+
3945
impl TesterContextInterfaces {
4046
pub fn new() -> Self {
4147
TesterContextInterfaces {
@@ -50,7 +56,7 @@ impl TesterContextInterfaces {
5056
}
5157

5258
pub fn interfaces(&self) -> *mut IUnityInterfaces {
53-
unsafe { std::mem::transmute::<_, _>(&self.interfaces) }
59+
&self.interfaces as *const IUnityInterfaces as *mut IUnityInterfaces
5460
}
5561

5662
pub fn get_interface(&self, guid: UnityInterfaceGUID) -> Option<Rc<dyn UnityInterfaceBase>> {
@@ -133,7 +139,7 @@ pub unsafe fn get_unity_interface<T: UnityInterfaceBase + UnityInterfaceID + 'st
133139

134140
// Downcast the inner value of Rc and create a new Rc
135141
let any_ref = interface_rc.as_any();
136-
if let Some(_) = any_ref.downcast_ref::<T>() {
142+
if any_ref.downcast_ref::<T>().is_some() {
137143
// Use Rc::clone to safely create an Rc<T>
138144
// First, get a raw pointer from the original Rc
139145
let ptr = Rc::as_ptr(&interface_rc);

0 commit comments

Comments
 (0)