Skip to content

Commit

Permalink
Merge pull request #130 from taladar/fix_separate_debug_symbols_in_ca…
Browse files Browse the repository at this point in the history
…rgo_toml_ignored
  • Loading branch information
kornelski authored May 24, 2024
2 parents 8af9fdb + ea50453 commit 2c1628b
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ cargo deb

Upon running `cargo deb` from the base directory of your Rust project, the Debian package will be created in `target/debian/<project_name>_<version>-1_<arch>.deb` (or you can change the location with the `--output` option). This package can be installed with `dpkg -i target/debian/*.deb`.

Debug symbols are stripped from the main binary by default, unless `[profile.release] debug = true` is set in `Cargo.toml`. If `cargo deb --separate-debug-symbols` is run, the debug symbols will be packaged as a separate file installed at `/usr/lib/debug/<path-to-binary>.debug`.
Debug symbols are stripped from the main binary by default, unless `[profile.release] debug = true` is set in `Cargo.toml`. If `cargo deb --separate-debug-symbols` is run, the debug symbols will be packaged as a separate file installed at `/usr/lib/debug/<path-to-binary>.debug`. This can also be configured in the `[package.metadata.deb]` section with the **separate-debug-symbols** key. If it is enabled there the parameter `cargo deb --no-separate-debug-symbols` can be used to suppress inclusion of the debug symbols.

`cargo deb --install` builds and installs the project system-wide.

Expand Down
1 change: 1 addition & 0 deletions src/control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ mod tests {
None,
mock_listener,
"release",
None,
)
.unwrap();

Expand Down
9 changes: 6 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::process;
struct CliOptions {
no_build: bool,
strip_override: Option<bool>,
separate_debug_symbols: bool,
separate_debug_symbols: Option<bool>,
fast: bool,
verbose: bool,
quiet: bool,
Expand Down Expand Up @@ -38,6 +38,7 @@ fn main() {
let mut cli_opts = getopts::Options::new();
cli_opts.optflag("", "no-strip", "Do not strip debug symbols from the binary");
cli_opts.optflag("", "strip", "Always try to strip debug symbols");
cli_opts.optflag("", "no-separate-debug-symbols", "Do not strip debug symbols into a separate .debug file");
cli_opts.optflag("", "separate-debug-symbols", "Strip debug symbols into a separate .debug file");
cli_opts.optopt("o", "output", "Write .deb to this file or directory", "path");
cli_opts.optopt("p", "package", "Select which Cargo workspace package to use", "name");
Expand Down Expand Up @@ -99,7 +100,7 @@ fn main() {
match process(CliOptions {
no_build: matches.opt_present("no-build"),
strip_override: if matches.opt_present("strip") { Some(true) } else if matches.opt_present("no-strip") { Some(false) } else { None },
separate_debug_symbols: matches.opt_present("separate-debug-symbols"),
separate_debug_symbols: if matches.opt_present("separate-debug-symbols") { Some(true) } else if matches.opt_present("no-separate-debug-symbols") { Some(false) } else { None },
quiet: matches.opt_present("quiet"),
verbose: matches.opt_present("verbose"),
install,
Expand Down Expand Up @@ -221,6 +222,7 @@ fn process(
deb_revision,
listener,
selected_profile,
separate_debug_symbols,
)?;
reset_deb_temp_directory(&options)?;

Expand All @@ -234,7 +236,8 @@ fn process(

crate::data::compress_assets(&mut options, listener)?;

if strip_override.unwrap_or(separate_debug_symbols || !options.debug_enabled) {
if strip_override.unwrap_or(options.separate_debug_symbols || !options.debug_enabled) {
let separate_debug_symbols = options.separate_debug_symbols.clone();
strip_binaries(&mut options, target, listener, separate_debug_symbols)?;
} else {
log::debug!("not stripping profile.release.debug={} strip-flag={:?}", options.debug_enabled, strip_override);
Expand Down
37 changes: 32 additions & 5 deletions src/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,18 @@ impl Config {
/// Makes a new config from `Cargo.toml` in the `manifest_path`
///
/// `None` target means the host machine's architecture.
pub fn from_manifest(root_manifest_path: Option<&Path>, selected_package_name: Option<&str>, output_path: Option<String>, target: Option<&str>, variant: Option<&str>, deb_version: Option<String>, deb_revision: Option<String>, listener: &dyn Listener, selected_profile: &str) -> CDResult<Config> {
pub fn from_manifest(
root_manifest_path: Option<&Path>,
selected_package_name: Option<&str>,
output_path: Option<String>,
target: Option<&str>,
variant: Option<&str>,
deb_version: Option<String>,
deb_revision: Option<String>,
listener: &dyn Listener,
selected_profile: &str,
separate_debug_symbols: Option<bool>
) -> CDResult<Config> {
let metadata = cargo_metadata(root_manifest_path)?;
let available_package_names = || {
metadata.packages.iter()
Expand Down Expand Up @@ -448,7 +459,22 @@ impl Config {
let ws_root = workspace_root_manifest.as_ref().map(|ws| (ws, Path::new(&metadata.workspace_root)));
manifest.complete_from_path_and_workspace(manifest_path, ws_root)
.map_err(move |e| CargoDebError::TomlParsing(e, manifest_path.to_path_buf()))?;
Self::from_manifest_inner(manifest, workspace_root_manifest.as_ref(), target_package, package_manifest_dir, output_path, target_dir, target, variant, deb_version, deb_revision, listener, selected_profile, default_timestamp)
Self::from_manifest_inner(
manifest,
workspace_root_manifest.as_ref(),
target_package,
package_manifest_dir,
output_path,
target_dir,
target,
variant,
deb_version,
deb_revision,
listener,
selected_profile,
separate_debug_symbols,
default_timestamp
)
}

/// Convert Cargo.toml/metadata information into internal config structure
Expand All @@ -468,6 +494,7 @@ impl Config {
deb_revision: Option<String>,
listener: &dyn Listener,
selected_profile: &str,
separate_debug_symbols: Option<bool>,
default_timestamp: u64,
) -> CDResult<Self> {
// Cargo cross-compiles to a dir
Expand Down Expand Up @@ -558,7 +585,7 @@ impl Config {
maintainer_scripts: deb.maintainer_scripts.map(PathBuf::from),
features: deb.features.take().unwrap_or_default(),
default_features: deb.default_features.unwrap_or(true),
separate_debug_symbols: deb.separate_debug_symbols.unwrap_or(false),
separate_debug_symbols: separate_debug_symbols.unwrap_or_else(|| deb.separate_debug_symbols.unwrap_or(false)),
debug_enabled,
preserve_symlinks: deb.preserve_symlinks.unwrap_or(false),
systemd_units: match deb.systemd_units {
Expand Down Expand Up @@ -1514,7 +1541,7 @@ mod tests {
// supply a systemd unit file as if it were available on disk
let _g = add_test_fs_paths(&[to_canon_static_str("cargo-deb.service")]);

let config = Config::from_manifest(Some(Path::new("Cargo.toml")), None, None, None, None, None, None, &mock_listener, "release").unwrap();
let config = Config::from_manifest(Some(Path::new("Cargo.toml")), None, None, None, None, None, None, &mock_listener, "release", None).unwrap();

let num_unit_assets = config.assets.resolved.iter()
.filter(|a| a.c.target_path.starts_with("lib/systemd/system/"))
Expand All @@ -1531,7 +1558,7 @@ mod tests {
// supply a systemd unit file as if it were available on disk
let _g = add_test_fs_paths(&[to_canon_static_str("cargo-deb.service")]);

let mut config = Config::from_manifest(Some(Path::new("Cargo.toml")), None, None, None, None, None, None, &mock_listener, "release").unwrap();
let mut config = Config::from_manifest(Some(Path::new("Cargo.toml")), None, None, None, None, None, None, &mock_listener, "release", None).unwrap();

config.systemd_units.get_or_insert(vec![SystemdUnitsConfig::default()]);
config.maintainer_scripts.get_or_insert(PathBuf::new());
Expand Down

0 comments on commit 2c1628b

Please sign in to comment.