[librsvg: 34/36] Fix Windows build and static linking
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 34/36] Fix Windows build and static linking
- Date: Mon, 1 Jul 2019 01:56:29 +0000 (UTC)
commit e310e36b11fd706a7c995d1d0e1685da7d168f78
Author: Kleis Auke Wolthuizen <github kleisauke nl>
Date: Tue Jun 25 16:54:20 2019 +0200
Fix Windows build and static linking
Makefile.am | 29 ++++++++++++++++-------
configure.ac | 1 +
rsvg_internals/build.rs | 50 ++++++++++++++++++++++++++++++++++++++++
rsvg_internals/src/properties.rs | 2 +-
4 files changed, 73 insertions(+), 9 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index a2b88382..17929e24 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -4,6 +4,7 @@ NULL =
BUILT_SOURCES =
lib_LTLIBRARIES = librsvg-@RSVG_API_MAJOR_VERSION@.la
+noinst_LTLIBRARIES = librsvg_internals.la
bin_PROGRAMS = rsvg-convert
if HAVE_GTK_3
@@ -25,7 +26,7 @@ librsvg_@RSVG_API_MAJOR_VERSION@_la_SOURCES = \
librsvg/rsvg.h \
$(NULL)
-RUST_SRC = \
+librsvg_internals_la_SOURCES = \
Cargo.toml \
rsvg_internals/Cargo.toml \
rsvg_internals/build.rs \
@@ -147,16 +148,25 @@ cargo_verbose_ = $(cargo_verbose_$(AM_DEFAULT_VERBOSITY))
cargo_verbose_0 =
cargo_verbose_1 = --verbose
-RUST_LIB=@abs_top_builddir@/target/@RUST_TARGET_SUBDIR@/librsvg_internals.a
+RUST_LIB=@abs_top_builddir@/.libs/librsvg_internals.a
CARGO_TARGET_DIR=@abs_top_builddir@/target
+LIBRSVG_BUILD_DIR=@abs_top_builddir@
+LIBRSVG_TARGET_DIR=@abs_top_builddir@/target/@RUST_TARGET_SUBDIR@
+
check-local:
cd $(srcdir) && \
- CARGO_TARGET_DIR=$(CARGO_TARGET_DIR) $(CARGO) --locked test $(CARGO_VERBOSE) $(CARGO_TARGET_ARGS)
$(CARGO_RELEASE_ARGS)
+ CARGO_TARGET_DIR=$(CARGO_TARGET_DIR) \
+ LIBRSVG_BUILD_DIR=$(LIBRSVG_BUILD_DIR) \
+ LIBRSVG_TARGET_DIR=$(LIBRSVG_TARGET_DIR) \
+ $(CARGO) --locked test $(CARGO_VERBOSE) $(CARGO_TARGET_ARGS) $(CARGO_RELEASE_ARGS)
clean-local:
cd $(top_srcdir) && \
- CARGO_TARGET_DIR=$(CARGO_TARGET_DIR) $(CARGO) clean
+ CARGO_TARGET_DIR=$(CARGO_TARGET_DIR) \
+ LIBRSVG_BUILD_DIR=$(LIBRSVG_BUILD_DIR) \
+ LIBRSVG_TARGET_DIR=$(LIBRSVG_TARGET_DIR) \
+ $(CARGO) clean
distcheck-hook:
if test -z "${DESTDIR}"; \
@@ -171,12 +181,15 @@ dist-hook:
mkdir .cargo && \
cp cargo-vendor-config .cargo/config)
-$(RUST_LIB): $(RUST_SRC)
+librsvg_internals.la: $(librsvg_internals_la_SOURCES)
+cd $(top_srcdir)/rsvg_internals && \
PKG_CONFIG_ALLOW_CROSS=1 \
PKG_CONFIG='$(PKG_CONFIG)' \
CARGO_TARGET_DIR=$(CARGO_TARGET_DIR) \
- $(CARGO) --locked build $(CARGO_VERBOSE) $(CARGO_TARGET_ARGS) $(CARGO_RELEASE_ARGS) --features
"c-library"
+ LIBRSVG_BUILD_DIR=$(LIBRSVG_BUILD_DIR) \
+ LIBRSVG_TARGET_DIR=$(LIBRSVG_TARGET_DIR) \
+ $(CARGO) --locked build $(CARGO_VERBOSE) $(CARGO_TARGET_ARGS) $(CARGO_RELEASE_ARGS) --features
"c-library" \
+ && $(AR) d $(RUST_LIB) clzsi2.o # HACK: https://github.com/rust-lang/rust/issues/58277
librsvg_@RSVG_API_MAJOR_VERSION@_la_CPPFLAGS = \
-I$(top_srcdir) \
@@ -202,7 +215,7 @@ librsvg_@RSVG_API_MAJOR_VERSION@_la_LDFLAGS = \
$(AM_LDFLAGS)
librsvg_@RSVG_API_MAJOR_VERSION@_la_LIBADD = \
- $(RUST_LIB) \
+ librsvg_internals.la \
$(LIBRSVG_LIBS) \
$(LIBM) \
$(DLOPEN_LIBS)
@@ -270,7 +283,7 @@ dist_doc_DATA = \
code-of-conduct.md
EXTRA_DIST = \
- $(RUST_SRC) \
+ $(librsvg_internals_la_SOURCES) \
$(RUST_EXTRA) \
$(LIBRSVG_CRATE_SOURCES) \
librsvg.doap \
diff --git a/configure.ac b/configure.ac
index 82728873..93dc2bd2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -109,6 +109,7 @@ AC_CHECK_PROGS(RUSTC, [rustc], [no])
AS_IF(test x$RUSTC = xno,
AC_MSG_ERROR([rustc is required. Please install the Rust toolchain from https://www.rust-lang.org/])
)
+AC_CHECK_PROGS(AR, ar)
dnl Minimum version of rustc that we support
dnl If you change this, please update COMPILING.md
diff --git a/rsvg_internals/build.rs b/rsvg_internals/build.rs
index b30fac62..29249991 100644
--- a/rsvg_internals/build.rs
+++ b/rsvg_internals/build.rs
@@ -1,10 +1,14 @@
use std::env;
+use std::fs;
use std::fs::File;
use std::io::{BufWriter, Write};
+use std::os::unix::fs::symlink;
use std::path::Path;
+use std::path::PathBuf;
fn main() {
generate_srgb_tables();
+ generate_convenience_lib().unwrap();
}
/// Converts an sRGB color value to a linear sRGB color value (undoes the gamma correction).
@@ -63,3 +67,49 @@ fn generate_srgb_tables() {
print_table(&mut file, "LINEARIZE", &linearize_table);
print_table(&mut file, "UNLINEARIZE", &unlinearize_table);
}
+
+/// Generate libtool archive file librsvg_internals.la
+/// From: https://docs.rs/libtool/0.1.1/libtool/
+pub fn generate_convenience_lib() -> std::io::Result<()> {
+ let target = env::var("TARGET").expect("TARGET was not set");
+ let build_dir = env::var("LIBRSVG_BUILD_DIR").expect("LIBRSVG_BUILD_DIR was not set");
+ let target_dir = env::var("LIBRSVG_TARGET_DIR").expect("LIBRSVG_TARGET_DIR was not set");
+ let libs_dir = format!("{}/.libs", build_dir);
+ let libs_path = PathBuf::from(&libs_dir);
+ let la_path = PathBuf::from(format!("{}/librsvg_internals.la", build_dir));
+ let rust_lib = if target.contains("windows") {
+ /* https://github.com/rust-lang/rust/issues/43749 */
+ "rsvg_internals.lib"
+ } else {
+ "librsvg_internals.a"
+ };
+ let old_lib_path = PathBuf::from(format!("{}/{}", target_dir, rust_lib));
+ let new_lib_path = PathBuf::from(format!("{}/librsvg_internals.a", libs_dir));
+
+ match fs::create_dir_all(&libs_path) {
+ Ok(()) => println!("libs_path created"),
+ _ => panic!("Failed to create libs_path"),
+ }
+
+ if la_path.exists() {
+ fs::remove_file(&la_path)?;
+ }
+
+ /* PathBuf.exists() traverses symlinks so just try and remove it */
+ match fs::remove_file(&new_lib_path) {
+ Ok(_v) => {},
+ Err(e) => println!("Error removing symlink: {:?}", e),
+ }
+
+ let mut file = File::create(&la_path).unwrap();
+ writeln!(file, "# librsvg_internals.la - a libtool library file")?;
+ writeln!(file, "# Generated by libtool-rust")?;
+ writeln!(file, "dlname=''")?;
+ writeln!(file, "library_names=''")?;
+ writeln!(file, "old_library='librsvg_internals.a'")?;
+ writeln!(file, "inherited_linker_flags=''")?;
+ writeln!(file, "installed=no")?;
+ writeln!(file, "shouldnotlink=no")?;
+ symlink(&old_lib_path, &new_lib_path)?;
+ Ok(())
+}
diff --git a/rsvg_internals/src/properties.rs b/rsvg_internals/src/properties.rs
index 4e693756..c6f5561b 100644
--- a/rsvg_internals/src/properties.rs
+++ b/rsvg_internals/src/properties.rs
@@ -399,7 +399,7 @@ macro_rules! compute_value {
impl SpecifiedValues {
#[cfg_attr(rustfmt, rustfmt_skip)]
pub fn set_parsed_property(&mut self, prop: &ParsedProperty) {
- use ParsedProperty::*;
+ use crate::properties::ParsedProperty::*;
use crate::properties as p;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]