From c718f34d435a913d462e90c74adff03c6252dc7b Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Fri, 11 Dec 2020 15:09:57 +0000 Subject: [PATCH] Fix and improve support for rpmostree-rust.h being pre-generated First, we now need the `vendor/` directory at the toplevel because that's where `Cargo.toml` is. Now this triggers another bug introduced in the build system with how we're handling the `rpmostree-rust.h` header. We ended up vendoring a pre-generated one in the tarball mainly because RHEL doesn't include cbindgen. Now probably in the future I'd like to fix that. But let's clean this up - the tarball generation process copies the file into `rpmostree-rust-prebuilt.h`, and build machinery detects that and entirely skips looking for or trying to build our internal cbindgen. --- Makefile-rpm-ostree.am | 7 ++++++- configure.ac | 8 ++++++-- packaging/make-git-snapshot.sh | 4 ++-- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/Makefile-rpm-ostree.am b/Makefile-rpm-ostree.am index b1cfdb12..713d4b00 100644 --- a/Makefile-rpm-ostree.am +++ b/Makefile-rpm-ostree.am @@ -106,6 +106,10 @@ $(librpmostree_rust_path): Makefile $(LIBRPMOSTREE_RUST_SRCS) EXTRA_DIST += $(LIBRPMOSTREE_RUST_SRCS) # Generate bindings from Rust to C +if BUILDOPT_PREBUILT_BINDINGS +rpmostree-rust.h: + ln -sfr rpmostree-rust-prebuilt.h $@ +else if !HAVE_PREBUILT_CBINDGEN if HAVE_EXTERNAL_CBINDGEN rpmostree-rust.h: @@ -114,8 +118,9 @@ else rpmostree-rust.h: rpmostree-bindgen $(AM_V_GEN) ./rpmostree-bindgen $(top_srcdir) endif -BUILT_SOURCES += rpmostree-rust.h endif +endif +BUILT_SOURCES += rpmostree-rust.h rpm_ostree_CFLAGS += $(PKGDEP_RPMOSTREE_RS_CFLAGS) rpm_ostree_LDADD += $(librpmostree_rust_path) $(PKGDEP_RPMOSTREE_RS_LIBS) -lstdc++ diff --git a/configure.ac b/configure.ac index d319e2fe..e1d2d205 100644 --- a/configure.ac +++ b/configure.ac @@ -195,14 +195,18 @@ AS_IF([test -z "$cargo"], [AC_MSG_ERROR([cargo is required for --enable-rust])]) AC_PATH_PROG([rustc], [rustc]) AS_IF([test -z "$rustc"], [AC_MSG_ERROR([rustc is required for --enable-rust])]) +dnl this is true effectively iff we used make-git-snapshot.sh +AM_CONDITIONAL(BUILDOPT_PREBUILT_BINDINGS, [test -f rpmostree-rust-prebuilt.h]) + +AM_COND_IF([BUILDOPT_PREBUILT_BINDINGS], [cbindgen=prebuilt], [ dnl https://github.com/projectatomic/rpm-ostree/pull/1573 -dnl We support 3 modes for bindgen: +dnl We support 2 modes for bindgen: dnl - External /usr/bin/cbindgen (Fedora + CI) dnl - Downloading it from crates.io (CentOS + CI builds) -dnl - Not running it at all, and using a pre-built rpmostree-rust.h (Koji) AS_IF([test -d "${srcdir}"/rust/vendor], [cbindgen=dist], [AC_PATH_PROG([cbindgen], [cbindgen])]) +]) AM_CONDITIONAL(HAVE_PREBUILT_CBINDGEN, [test "${cbindgen}" = "dist"]) AM_CONDITIONAL(HAVE_EXTERNAL_CBINDGEN, [test -n "${cbindgen}" && test "${cbindgen}" != dist]) diff --git a/packaging/make-git-snapshot.sh b/packaging/make-git-snapshot.sh index fb69c907..d9102609 100755 --- a/packaging/make-git-snapshot.sh +++ b/packaging/make-git-snapshot.sh @@ -57,13 +57,13 @@ j = json.load(open(checksum_file)) j["files"] = {f:c for f, c in j["files"].items() if not f.startswith(subdir)} open(checksum_file, "w").write(json.dumps(j))' $crate_subdir done - tar --transform="s,^,${PKG_VER}/rust/," -rf ${TARFILE_TMP} * .cargo/ + tar --transform="s,^,${PKG_VER}/," -rf ${TARFILE_TMP} * .cargo/ ) # And finally, vendor rpmostree-rust.h; it's generated by cbindgen, # and it's easier than vendoring all of the source for that too. # This is currently the *only* generated file we treat this way. See also # https://github.com/projectatomic/rpm-ostree/pull/1573 -(cd ${srcdir} && tar --transform "s,^,${PKG_VER}/," -rf ${TARFILE_TMP} rpmostree-rust.h) +(cd ${srcdir} && cp rpmostree-rust{,-prebuilt}.h && tar --transform "s,^,${PKG_VER}/," -rf ${TARFILE_TMP} rpmostree-rust-prebuilt.h) mv ${TARFILE_TMP} ${TARFILE}