Skip to content

Commit

Permalink
Defer module name lowercase conversion for Windows (#2934)
Browse files Browse the repository at this point in the history
  • Loading branch information
kennykerr authored Mar 18, 2024
1 parent 50ef983 commit 66f0108
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 11 deletions.
7 changes: 5 additions & 2 deletions crates/libs/bindgen/src/rust/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use metadata::HasAttributes;

pub fn writer(writer: &Writer, namespace: &str, def: metadata::MethodDef) -> TokenStream {
// TODO: remove inline functions from metadata
if def.module_name() == "forceinline" {
if def.module_name() == "FORCEINLINE" {
return quote! {};
}

Expand Down Expand Up @@ -197,7 +197,10 @@ fn gen_win_function(writer: &Writer, namespace: &str, def: metadata::MethodDef)
fn gen_link(writer: &Writer, namespace: &str, signature: &metadata::Signature) -> TokenStream {
let name = signature.def.name();
let ident = to_ident(name);
let library = signature.def.module_name();

// Windows libs are always produced with lowercase module names.
let library = if namespace.starts_with("Windows.") { signature.def.module_name().to_lowercase() } else { signature.def.module_name().to_string() };

let abi = method_def_extern_abi(signature.def);

let symbol = if let Some(impl_map) = signature.def.impl_map() { impl_map.import_name() } else { name };
Expand Down
2 changes: 1 addition & 1 deletion crates/libs/bindgen/src/rust/standalone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ pub fn standalone_imp(writer: &Writer) -> String {
}

for (function, namespace) in functions {
sorted.insert(&format!(".{}.{}", function.module_name(), function.name()), functions::writer(writer, namespace, function));
sorted.insert(&format!(".{}.{}", function.module_name().to_lowercase(), function.name()), functions::writer(writer, namespace, function));
}

for constant in constants {
Expand Down
9 changes: 2 additions & 7 deletions crates/libs/metadata/src/tables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,13 +255,8 @@ impl MethodDef {
self.equal_range(1, MemberForwarded::MethodDef(*self).encode()).next()
}

pub fn module_name(&self) -> String {
// TODO: riddle should always lower case the module name to avoid allocating here
let Some(impl_map) = self.impl_map() else {
return String::new();
};

impl_map.scope().name().to_lowercase()
pub fn module_name(&self) -> &'static str {
self.impl_map().map_or("", |map| map.scope().name())
}

pub fn signature(&self, generics: &[Type]) -> MethodDefSig {
Expand Down
3 changes: 2 additions & 1 deletion crates/tools/lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ fn combine_libraries(
continue;
};

let library = method.module_name();
// Windows libs are always produced with lower case module names.
let library = method.module_name().to_lowercase();
let impl_map = method.impl_map().expect("ImplMap not found");
let flags = impl_map.flags();
let name = impl_map.import_name().to_string();
Expand Down

0 comments on commit 66f0108

Please sign in to comment.