Skip to content

Commit

Permalink
Complete the soversion granularity
Browse files Browse the repository at this point in the history
Co-authored-by: kpcyrd <git@rxv.cc>
  • Loading branch information
lu-zero and kpcyrd authored Oct 11, 2023
1 parent 712a0c4 commit 8f78176
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 25 deletions.
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();
}

let mut ln_sf = std::process::Command::new("ln");
ln_sf.arg("-sf");
Expand Down
15 changes: 15 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,18 @@ 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 {
match (self.major, self.minor, self.patch) {
(0, 0, patch) => format!("0.0.{patch}"),
(0, minor, _) => format!("0.{minor}"),
(major, _, _) => format!("{major}"),
}
}
}
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

0 comments on commit 8f78176

Please sign in to comment.