Blame SOURCES/0001-Backport-f50f9e8d-to-v2018.8-for-RHEL8.patch

cb59a0
From 603f7e1d6ca4b0dffdb0275550a75e67d7a04623 Mon Sep 17 00:00:00 2001
cb59a0
From: Jonathan Lebon <jonathan@jlebon.com>
cb59a0
Date: Thu, 11 Oct 2018 14:16:02 -0400
cb59a0
Subject: [PATCH] Backport f50f9e8d to v2018.8 for RHEL8
cb59a0
cb59a0
We don't want to use cbindgen there, we want to use the vendored
cb59a0
rpmostree-rust.h.
cb59a0
---
cb59a0
 Makefile-rpm-ostree.am               | 22 +++++++++++++++++++---
cb59a0
 bindgen/.gitignore                   |  2 ++
cb59a0
 bindgen/Cargo.toml                   | 12 ++++++++++++
cb59a0
 rust/build.rs => bindgen/src/main.rs | 10 ++++++----
cb59a0
 configure.ac                         | 12 ++++++++++++
cb59a0
 packaging/make-git-snapshot.sh       |  7 +++++++
cb59a0
 rust/Cargo.toml                      |  4 ----
cb59a0
 7 files changed, 58 insertions(+), 11 deletions(-)
cb59a0
 create mode 100644 bindgen/.gitignore
cb59a0
 create mode 100644 bindgen/Cargo.toml
cb59a0
 rename rust/build.rs => bindgen/src/main.rs (61%)
cb59a0
cb59a0
diff --git a/Makefile-rpm-ostree.am b/Makefile-rpm-ostree.am
cb59a0
index 50a57e8e..9198961b 100644
cb59a0
--- a/Makefile-rpm-ostree.am
cb59a0
+++ b/Makefile-rpm-ostree.am
cb59a0
@@ -82,6 +82,16 @@ if BUILDOPT_NEW_NAME
cb59a0
 INSTALL_DATA_HOOKS += install-bin-hook
cb59a0
 endif
cb59a0
 
cb59a0
+if !HAVE_PREBUILT_CBINDGEN
cb59a0
+if !HAVE_EXTERNAL_CBINDGEN
cb59a0
+rpmostree-bindgen: bindgen/Cargo.toml bindgen/src/main.rs
cb59a0
+	cd $(top_srcdir)/bindgen && \
cb59a0
+	export CARGO_TARGET_DIR=@abs_top_builddir@/bindgen-target && \
cb59a0
+	$(cargo) build --verbose && \
cb59a0
+	ln -sf $${CARGO_TARGET_DIR}/debug/rpmostree-bindgen $(abs_top_builddir)/rpmostree-bindgen
cb59a0
+endif
cb59a0
+endif
cb59a0
+
cb59a0
 librpmostree_rust_path = @abs_top_builddir@/target/@RUST_TARGET_SUBDIR@/librpmostree_rust.a
cb59a0
 # If the target directory exists, use --frozen; we don't
cb59a0
 # want to (by default) touch the Internet during builds here.
cb59a0
@@ -95,11 +105,17 @@ $(librpmostree_rust_path): Makefile $(LIBRPMOSTREE_RUST_SRCS)
cb59a0
 	  $(cargo) build --verbose $${frozen} $(CARGO_RELEASE_ARGS)
cb59a0
 EXTRA_DIST += $(LIBRPMOSTREE_RUST_SRCS) rust/Cargo.lock
cb59a0
 
cb59a0
-# See rust/build.rs - it uses cbindgen as part of the Rust build
cb59a0
+# Generate bindings from Rust to C
cb59a0
+if !HAVE_PREBUILT_CBINDGEN
cb59a0
+if HAVE_EXTERNAL_CBINDGEN
cb59a0
 rpmostree-rust.h: $(librpmostree_rust_path)
cb59a0
-	$(AM_V_GEN) src=$$(find @abs_top_builddir@/target/@RUST_TARGET_SUBDIR@/ -name 'rpmostree-rust.h') && \
cb59a0
-	  test -n "$${src}" && ln -sfr "$${src}" rpmostree-rust.h
cb59a0
+	$(AM_V_GEN) cbindgen -c rust/cbindgen.toml -o $@ $(top_srcdir)/rust
cb59a0
+else
cb59a0
+rpmostree-rust.h: $(librpmostree_rust_path) rpmostree-bindgen
cb59a0
+	$(AM_V_GEN) ./rpmostree-bindgen $(top_srcdir)/rust
cb59a0
+endif
cb59a0
 BUILT_SOURCES += rpmostree-rust.h
cb59a0
+endif
cb59a0
 
cb59a0
 rpm_ostree_CFLAGS += $(PKGDEP_RPMOSTREE_RS_CFLAGS)
cb59a0
 rpm_ostree_LDADD += $(librpmostree_rust_path) $(PKGDEP_RPMOSTREE_RS_LIBS)
cb59a0
diff --git a/bindgen/.gitignore b/bindgen/.gitignore
cb59a0
new file mode 100644
cb59a0
index 00000000..fa8d85ac
cb59a0
--- /dev/null
cb59a0
+++ b/bindgen/.gitignore
cb59a0
@@ -0,0 +1,2 @@
cb59a0
+Cargo.lock
cb59a0
+target
cb59a0
diff --git a/bindgen/Cargo.toml b/bindgen/Cargo.toml
cb59a0
new file mode 100644
cb59a0
index 00000000..5a9e09ef
cb59a0
--- /dev/null
cb59a0
+++ b/bindgen/Cargo.toml
cb59a0
@@ -0,0 +1,12 @@
cb59a0
+[package]
cb59a0
+name = "rpmostree-bindgen"
cb59a0
+version = "0.1.0"
cb59a0
+authors = ["Colin Walters <walters@verbum.org>"]
cb59a0
+
cb59a0
+[dependencies]
cb59a0
+cbindgen = "0.6.3"
cb59a0
+
cb59a0
+# Might as well keep these from the main Rust source
cb59a0
+[profile.release]
cb59a0
+panic = "abort"
cb59a0
+debug = true
cb59a0
diff --git a/rust/build.rs b/bindgen/src/main.rs
cb59a0
similarity index 61%
cb59a0
rename from rust/build.rs
cb59a0
rename to bindgen/src/main.rs
cb59a0
index b2e487ee..502a021d 100644
cb59a0
--- a/rust/build.rs
cb59a0
+++ b/bindgen/src/main.rs
cb59a0
@@ -4,12 +4,14 @@
cb59a0
 extern crate cbindgen;
cb59a0
 
cb59a0
 fn run() -> Result<(), String> {
cb59a0
-    let out_dir_v = std::env::var("OUT_DIR").expect("OUT_DIR is unset");
cb59a0
-    let out_dir = std::path::Path::new(&out_dir_v);
cb59a0
-    let bindings = cbindgen::generate(std::path::Path::new(".")).map_err(|e| e.to_string())?;
cb59a0
+    let args: Vec<String> = std::env::args().collect();
cb59a0
+    let rustdir = std::path::Path::new(&args[1]);
cb59a0
+    let out = std::path::Path::new("rpmostree-rust.h");
cb59a0
+
cb59a0
+    let bindings = cbindgen::generate(rustdir).map_err(|e| e.to_string())?;
cb59a0
     // This uses unwraps internally; it'd be good to submit a patch
cb59a0
     // to add a Result-based API.
cb59a0
-    bindings.write_to_file(out_dir.join("rpmostree-rust.h"));
cb59a0
+    bindings.write_to_file(out);
cb59a0
     Ok(())
cb59a0
 }
cb59a0
 
cb59a0
diff --git a/configure.ac b/configure.ac
cb59a0
index 89cb2add..3d768e7d 100644
cb59a0
--- a/configure.ac
cb59a0
+++ b/configure.ac
cb59a0
@@ -213,6 +213,17 @@ AS_IF([test -z "$cargo"], [AC_MSG_ERROR([cargo is required for --enable-rust])])
cb59a0
 AC_PATH_PROG([rustc], [rustc])
cb59a0
 AS_IF([test -z "$rustc"], [AC_MSG_ERROR([rustc is required for --enable-rust])])
cb59a0
 
cb59a0
+dnl https://github.com/projectatomic/rpm-ostree/pull/1573
cb59a0
+dnl We support 3 modes for bindgen:
cb59a0
+dnl  - External /usr/bin/cbindgen (Fedora + CI)
cb59a0
+dnl  - Downloading it from crates.io (CentOS + CI builds)
cb59a0
+dnl  - Not running it at all, and using a pre-built rpmostree-rust.h (Koji)
cb59a0
+AS_IF([test -d "${srcdir}"/rust/vendor],
cb59a0
+      [cbindgen=dist],
cb59a0
+      [AC_PATH_PROG([cbindgen], [cbindgen])])
cb59a0
+AM_CONDITIONAL(HAVE_PREBUILT_CBINDGEN, [test "${cbindgen}" = "dist"])
cb59a0
+AM_CONDITIONAL(HAVE_EXTERNAL_CBINDGEN, [test -n "${cbindgen}" && test "${cbindgen}" != dist])
cb59a0
+
cb59a0
 AC_MSG_CHECKING(whether to build in debug mode)
cb59a0
 debug_release=release
cb59a0
 if $(echo $CFLAGS |grep -q -E "(-O0|-Og)"); then
cb59a0
@@ -279,4 +290,5 @@ echo "
cb59a0
     bubblewrap:                              $with_bubblewrap
cb59a0
     gtk-doc:                                 $enable_gtk_doc
cb59a0
     rust:                                    $rust_debug_release
cb59a0
+    cbindgen:                                ${cbindgen:-internal}
cb59a0
 "
cb59a0
diff --git a/packaging/make-git-snapshot.sh b/packaging/make-git-snapshot.sh
cb59a0
index bbcf0092..da285e8c 100755
cb59a0
--- a/packaging/make-git-snapshot.sh
cb59a0
+++ b/packaging/make-git-snapshot.sh
cb59a0
@@ -47,4 +47,11 @@ mkdir ${tmpd} && touch ${tmpd}/.tmp
cb59a0
  cp ${TOP}/rust/cargo-vendor-config .cargo/config
cb59a0
  tar --transform="s,^,${PKG_VER}/rust/," -rf ${TARFILE_TMP} * .cargo/
cb59a0
  )
cb59a0
+
cb59a0
+# And finally, vendor rpmostree-rust.h; it's generated by cbindgen,
cb59a0
+# and it's easier than vendoring all of the source for that too.
cb59a0
+# This is currently the *only* generated file we treat this way. See also
cb59a0
+# https://github.com/projectatomic/rpm-ostree/pull/1573
cb59a0
+(cd ${srcdir} && tar --transform "s,^,${PKG_VER}/," -rf ${TARFILE_TMP} rpmostree-rust.h)
cb59a0
+
cb59a0
 mv ${TARFILE_TMP} ${TARFILE}
cb59a0
diff --git a/rust/Cargo.toml b/rust/Cargo.toml
cb59a0
index ee95b012..258da5fa 100644
cb59a0
--- a/rust/Cargo.toml
cb59a0
+++ b/rust/Cargo.toml
cb59a0
@@ -2,7 +2,6 @@
cb59a0
 name = "rpmostree-rust"
cb59a0
 version = "0.1.0"
cb59a0
 authors = ["Colin Walters <walters@verbum.org>"]
cb59a0
-build = "build.rs"
cb59a0
 
cb59a0
 [dependencies]
cb59a0
 serde = "1.0"
cb59a0
@@ -17,9 +16,6 @@ tempfile = "3.0.3"
cb59a0
 openat = "0.1.15"
cb59a0
 curl = "0.4.14"
cb59a0
 
cb59a0
-[build-dependencies]
cb59a0
-cbindgen = "0.6.3"
cb59a0
-
cb59a0
 [lib]
cb59a0
 name = "rpmostree_rust"
cb59a0
 path = "src/lib.rs"
cb59a0
-- 
cb59a0
2.17.1
cb59a0