Skip to content
Open
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
8 changes: 5 additions & 3 deletions compiler/rustc_metadata/src/native_libs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ impl<'tcx> Collector<'tcx> {
let dll_imports = match attr.kind {
NativeLibKind::RawDylib { .. } => foreign_items
.iter()
.map(|&child_item| {
.filter_map(|&child_item| {
self.build_dll_import(
abi,
attr.import_name_type.map(|(import_name_type, _)| import_name_type),
Expand Down Expand Up @@ -388,7 +388,7 @@ impl<'tcx> Collector<'tcx> {
abi: ExternAbi,
import_name_type: Option<PeImportNameType>,
item: DefId,
) -> DllImport {
) -> Option<DllImport> {
let span = self.tcx.def_span(item);

// This `extern` block should have been checked for general ABI support before, but let's
Expand Down Expand Up @@ -465,6 +465,8 @@ impl<'tcx> Collector<'tcx> {
} else {
DllImportSymbolType::Static
}
} else if def_kind == DefKind::ForeignTy {
return None;
} else {
bug!("Unexpected type for raw-dylib: {}", def_kind.descr(item));
};
Expand All @@ -482,6 +484,6 @@ impl<'tcx> Collector<'tcx> {
}
};

DllImport { name, import_name_type, calling_convention, span, symbol_type, size }
Some(DllImport { name, import_name_type, calling_convention, span, symbol_type, size })
}
}
21 changes: 21 additions & 0 deletions tests/run-make/raw-dylib-elf-extern-types/bin.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#![feature(extern_types)]
#![feature(raw_dylib_elf)]

use std::ffi::c_char;

#[link(name = "extern", kind = "raw-dylib")]
unsafe extern "C" {
type FOO;
fn create_foo() -> *const FOO;
fn get_foo(foo: *const FOO) -> c_char;
fn set_foo(foo: *const FOO, value: c_char);
}

pub fn main() {
let value = unsafe {
let foo = create_foo();
set_foo(foo, 42);
get_foo(foo)
};
println!("{}", value);
}
16 changes: 16 additions & 0 deletions tests/run-make/raw-dylib-elf-extern-types/extern.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
typedef struct FOO {
char val;
} FOO;

FOO* create_foo() {
static FOO foo;
return &foo;
}

void set_foo(FOO* foo, char val) {
foo->val = val;
}

char get_foo(FOO* foo) {
return foo->val;
}
1 change: 1 addition & 0 deletions tests/run-make/raw-dylib-elf-extern-types/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
42
18 changes: 18 additions & 0 deletions tests/run-make/raw-dylib-elf-extern-types/rmake.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//@ only-elf
//@ ignore-cross-compile: Runs a binary.
//@ needs-dynamic-linking
// FIXME(raw_dylib_elf): Debug the failures on other targets.
//@ only-gnu
//@ only-x86_64
Comment on lines +1 to +6
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a copy from other raw-dylib-elf tests.
I don't know if we can make it run on both Windows and ELF && gnu && x86_64 at the same time.


//@ ignore-rustc-debug-assertions

use run_make_support::{build_native_dynamic_lib, diff, run, rustc};

fn main() {
rustc().crate_type("bin").crate_name("raw_dylib_test").input("bin.rs").run();
build_native_dynamic_lib("extern");

let out_raw = run("raw_dylib_test").stdout_utf8();
diff().expected_file("output.txt").actual_text("actual", out_raw).normalize(r#"\r"#, "").run();
}
Loading