Skip to content

Commit

Permalink
Rollup merge of rust-lang#98778 - dpaoliello:rawdylibbin, r=michaelwo…
Browse files Browse the repository at this point in the history
…erister

Enable raw-dylib for bin crates

Fixes rust-lang#93842

When a `raw-dylib` is used in a `bin` crate, we need to link to the library name specified.
  • Loading branch information
Dylan-DPC authored Jul 4, 2022
2 parents 9ed515f + b8213bb commit 829a718
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
8 changes: 3 additions & 5 deletions compiler/rustc_codegen_ssa/src/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2212,7 +2212,9 @@ fn add_local_native_libraries(
NativeLibKind::Dylib { as_needed } => {
cmd.link_dylib(name, verbatim, as_needed.unwrap_or(true))
}
NativeLibKind::Unspecified => cmd.link_dylib(name, verbatim, true),
NativeLibKind::RawDylib | NativeLibKind::Unspecified => {
cmd.link_dylib(name, verbatim, true)
}
NativeLibKind::Framework { as_needed } => {
cmd.link_framework(name, as_needed.unwrap_or(true))
}
Expand All @@ -2233,10 +2235,6 @@ fn add_local_native_libraries(
cmd.link_staticlib(name, verbatim)
}
}
NativeLibKind::RawDylib => {
// FIXME(#58713): Proper handling for raw dylibs.
bug!("raw_dylib feature not yet implemented");
}
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/test/run-make/raw-dylib-c/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@ else
endif
$(RUSTC) --crate-type lib --crate-name raw_dylib_test lib.rs
$(RUSTC) --crate-type bin driver.rs -L "$(TMPDIR)"
$(RUSTC) --crate-type bin --crate-name raw_dylib_test_bin lib.rs
"$(TMPDIR)"/driver > "$(TMPDIR)"/output.txt
"$(TMPDIR)"/raw_dylib_test_bin > "$(TMPDIR)"/output_bin.txt

ifdef RUSTC_BLESS_TEST
cp "$(TMPDIR)"/output.txt output.txt
else
$(DIFF) output.txt "$(TMPDIR)"/output.txt
$(DIFF) output.txt "$(TMPDIR)"/output_bin.txt
endif
4 changes: 4 additions & 0 deletions src/test/run-make/raw-dylib-c/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@ pub fn library_function() {
extern_fn_3();
}
}

fn main() {
library_function();
}

0 comments on commit 829a718

Please sign in to comment.