Skip to content
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

Complete the soversion granularity #350

Merged
merged 2 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 20 additions & 20 deletions src/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use semver::Version;

use crate::build::*;
use crate::build_targets::BuildTargets;
use crate::VersionExt;

fn append_to_destdir(destdir: Option<&Path>, path: &Path) -> PathBuf {
if let Some(destdir) = destdir {
Expand Down Expand Up @@ -101,43 +102,40 @@ impl LibType {

pub(crate) struct UnixLibNames {
canonical: String,
with_major_ver: String,
with_main_ver: String,
with_full_ver: String,
}

impl UnixLibNames {
pub(crate) fn new(lib_type: LibType, lib_name: &str, lib_version: &Version) -> Option<Self> {
let main_version = lib_version.main_version();

match lib_type {
LibType::So => {
let lib = format!("lib{lib_name}.so");
let lib_with_major_ver = format!("{}.{}", lib, lib_version.major);
let lib_with_full_ver = format!(
"{}.{}.{}",
lib_with_major_ver, lib_version.minor, lib_version.patch
"{}.{}.{}.{}",
lib, lib_version.major, lib_version.minor, lib_version.patch
);
let lib_with_main_ver = format!("{}.{}", lib, main_version);

Some(Self {
canonical: lib,
with_major_ver: lib_with_major_ver,
with_main_ver: lib_with_main_ver,
with_full_ver: lib_with_full_ver,
})
}
LibType::Dylib => {
let lib = format!("lib{lib_name}.dylib");
let lib_with_major_ver = if lib_version.major == 0 {
format!(
"lib{}.{}.{}.dylib",
lib_name, lib_version.major, lib_version.minor
)
} else {
format!("lib{}.{}.dylib", lib_name, lib_version.major)
};
let lib_with_main_ver = format!("lib{}.{}.dylib", lib_name, main_version);

let lib_with_full_ver = format!(
"lib{}.{}.{}.{}.dylib",
lib_name, lib_version.major, lib_version.minor, lib_version.patch
);
Some(Self {
canonical: lib,
with_major_ver: lib_with_major_ver,
with_main_ver: lib_with_main_ver,
with_full_ver: lib_with_full_ver,
})
}
Expand All @@ -146,12 +144,14 @@ impl UnixLibNames {
}

fn links(&self, install_path_lib: &Path) {
let mut ln_sf = std::process::Command::new("ln");
ln_sf.arg("-sf");
ln_sf
.arg(&self.with_full_ver)
.arg(install_path_lib.join(&self.with_major_ver));
let _ = ln_sf.status().unwrap();
if self.with_main_ver != self.with_full_ver {
let mut ln_sf = std::process::Command::new("ln");
ln_sf.arg("-sf");
ln_sf
.arg(&self.with_full_ver)
.arg(install_path_lib.join(&self.with_main_ver));
let _ = ln_sf.status().unwrap();
Copy link
Contributor

@kpcyrd kpcyrd Oct 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This panics if the ln binary couldn't be executed, and ignores the ExitStatus if ln returned an error (below for self.canonical too).

fn links(...) could be changed to fn links(...) -> anyhow::Result<()>, creating the symlink could also be its own function.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's unrelated to this set, but it would be a welcomed change, if you feel like sending a patch for it :)

}

let mut ln_sf = std::process::Command::new("ln");
ln_sf.arg("-sf");
Expand Down
19 changes: 19 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,22 @@ pub mod config;
pub mod install;
pub mod pkg_config_gen;
pub mod target;

trait VersionExt {
/// build the main version string
fn main_version(&self) -> String;
}

impl VersionExt for semver::Version {
fn main_version(&self) -> String {
if self.major == 0 {
if self.minor == 0 {
format!("{}.{}.{}", self.major, self.minor, self.patch)
} else {
format!("{}.{}", self.major, self.minor)
}
} else {
format!("{}", self.major)
}
lu-zero marked this conversation as resolved.
Show resolved Hide resolved
}
}
7 changes: 2 additions & 5 deletions src/target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::path::Path;
use anyhow::*;

use crate::build::CApiConfig;
use crate::VersionExt;

/// Split a target string to its components
///
Expand Down Expand Up @@ -69,11 +70,7 @@ impl Target {
let os = &self.os;
let env = &self.env;

let sover = if major == 0 {
format!("{major}.{minor}")
} else {
format!("{major}")
};
let sover = version.main_version();

if os == "android" {
lines.push(format!("-Wl,-soname,lib{lib_name}.so"));
Expand Down