ADD - initial port of link.rs
This commit is contained in:
parent
0f97d4a141
commit
12aa84bdf3
4 changed files with 166 additions and 58 deletions
|
@ -1,10 +1,16 @@
|
|||
//! Errors emitted by codegen_ssa
|
||||
|
||||
use rustc_errors::{DiagnosticArgValue, IntoDiagnosticArg};
|
||||
use crate::back::command::Command;
|
||||
use rustc_errors::{
|
||||
fluent, DiagnosticArgValue, DiagnosticBuilder, ErrorGuaranteed, Handler, IntoDiagnostic,
|
||||
IntoDiagnosticArg,
|
||||
};
|
||||
use rustc_macros::Diagnostic;
|
||||
use rustc_span::{Span, Symbol};
|
||||
use std::borrow::Cow;
|
||||
use std::io::Error;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process::ExitStatus;
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(codegen_ssa::lib_def_write_failure)]
|
||||
|
@ -73,17 +79,15 @@ pub struct CopyPath<'a> {
|
|||
|
||||
impl<'a> CopyPath<'a> {
|
||||
pub fn new(from: &'a Path, to: &'a Path, error: Error) -> CopyPath<'a> {
|
||||
CopyPath { from: DebugArgPath { path: from }, to: DebugArgPath { path: to }, error }
|
||||
CopyPath { from: DebugArgPath(from), to: DebugArgPath(to), error }
|
||||
}
|
||||
}
|
||||
|
||||
struct DebugArgPath<'a> {
|
||||
pub path: &'a Path,
|
||||
}
|
||||
struct DebugArgPath<'a>(pub &'a Path);
|
||||
|
||||
impl IntoDiagnosticArg for DebugArgPath<'_> {
|
||||
fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue<'static> {
|
||||
DiagnosticArgValue::Str(Cow::Owned(format!("{:?}", self.path)))
|
||||
DiagnosticArgValue::Str(Cow::Owned(format!("{:?}", self.0)))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -98,3 +102,96 @@ pub struct IgnoringEmitPath {
|
|||
pub struct IgnoringOutput {
|
||||
pub extension: String,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(codegen_ssa::create_temp_dir)]
|
||||
pub struct CreateTempDir {
|
||||
pub error: Error,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(codegen_ssa::incompatible_linking_modifiers)]
|
||||
pub struct IncompatibleLinkingModifiers;
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(codegen_ssa::add_native_library)]
|
||||
pub struct AddNativeLibrary<'a> {
|
||||
pub library_path: &'a str,
|
||||
pub error: Error,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(codegen_ssa::multiple_external_func_decl)]
|
||||
pub struct MultipleExternalFuncDecl<'a> {
|
||||
#[primary_span]
|
||||
pub span: Span,
|
||||
pub function: Symbol,
|
||||
pub library_name: &'a str,
|
||||
}
|
||||
|
||||
pub enum LinkRlibError {
|
||||
MissingFormat,
|
||||
OnlyRmetaFound { crate_name: Symbol },
|
||||
NotFound { crate_name: Symbol },
|
||||
}
|
||||
|
||||
impl IntoDiagnostic<'_, !> for LinkRlibError {
|
||||
fn into_diagnostic(self, handler: &Handler) -> DiagnosticBuilder<'_, !> {
|
||||
match self {
|
||||
LinkRlibError::MissingFormat => {
|
||||
handler.struct_fatal(fluent::codegen_ssa::rlib_missing_format)
|
||||
}
|
||||
LinkRlibError::OnlyRmetaFound { crate_name } => {
|
||||
let mut diag = handler.struct_fatal(fluent::codegen_ssa::rlib_only_rmeta_found);
|
||||
diag.set_arg("crate_name", crate_name);
|
||||
diag
|
||||
}
|
||||
LinkRlibError::NotFound { crate_name } => {
|
||||
let mut diag = handler.struct_fatal(fluent::codegen_ssa::rlib_not_found);
|
||||
diag.set_arg("crate_name", crate_name);
|
||||
diag
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(codegen_ssa::thorin_dwarf_linking)]
|
||||
#[note]
|
||||
pub struct ThorinDwarfLinking {
|
||||
pub thorin_error: ThorinErrorWrapper,
|
||||
}
|
||||
pub struct ThorinErrorWrapper(pub thorin::Error);
|
||||
|
||||
// FIXME: How should we support translations for external crate errors?
|
||||
impl IntoDiagnosticArg for ThorinErrorWrapper {
|
||||
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
|
||||
DiagnosticArgValue::Str(Cow::Owned(format!("{:?}", self.0)))
|
||||
}
|
||||
}
|
||||
|
||||
pub struct LinkingFailed<'a> {
|
||||
pub linker_path: &'a PathBuf,
|
||||
pub exit_status: ExitStatus,
|
||||
pub command: &'a Command,
|
||||
pub escaped_output: &'a str,
|
||||
}
|
||||
|
||||
impl IntoDiagnostic<'_> for LinkingFailed<'_> {
|
||||
fn into_diagnostic(self, handler: &Handler) -> DiagnosticBuilder<'_, ErrorGuaranteed> {
|
||||
let mut diag = handler.struct_err(fluent::codegen_ssa::linking_failed);
|
||||
diag.set_arg("linker_path", format!("{}", self.linker_path.display()));
|
||||
diag.set_arg("exit_status", format!("{}", self.exit_status));
|
||||
|
||||
diag.note(format!("{:?}", self.command)).note(self.escaped_output);
|
||||
|
||||
// Trying to match an error from OS linkers
|
||||
// which by now we have no way to translate.
|
||||
if self.escaped_output.contains("undefined reference to") {
|
||||
diag.note(fluent::codegen_ssa::extern_funcs_not_found)
|
||||
.note(fluent::codegen_ssa::specify_libraries_to_link)
|
||||
.note(fluent::codegen_ssa::use_cargo_directive);
|
||||
}
|
||||
diag
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue