Skip to content

Commit

Permalink
Use a HashMap for profile metadata to allow custom profiles
Browse files Browse the repository at this point in the history
  • Loading branch information
nikarh committed Apr 5, 2024
1 parent bd63ed7 commit ec09015
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 20 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ vita_make_fself_flags = ["-s"]
# Optional, this is the default
vita_mksfoex_flags = ["-d", "ATTRIBUTE2=12"]

[package.metadata.vita.dev]
[package.metadata.vita.profile.dev]
# Strips symbols from the vita elf in dev profile. Optional, default is false
strip_symbols = true
[package.metadata.vita.release]
[package.metadata.vita.profile.release]
# Strips symbols from the vita elf in release profile. Optional, default is true
strip_symbols = true
```
Expand Down Expand Up @@ -184,13 +184,13 @@ since symbol stripping also strips relocation information.

To counter this issue, `cargo-vita` can do an additional strip step of the `elf` with `--strip-unneeded` flag, which reduces the binary size without interfering with other steps necessary to produce a runnable binary.

This step is enabled for release builds and disabled for dev builds by default, but can be configured per-crate via the following section in `Cargo.toml`:
This step is enabled for release profile builds and disabled for other profile builds by default, but can be configured per-crate via the following section in `Cargo.toml`:

```toml
[package.metadata.vita.dev]
[package.metadata.vita.profile.dev]
# Strips symbols from the vita elf in dev profile, default is false
strip_symbols = true
[package.metadata.vita.release]
[package.metadata.vita.profile.release]
# Strips symbols from the vita elf in release profile, default is true
strip_symbols = true
```
Expand Down
5 changes: 3 additions & 2 deletions src/commands/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,9 +319,10 @@ impl<'a> BuildContext<'a> {
.components()
.skip_while(|s| s.as_str() != "armv7-sony-vita-newlibeabihf")
.nth(1);
let is_release = profile.map(|p| p.as_str()) == Some("release");

if !art.meta.strip_symbols(is_release) {
let profile = profile.map_or("dev", |p| p.as_str());

if !art.meta.strip_symbols(profile) {
info!("{}", "Skipping additional elf strip".yellow());
return Ok(());
}
Expand Down
2 changes: 1 addition & 1 deletion src/commands/build/unit_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::process::{Command, Stdio};
use anyhow::Context;

pub struct BuildHints {
// Can be "debug" or "release"
// Can be "dev" or "release", or any custom profile
pub profile: String,

// Can be "None", "debuginfo", "symbols", "true" or any invalid value
Expand Down
22 changes: 10 additions & 12 deletions src/meta.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{fmt::Display, ops::Deref, str::FromStr};
use std::{collections::HashMap, fmt::Display, ops::Deref, str::FromStr};

use anyhow::Context;
use cargo_metadata::{camino::Utf8PathBuf, Artifact, MetadataCommand, Package};
Expand Down Expand Up @@ -83,18 +83,17 @@ pub struct PackageMetadata {
pub vita_mksfoex_flags: Vec<String>,

#[serde(default)]
pub dev: ProfileMetadata,
#[serde(default)]
pub release: ProfileMetadata,
pub profile: HashMap<String, ProfileMetadata>,
}

impl PackageMetadata {
pub fn strip_symbols(&self, release: bool) -> bool {
if release {
self.release.strip_symbols.unwrap_or(true)
} else {
self.dev.strip_symbols.unwrap_or(false)
}
pub fn strip_symbols(&self, profile: &str) -> bool {
let default = profile == "release";

self.profile
.get("release")
.and_then(|p| p.strip_symbols)
.unwrap_or(default)
}
}

Expand All @@ -112,8 +111,7 @@ impl Default for PackageMetadata {
build_std: default_build_std(),
vita_make_fself_flags: default_vita_make_fself_flags(),
vita_mksfoex_flags: default_vita_mksfoex_flags(),
release: ProfileMetadata::default(),
dev: ProfileMetadata::default(),
profile: HashMap::new(),
}
}
}
Expand Down

0 comments on commit ec09015

Please sign in to comment.