Skip to content

Commit 13d3b75

Browse files
committed
Stabilize -Cdlltool
1 parent df7fd99 commit 13d3b75

File tree

17 files changed

+104
-15
lines changed

17 files changed

+104
-15
lines changed

compiler/rustc_codegen_llvm/messages.ftl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ codegen_llvm_error_writing_def_file =
2424
Error writing .DEF file: {$error}
2525
2626
codegen_llvm_error_calling_dlltool =
27-
Error calling dlltool: {$error}
27+
Error calling dlltool '{$dlltool_path}': {$error}
2828
2929
codegen_llvm_dlltool_fail_import_library =
30-
Dlltool could not create import library: {$stdout}\n{$stderr}
30+
Dlltool could not create import library: {$error}
3131
3232
codegen_llvm_target_feature_disable_or_enable =
3333
the target features {$features} must all be either enabled or disabled together

compiler/rustc_codegen_llvm/src/back/archive.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ impl ArchiveBuilderBuilder for LlvmArchiveBuilderBuilder {
198198
"arm" => ("arm", "--32"),
199199
_ => panic!("unsupported arch {}", sess.target.arch),
200200
};
201-
let result = std::process::Command::new(dlltool)
201+
let result = std::process::Command::new(&dlltool)
202202
.args([
203203
"-d",
204204
def_file_path.to_str().unwrap(),
@@ -218,12 +218,15 @@ impl ArchiveBuilderBuilder for LlvmArchiveBuilderBuilder {
218218

219219
match result {
220220
Err(e) => {
221-
sess.emit_fatal(ErrorCallingDllTool { error: e });
221+
sess.emit_fatal(ErrorCallingDllTool {
222+
dlltool_path: dlltool.to_string_lossy(),
223+
error: e,
224+
});
222225
}
223-
Ok(output) if !output.status.success() => {
226+
// dlltool returns '0' on failure, so check for error output instead.
227+
Ok(output) if !output.stderr.is_empty() => {
224228
sess.emit_fatal(DlltoolFailImportLibrary {
225-
stdout: String::from_utf8_lossy(&output.stdout),
226-
stderr: String::from_utf8_lossy(&output.stderr),
229+
error: String::from_utf8_lossy(&output.stderr),
227230
})
228231
}
229232
_ => {}
@@ -431,7 +434,7 @@ fn string_to_io_error(s: String) -> io::Error {
431434

432435
fn find_binutils_dlltool(sess: &Session) -> OsString {
433436
assert!(sess.target.options.is_like_windows && !sess.target.options.is_like_msvc);
434-
if let Some(dlltool_path) = &sess.opts.unstable_opts.dlltool {
437+
if let Some(dlltool_path) = &sess.opts.cg.dlltool {
435438
return dlltool_path.clone().into_os_string();
436439
}
437440

compiler/rustc_codegen_llvm/src/errors.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,15 @@ pub(crate) struct ErrorWritingDEFFile {
6767

6868
#[derive(Diagnostic)]
6969
#[diag(codegen_llvm_error_calling_dlltool)]
70-
pub(crate) struct ErrorCallingDllTool {
70+
pub(crate) struct ErrorCallingDllTool<'a> {
71+
pub dlltool_path: Cow<'a, str>,
7172
pub error: std::io::Error,
7273
}
7374

7475
#[derive(Diagnostic)]
7576
#[diag(codegen_llvm_dlltool_fail_import_library)]
7677
pub(crate) struct DlltoolFailImportLibrary<'a> {
77-
pub stdout: Cow<'a, str>,
78-
pub stderr: Cow<'a, str>,
78+
pub error: Cow<'a, str>,
7979
}
8080

8181
#[derive(Diagnostic)]

compiler/rustc_interface/src/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,7 @@ fn test_codegen_options_tracking_hash() {
545545
untracked!(ar, String::from("abc"));
546546
untracked!(codegen_units, Some(42));
547547
untracked!(default_linker_libraries, true);
548+
untracked!(dlltool, Some(PathBuf::from("custom_dlltool.exe")));
548549
untracked!(extra_filename, String::from("extra-filename"));
549550
untracked!(incremental, Some(String::from("abc")));
550551
// `link_arg` is omitted because it just forwards to `link_args`.
@@ -649,7 +650,6 @@ fn test_unstable_options_tracking_hash() {
649650
untracked!(assert_incr_state, Some(String::from("loaded")));
650651
untracked!(deduplicate_diagnostics, false);
651652
untracked!(dep_tasks, true);
652-
untracked!(dlltool, Some(PathBuf::from("custom_dlltool.exe")));
653653
untracked!(dont_buffer_diagnostics, true);
654654
untracked!(dump_dep_graph, true);
655655
untracked!(dump_drop_tracking_cfg, Some("cfg.dot".to_string()));

compiler/rustc_session/src/options.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1205,6 +1205,8 @@ options! {
12051205
2 = full debug info with variable and type information; default: 0)"),
12061206
default_linker_libraries: bool = (false, parse_bool, [UNTRACKED],
12071207
"allow the linker to link its default libraries (default: no)"),
1208+
dlltool: Option<PathBuf> = (None, parse_opt_pathbuf, [UNTRACKED],
1209+
"import library generation tool (windows-gnu only)"),
12081210
embed_bitcode: bool = (true, parse_bool, [TRACKED],
12091211
"emit bitcode in rlibs (default: yes)"),
12101212
extra_filename: String = (String::new(), parse_string, [UNTRACKED],
@@ -1361,8 +1363,6 @@ options! {
13611363
(default: no)"),
13621364
diagnostic_width: Option<usize> = (None, parse_opt_number, [UNTRACKED],
13631365
"set the current output width for diagnostic truncation"),
1364-
dlltool: Option<PathBuf> = (None, parse_opt_pathbuf, [UNTRACKED],
1365-
"import library generation tool (windows-gnu only)"),
13661366
dont_buffer_diagnostics: bool = (false, parse_bool, [UNTRACKED],
13671367
"emit diagnostics rather than buffering (breaks NLL error downgrading, sorting) \
13681368
(default: no)"),

src/doc/rustc/src/codegen-options/index.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,14 @@ It takes one of the following values:
8888
For example, for gcc flavor linkers, this issues the `-nodefaultlibs` flag to
8989
the linker.
9090

91+
## dlltool
92+
93+
On `windows-gnu` targets, this flag controls which dlltool `rustc` invokes to
94+
generate import libraries when using the [`raw-dylib` link kind](../../reference/items/external-blocks.md#the-link-attribute).
95+
It takes a path to [the dlltool executable](https://sourceware.org/binutils/docs/binutils/dlltool.html).
96+
If this flag is not specified, a dlltool executable will be inferred based on
97+
the host environment and target.
98+
9199
## embed-bitcode
92100

93101
This flag controls whether or not the compiler embeds LLVM bitcode into object

src/tools/compiletest/src/header.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -976,6 +976,15 @@ pub fn make_test_description<R: Read>(
976976
#[cfg(not(windows))]
977977
let (has_i686_dlltool, has_x86_64_dlltool) =
978978
(is_on_path("i686-w64-mingw32-dlltool"), is_on_path("x86_64-w64-mingw32-dlltool"));
979+
let has_dlltool = || {
980+
if config.matches_arch("x86") {
981+
has_i686_dlltool()
982+
} else if config.matches_arch("x86_64") {
983+
has_x86_64_dlltool()
984+
} else {
985+
false
986+
}
987+
};
979988

980989
iter_header(path, src, &mut |revision, ln| {
981990
if revision.is_some() && revision != cfg {
@@ -1046,6 +1055,7 @@ pub fn make_test_description<R: Read>(
10461055
reason!(!has_rust_lld && config.parse_name_directive(ln, "needs-rust-lld"));
10471056
reason!(config.parse_name_directive(ln, "needs-i686-dlltool") && !has_i686_dlltool());
10481057
reason!(config.parse_name_directive(ln, "needs-x86_64-dlltool") && !has_x86_64_dlltool());
1058+
reason!(config.parse_name_directive(ln, "needs-dlltool") && !has_dlltool());
10491059
should_fail |= config.parse_name_directive(ln, "should-fail");
10501060
});
10511061

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Test using -Cdlltool to change where raw-dylib looks for the dlltool binary.
2+
3+
# only-windows
4+
# only-gnu
5+
# needs-dlltool
6+
7+
include ../../run-make-fulldeps/tools.mk
8+
9+
all:
10+
$(RUSTC) --crate-type lib --crate-name raw_dylib_test lib.rs -Cdlltool=$(CURDIR)/script.cmd
11+
$(DIFF) output.txt "$(TMPDIR)"/output.txt
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#![feature(raw_dylib)]
2+
3+
#[link(name = "extern_1", kind = "raw-dylib")]
4+
extern {
5+
fn extern_fn_1();
6+
}
7+
8+
pub fn library_function() {
9+
unsafe {
10+
extern_fn_1();
11+
}
12+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Called dlltool via script.cmd

0 commit comments

Comments
 (0)