Skip to content

Commit e310e36

Browse files
kleisaukeFederico Mena Quintero
authored and
Federico Mena Quintero
committed
Fix Windows build and static linking
1 parent fd24ae3 commit e310e36

File tree

4 files changed

+73
-9
lines changed

4 files changed

+73
-9
lines changed

Makefile.am

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ NULL =
44
BUILT_SOURCES =
55

66
lib_LTLIBRARIES = librsvg-@[email protected]
7+
noinst_LTLIBRARIES = librsvg_internals.la
78

89
bin_PROGRAMS = rsvg-convert
910
if HAVE_GTK_3
@@ -25,7 +26,7 @@ librsvg_@RSVG_API_MAJOR_VERSION@_la_SOURCES = \
2526
librsvg/rsvg.h \
2627
$(NULL)
2728

28-
RUST_SRC = \
29+
librsvg_internals_la_SOURCES = \
2930
Cargo.toml \
3031
rsvg_internals/Cargo.toml \
3132
rsvg_internals/build.rs \
@@ -147,16 +148,25 @@ cargo_verbose_ = $(cargo_verbose_$(AM_DEFAULT_VERBOSITY))
147148
cargo_verbose_0 =
148149
cargo_verbose_1 = --verbose
149150

150-
RUST_LIB=@abs_top_builddir@/target/@RUST_TARGET_SUBDIR@/librsvg_internals.a
151+
RUST_LIB=@abs_top_builddir@/.libs/librsvg_internals.a
151152
CARGO_TARGET_DIR=@abs_top_builddir@/target
152153

154+
LIBRSVG_BUILD_DIR=@abs_top_builddir@
155+
LIBRSVG_TARGET_DIR=@abs_top_builddir@/target/@RUST_TARGET_SUBDIR@
156+
153157
check-local:
154158
cd $(srcdir) && \
155-
CARGO_TARGET_DIR=$(CARGO_TARGET_DIR) $(CARGO) --locked test $(CARGO_VERBOSE) $(CARGO_TARGET_ARGS) $(CARGO_RELEASE_ARGS)
159+
CARGO_TARGET_DIR=$(CARGO_TARGET_DIR) \
160+
LIBRSVG_BUILD_DIR=$(LIBRSVG_BUILD_DIR) \
161+
LIBRSVG_TARGET_DIR=$(LIBRSVG_TARGET_DIR) \
162+
$(CARGO) --locked test $(CARGO_VERBOSE) $(CARGO_TARGET_ARGS) $(CARGO_RELEASE_ARGS)
156163

157164
clean-local:
158165
cd $(top_srcdir) && \
159-
CARGO_TARGET_DIR=$(CARGO_TARGET_DIR) $(CARGO) clean
166+
CARGO_TARGET_DIR=$(CARGO_TARGET_DIR) \
167+
LIBRSVG_BUILD_DIR=$(LIBRSVG_BUILD_DIR) \
168+
LIBRSVG_TARGET_DIR=$(LIBRSVG_TARGET_DIR) \
169+
$(CARGO) clean
160170

161171
distcheck-hook:
162172
if test -z "${DESTDIR}"; \
@@ -171,12 +181,15 @@ dist-hook:
171181
mkdir .cargo && \
172182
cp cargo-vendor-config .cargo/config)
173183

174-
$(RUST_LIB): $(RUST_SRC)
184+
librsvg_internals.la: $(librsvg_internals_la_SOURCES)
175185
+cd $(top_srcdir)/rsvg_internals && \
176186
PKG_CONFIG_ALLOW_CROSS=1 \
177187
PKG_CONFIG='$(PKG_CONFIG)' \
178188
CARGO_TARGET_DIR=$(CARGO_TARGET_DIR) \
179-
$(CARGO) --locked build $(CARGO_VERBOSE) $(CARGO_TARGET_ARGS) $(CARGO_RELEASE_ARGS) --features "c-library"
189+
LIBRSVG_BUILD_DIR=$(LIBRSVG_BUILD_DIR) \
190+
LIBRSVG_TARGET_DIR=$(LIBRSVG_TARGET_DIR) \
191+
$(CARGO) --locked build $(CARGO_VERBOSE) $(CARGO_TARGET_ARGS) $(CARGO_RELEASE_ARGS) --features "c-library" \
192+
&& $(AR) d $(RUST_LIB) clzsi2.o # HACK: https://github.com/rust-lang/rust/issues/58277
180193

181194
librsvg_@RSVG_API_MAJOR_VERSION@_la_CPPFLAGS = \
182195
-I$(top_srcdir) \
@@ -202,7 +215,7 @@ librsvg_@RSVG_API_MAJOR_VERSION@_la_LDFLAGS = \
202215
$(AM_LDFLAGS)
203216

204217
librsvg_@RSVG_API_MAJOR_VERSION@_la_LIBADD = \
205-
$(RUST_LIB) \
218+
librsvg_internals.la \
206219
$(LIBRSVG_LIBS) \
207220
$(LIBM) \
208221
$(DLOPEN_LIBS)
@@ -270,7 +283,7 @@ dist_doc_DATA = \
270283
code-of-conduct.md
271284

272285
EXTRA_DIST = \
273-
$(RUST_SRC) \
286+
$(librsvg_internals_la_SOURCES) \
274287
$(RUST_EXTRA) \
275288
$(LIBRSVG_CRATE_SOURCES) \
276289
librsvg.doap \

configure.ac

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ AC_CHECK_PROGS(RUSTC, [rustc], [no])
109109
AS_IF(test x$RUSTC = xno,
110110
AC_MSG_ERROR([rustc is required. Please install the Rust toolchain from https://www.rust-lang.org/])
111111
)
112+
AC_CHECK_PROGS(AR, ar)
112113

113114
dnl Minimum version of rustc that we support
114115
dnl If you change this, please update COMPILING.md

rsvg_internals/build.rs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
use std::env;
2+
use std::fs;
23
use std::fs::File;
34
use std::io::{BufWriter, Write};
5+
use std::os::unix::fs::symlink;
46
use std::path::Path;
7+
use std::path::PathBuf;
58

69
fn main() {
710
generate_srgb_tables();
11+
generate_convenience_lib().unwrap();
812
}
913

1014
/// Converts an sRGB color value to a linear sRGB color value (undoes the gamma correction).
@@ -63,3 +67,49 @@ fn generate_srgb_tables() {
6367
print_table(&mut file, "LINEARIZE", &linearize_table);
6468
print_table(&mut file, "UNLINEARIZE", &unlinearize_table);
6569
}
70+
71+
/// Generate libtool archive file librsvg_internals.la
72+
/// From: https://docs.rs/libtool/0.1.1/libtool/
73+
pub fn generate_convenience_lib() -> std::io::Result<()> {
74+
let target = env::var("TARGET").expect("TARGET was not set");
75+
let build_dir = env::var("LIBRSVG_BUILD_DIR").expect("LIBRSVG_BUILD_DIR was not set");
76+
let target_dir = env::var("LIBRSVG_TARGET_DIR").expect("LIBRSVG_TARGET_DIR was not set");
77+
let libs_dir = format!("{}/.libs", build_dir);
78+
let libs_path = PathBuf::from(&libs_dir);
79+
let la_path = PathBuf::from(format!("{}/librsvg_internals.la", build_dir));
80+
let rust_lib = if target.contains("windows") {
81+
/* https://github.com/rust-lang/rust/issues/43749 */
82+
"rsvg_internals.lib"
83+
} else {
84+
"librsvg_internals.a"
85+
};
86+
let old_lib_path = PathBuf::from(format!("{}/{}", target_dir, rust_lib));
87+
let new_lib_path = PathBuf::from(format!("{}/librsvg_internals.a", libs_dir));
88+
89+
match fs::create_dir_all(&libs_path) {
90+
Ok(()) => println!("libs_path created"),
91+
_ => panic!("Failed to create libs_path"),
92+
}
93+
94+
if la_path.exists() {
95+
fs::remove_file(&la_path)?;
96+
}
97+
98+
/* PathBuf.exists() traverses symlinks so just try and remove it */
99+
match fs::remove_file(&new_lib_path) {
100+
Ok(_v) => {},
101+
Err(e) => println!("Error removing symlink: {:?}", e),
102+
}
103+
104+
let mut file = File::create(&la_path).unwrap();
105+
writeln!(file, "# librsvg_internals.la - a libtool library file")?;
106+
writeln!(file, "# Generated by libtool-rust")?;
107+
writeln!(file, "dlname=''")?;
108+
writeln!(file, "library_names=''")?;
109+
writeln!(file, "old_library='librsvg_internals.a'")?;
110+
writeln!(file, "inherited_linker_flags=''")?;
111+
writeln!(file, "installed=no")?;
112+
writeln!(file, "shouldnotlink=no")?;
113+
symlink(&old_lib_path, &new_lib_path)?;
114+
Ok(())
115+
}

rsvg_internals/src/properties.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ macro_rules! compute_value {
399399
impl SpecifiedValues {
400400
#[cfg_attr(rustfmt, rustfmt_skip)]
401401
pub fn set_parsed_property(&mut self, prop: &ParsedProperty) {
402-
use ParsedProperty::*;
402+
use crate::properties::ParsedProperty::*;
403403

404404
use crate::properties as p;
405405

0 commit comments

Comments
 (0)