Skip to content

Commit

Permalink
Use ash' built-in "linked" feature for static linking
Browse files Browse the repository at this point in the history
All the code here to define an `extern "system"` symbol for
`vkGetInstanceProcAddr` and use it inside `Entry` (via `StaticFn`) was
included in Ash release `0.35` (the minimum compatbile with `ash-molten`
already) to make it much more trivial to static-link on various
platforms, including against `MoltenVK` here.

This change makes the `lib.rs` portion of `MoltenVK` pretty much
useless as it's only forwarding the call (and `load()` should perhaps
be renamed?), should we rethink the structure of the crate a bit.
  • Loading branch information
MarijnS95 committed Apr 3, 2024
1 parent 1079a48 commit b289107
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 16 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ build = "build/build.rs"
# in this range, not just the start and the end, to be sure it's compatible.
version = ">=0.35, <=0.37"
default-features = false
features = ["linked"]

[build-dependencies]
anyhow = "1.0"
Expand Down
18 changes: 2 additions & 16 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,5 @@
use ash::{vk, Entry};
use ash::Entry;

extern "system" {
fn vkGetInstanceProcAddr(
instance: vk::Instance,
p_name: *const std::os::raw::c_char,
) -> vk::PFN_vkVoidFunction;
}

/// Fetches the function pointer to `vkGetInstanceProcAddr` which is statically linked.
pub fn load() -> Entry {
let static_fn = vk::StaticFn {
get_instance_proc_addr: vkGetInstanceProcAddr,
};
#[allow(unsafe_code)]
unsafe {
Entry::from_static_fn(static_fn)
}
Entry::linked()
}

0 comments on commit b289107

Please sign in to comment.