-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Allow named debuginfo options in Cargo.toml #11958
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
d861dcf
3dbb474
8a9db7a
a982bcc
dbab134
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
use std::collections::{BTreeMap, BTreeSet, HashMap}; | ||
use std::fmt; | ||
use std::fmt::{self, Display, Write}; | ||
use std::marker::PhantomData; | ||
use std::path::{Path, PathBuf}; | ||
use std::rc::Rc; | ||
|
@@ -12,8 +12,8 @@ use itertools::Itertools; | |
use lazycell::LazyCell; | ||
use log::{debug, trace}; | ||
use semver::{self, VersionReq}; | ||
use serde::de; | ||
use serde::de::IntoDeserializer as _; | ||
use serde::de::{self, Unexpected}; | ||
use serde::ser; | ||
use serde::{Deserialize, Serialize}; | ||
use url::Url; | ||
|
@@ -442,11 +442,99 @@ impl ser::Serialize for TomlOptLevel { | |
} | ||
} | ||
|
||
#[derive(Clone, Debug, Deserialize, Serialize, Eq, PartialEq)] | ||
#[serde(untagged, expecting = "expected a boolean or an integer")] | ||
pub enum U32OrBool { | ||
U32(u32), | ||
Bool(bool), | ||
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, PartialOrd, Ord)] | ||
pub enum TomlDebugInfo { | ||
None, | ||
LineDirectivesOnly, | ||
LineTablesOnly, | ||
Limited, | ||
Full, | ||
} | ||
|
||
impl ser::Serialize for TomlDebugInfo { | ||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> | ||
where | ||
S: ser::Serializer, | ||
{ | ||
match self { | ||
Self::None => 0.serialize(serializer), | ||
Self::LineDirectivesOnly => "line-directives-only".serialize(serializer), | ||
Self::LineTablesOnly => "line-tables-only".serialize(serializer), | ||
Self::Limited => 1.serialize(serializer), | ||
Self::Full => 2.serialize(serializer), | ||
} | ||
} | ||
} | ||
|
||
impl<'de> de::Deserialize<'de> for TomlDebugInfo { | ||
fn deserialize<D>(d: D) -> Result<TomlDebugInfo, D::Error> | ||
where | ||
D: de::Deserializer<'de>, | ||
{ | ||
struct Visitor; | ||
|
||
impl<'de> de::Visitor<'de> for Visitor { | ||
type Value = TomlDebugInfo; | ||
|
||
fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
formatter | ||
.write_str("a boolean, 0-2, \"line-tables-only\", or \"line-directives-only\"") | ||
jyn514 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
} | ||
|
||
fn visit_i64<E>(self, value: i64) -> Result<TomlDebugInfo, E> | ||
where | ||
E: de::Error, | ||
{ | ||
let debuginfo = match value { | ||
0 => TomlDebugInfo::None, | ||
1 => TomlDebugInfo::Limited, | ||
2 => TomlDebugInfo::Full, | ||
_ => return Err(de::Error::invalid_value(Unexpected::Signed(value), &self)), | ||
}; | ||
Ok(debuginfo) | ||
} | ||
|
||
fn visit_bool<E>(self, v: bool) -> Result<Self::Value, E> | ||
where | ||
E: de::Error, | ||
{ | ||
Ok(if v { | ||
TomlDebugInfo::Full | ||
} else { | ||
TomlDebugInfo::None | ||
}) | ||
} | ||
|
||
fn visit_str<E>(self, value: &str) -> Result<TomlDebugInfo, E> | ||
where | ||
E: de::Error, | ||
{ | ||
let debuginfo = match value { | ||
"none" => TomlDebugInfo::None, | ||
"limited" => TomlDebugInfo::Limited, | ||
"full" => TomlDebugInfo::Full, | ||
Comment on lines
+514
to
+516
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems like this PR is about adding There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I updated the PR description. The main reason is that I want to change There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I opened an MCP for that change: https://rust-lang.zulipchat.com/#narrow/stream/233931-t-compiler.2Fmajor-changes/topic/2024.3A.20Decrease.20debuginfo.20generated.20by.20.20.60-.E2.80.A6.20compiler-team.23613. I think allowing these aliases won't be too much of a maintenance burden for cargo even if it ends up not happening, though. |
||
"line-directives-only" => TomlDebugInfo::LineDirectivesOnly, | ||
"line-tables-only" => TomlDebugInfo::LineTablesOnly, | ||
_ => return Err(de::Error::invalid_value(Unexpected::Str(value), &self)), | ||
}; | ||
Ok(debuginfo) | ||
} | ||
} | ||
|
||
d.deserialize_any(Visitor) | ||
} | ||
} | ||
|
||
impl Display for TomlDebugInfo { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
match self { | ||
TomlDebugInfo::None => f.write_char('0'), | ||
TomlDebugInfo::Limited => f.write_char('1'), | ||
TomlDebugInfo::Full => f.write_char('2'), | ||
TomlDebugInfo::LineDirectivesOnly => f.write_str("line-directives-only"), | ||
TomlDebugInfo::LineTablesOnly => f.write_str("line-tables-only"), | ||
} | ||
} | ||
} | ||
|
||
#[derive(Deserialize, Serialize, Clone, Debug, Default, Eq, PartialEq)] | ||
|
@@ -456,7 +544,7 @@ pub struct TomlProfile { | |
pub lto: Option<StringOrBool>, | ||
pub codegen_backend: Option<InternedString>, | ||
pub codegen_units: Option<u32>, | ||
pub debug: Option<U32OrBool>, | ||
pub debug: Option<TomlDebugInfo>, | ||
pub split_debuginfo: Option<String>, | ||
pub debug_assertions: Option<bool>, | ||
pub rpath: Option<bool>, | ||
|
Uh oh!
There was an error while loading. Please reload this page.