From d40e28428936b1963b029652e6bd24983039fff2 Mon Sep 17 00:00:00 2001 From: William Brown Date: Tue, 21 Nov 2017 11:23:05 +0100 Subject: [PATCH] Ticket 49325 - fix rust linking. Bug Description: An issue with the rpm was found that the way the static .a was built would cause a missing library error when the rpm was distributed. Fix Description: Because both cargo and automake are opinionated and stubborn, this leaves the option as have cargo generate the .so but write manual rules for install and linking. This has been tested now with non-prefix, prefix, rpm build, copr. https://pagure.io/389-ds-base/issue/49325 Author: wibrown Review by: ??? --- Makefile.am | 39 ++++++++++++++++++++++----------------- rpm/389-ds-base.spec.in | 5 +---- src/libsds/Cargo.toml | 2 +- 3 files changed, 24 insertions(+), 22 deletions(-) diff --git a/Makefile.am b/Makefile.am index e3b30b6..bdce18a 100644 --- a/Makefile.am +++ b/Makefile.am @@ -308,11 +308,7 @@ bin_PROGRAMS = dbscan \ # based on defines # ---------------------------------------------------------------------------------------- -server_LTLIBRARIES = -if RUST_ENABLE -server_LTLIBRARIES += librsds.la -endif -server_LTLIBRARIES += libsds.la libnunc-stans.la libldaputil.la libslapd.la libns-dshttpd.la +server_LTLIBRARIES = libsds.la libnunc-stans.la libldaputil.la libslapd.la libns-dshttpd.la # this is how to add optional plugins @@ -1095,25 +1091,34 @@ libsds_la_CPPFLAGS = $(AM_CPPFLAGS) $(SDS_CPPFLAGS) libsds_la_LDFLAGS = $(AM_LDFLAGS) $(SDS_LDFLAGS) if RUST_ENABLE -libsds_la_LIBADD = librsds.la - -librsdspatha = $(abs_top_builddir)/rs/@rust_target_dir@/librsds.a -librsdspatho = $(abs_top_builddir)/rs/@rust_target_dir@/librsds.o -# Remember, these emit to cargo_target_dir/rust_target_dir/emit target -$(librsdspatha): Makefile src/libsds/Cargo.toml src/libsds/sds/lib.rs src/libsds/sds/tqueue.rs - CARGO_TARGET_DIR=$(abs_top_builddir)/rs cargo rustc $(CARGO_FLAGS) --verbose --manifest-path=$(srcdir)/src/libsds/Cargo.toml -- $(RUSTC_FLAGS) --emit link=$(librsdspatha) +### Why does this exist? +# +# Both cargo and autotools are really opinionated. You can't generate the correct +# outputs from cargo/rust for automake to use. But by the same token, you can't +# convince automake to use the outputs we *do* have. So instead, we manually +# create and install the .so instead. +# +# This acts like .PHONY for some reason ... -$(librsdspatho): Makefile src/libsds/Cargo.toml src/libsds/sds/lib.rs src/libsds/sds/tqueue.rs - CARGO_TARGET_DIR=$(abs_top_builddir)/rs cargo rustc $(CARGO_FLAGS) --verbose --manifest-path=$(srcdir)/src/libsds/Cargo.toml -- $(RUSTC_FLAGS) --emit obj=$(librsdspatho) +libsds_la_LDFLAGS += -L$(abs_builddir)/.libs -lrsds +libsds_la_DEPENDENCIES = librsds.so -am_librsds_la_OBJECTS = $(librsdspatho) -librsds_la_LIBADD = $(librsdspatha) -librsds_la_SOURCES = +librsds.so: src/libsds/Cargo.toml src/libsds/sds/lib.rs src/libsds/sds/tqueue.rs + CARGO_TARGET_DIR=$(abs_top_builddir)/rs \ + cargo rustc $(CARGO_FLAGS) --verbose --manifest-path=$(srcdir)/src/libsds/Cargo.toml \ + -- $(RUSTC_FLAGS) + mkdir -p $(abs_builddir)/.libs + cp $(abs_top_builddir)/rs/@rust_target_dir@/librsds.so $(abs_builddir)/.libs/librsds.so dist_noinst_DATA += $(srcdir)/src/libsds/Cargo.toml \ $(srcdir)/src/libsds/sds/*.rs +# echo $(serverdir) +install-data-local: + $(MKDIR_P) $(DESTDIR)$(serverdir) + $(INSTALL) -c -m 755 $(abs_builddir)/.libs/librsds.so $(DESTDIR)$(serverdir)/librsds.so + else # Just build the tqueue in C. libsds_la_SOURCES += \ diff --git a/rpm/389-ds-base.spec.in b/rpm/389-ds-base.spec.in index d16ab5a..f3c3699 100644 --- a/rpm/389-ds-base.spec.in +++ b/rpm/389-ds-base.spec.in @@ -539,9 +539,6 @@ fi %{_libdir}/%{pkgname}/libnunc-stans.so %{_libdir}/%{pkgname}/libsds.so %{_libdir}/%{pkgname}/libldaputil.so -%if %{use_rust} -%{_libdir}/%{pkgname}/librsds.so -%endif %{_libdir}/pkgconfig/* %files libs @@ -554,7 +551,7 @@ fi %{_libdir}/%{pkgname}/libsds.so.* %{_libdir}/%{pkgname}/libldaputil.so.* %if %{use_rust} -%{_libdir}/%{pkgname}/librsds.so.* +%{_libdir}/%{pkgname}/librsds.so %endif %files snmp diff --git a/src/libsds/Cargo.toml b/src/libsds/Cargo.toml index 594326c..2c57e66 100644 --- a/src/libsds/Cargo.toml +++ b/src/libsds/Cargo.toml @@ -8,7 +8,7 @@ authors = ["William Brown "] [lib] path = "sds/lib.rs" name = "rsds" -crate-type = ["dylib"] +crate-type = ["cdylib"] [profile.release] panic = "abort" -- 1.8.3.1