[librsvg] Support cross-compiling with Rust



commit fd9541ad05f9a4f795242dfde75a1ccf233c2d8b
Author: David Michael <fedora dm0 gmail com>
Date:   Sat Nov 4 22:50:15 2017 -0400

    Support cross-compiling with Rust
    
    The primary change here is to add the --target=$(host) option to
    the cargo build command, so the Rust components are compiled for
    the target host system specified by the configure command.  The
    cargo target subdirectory also needed to be prefixed with the host
    triplet for cross-compiling.
    
    Some of the crates' build scripts require cross-pkg-config settings
    in the environment, so they are set for the cargo build command.
    
    It's worth noting that Rust targets are limited to built-in values
    by default, so the --host value given to configure may not be
    supported.  Built in targets can be found by listing the directory
    src/librustc_back/target in the rustc source.  When building with
    an unsupported target, the user will have to write a target JSON
    definition file and set the environment variable RUST_TARGET_PATH
    to its directory (as with building any Rust project).
    
    This also sneaks in prefixing the Rust library recipe line with a
    "+" character to pass the GNU Make jobserver environment and file
    descriptors, which cargo supports to act as a jobserver client.

 Makefile.am  |   10 +++++++---
 configure.ac |    3 +++
 2 files changed, 10 insertions(+), 3 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index b18babc..75bd875 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -109,6 +109,10 @@ else
 CARGO_RELEASE_ARGS=--release
 endif
 
+if CROSS_COMPILING
+CARGO_TARGET_ARGS=--target=$(host)
+endif
+
 CARGO_VERBOSE = $(cargo_verbose_$(V))
 cargo_verbose_ = $(cargo_verbose_$(AM_DEFAULT_VERBOSITY))
 cargo_verbose_0 =
@@ -130,9 +134,9 @@ dist-hook:
        mkdir .cargo && \
        cp cargo-vendor-config .cargo/config)
 
-@abs_top_builddir@/rust/target/@RUST_TARGET_SUBDIR@/librsvg_internals.a: $(RUST_SOURCES)
-       cd $(top_srcdir)/rust && \
-       CARGO_TARGET_DIR=@abs_top_builddir@/rust/target cargo build $(CARGO_VERBOSE) $(CARGO_RELEASE_ARGS)
+$(RUST_LIB): $(RUST_SOURCES)
+       +cd $(top_srcdir)/rust && PKG_CONFIG_ALLOW_CROSS=1 PKG_CONFIG='$(PKG_CONFIG)' \
+       CARGO_TARGET_DIR=@abs_top_builddir@/rust/target cargo build $(CARGO_VERBOSE) $(CARGO_TARGET_ARGS) 
$(CARGO_RELEASE_ARGS)
 
 librsvg_@RSVG_API_MAJOR_VERSION@_la_CPPFLAGS = \
        -I$(top_srcdir)                         \
diff --git a/configure.ac b/configure.ac
index 93b9af0..18ca8bd 100644
--- a/configure.ac
+++ b/configure.ac
@@ -262,6 +262,9 @@ else
 fi
 AM_CONDITIONAL([DEBUG_RELEASE], [test "x$debug_release" = "xyes"])
 
+if test "x$cross_compiling" = "xyes" ; then
+       RUST_TARGET_SUBDIR="$host/$RUST_TARGET_SUBDIR"
+fi
 AC_SUBST([RUST_TARGET_SUBDIR])
 
 dnl ===========================================================================


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]