Move libdnf build over to Cargo
This is now further migration towards Cargo/Rust possible because we switched our main binary. We've had an internal `libdnf-sys` crate for a while, but now it can take over the build of the underlying library too (like many `-sys` crates support). This itself is just an incremental step towards migrating the main rpm-ostree build system to e.g. cmake too (or perhaps directly with the `cc` crate, not sure yet) and driving it via `cargo` too.
This commit is contained in:
parent
2128f5784a
commit
588541c60d
10
Cargo.lock
generated
10
Cargo.lock
generated
@ -131,6 +131,15 @@ dependencies = [
|
||||
"vec_map",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cmake"
|
||||
version = "0.1.45"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "eb6210b637171dfba4cda12e579ac6dc73f5165ad56133e5d72ef3131f320855"
|
||||
dependencies = [
|
||||
"cc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "console"
|
||||
version = "0.14.0"
|
||||
@ -630,6 +639,7 @@ name = "libdnf-sys"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"cmake",
|
||||
"libc",
|
||||
"system-deps 2.0.3",
|
||||
]
|
||||
|
@ -1,32 +0,0 @@
|
||||
# Makefile for C source code
|
||||
#
|
||||
# Copyright (C) 2016 Colin Walters <walters@verbum.org>
|
||||
#
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Lesser General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This library is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public
|
||||
# License along with this library; if not, write to the
|
||||
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
# Boston, MA 02111-1307, USA.
|
||||
|
||||
# Recurse into libdnf
|
||||
ALL_LOCAL_HOOKS += libdnf-local
|
||||
libdnf-local:
|
||||
cd libdnf-build && $(MAKE) $(if $(subst 0,,$(V)),VERBOSE=1,)
|
||||
ln -sf libdnf-build/libdnf/libdnf.a .
|
||||
libdnf.a: libdnf-local
|
||||
CLEANFILES += libdnf.a
|
||||
GITIGNOREFILES += libdnf-build/
|
||||
|
||||
clean-local: clean-local-dnf
|
||||
.PHONY: clean-local-dnf
|
||||
clean-local-dnf:
|
||||
cd libdnf-build && $(MAKE) clean
|
@ -79,7 +79,7 @@ rpmostree_common_cflags = -I$(srcdir)/src/app -I$(srcdir)/src/daemon \
|
||||
-I$(srcdir)/src/lib -I$(srcdir)/src/libpriv -I$(libglnx_srcpath) \
|
||||
-DG_LOG_DOMAIN=\"rpm-ostreed\" \
|
||||
-DLIBDIR=\"$(libdir)\" -DPKGLIBDIR=\"$(pkglibdir)\" \
|
||||
-I $(top_srcdir)/libdnf -I $(top_srcdir)/libdnf-build \
|
||||
-I $(top_srcdir)/libdnf \
|
||||
$(PKGDEP_RPMOSTREE_CFLAGS) $(PKGDEP_RPMOSTREE_RS_CFLAGS)
|
||||
rpmostree_bin_common_cflags = $(rpmostree_common_cflags)
|
||||
rpmostree_common_libs = libglnx.la librpmostree-1.la librpmostreecxxrs.la $(PKGDEP_RPMOSTREE_RS_LIBS) $(PKGDEP_RPMOSTREE_LIBS)
|
||||
|
@ -103,7 +103,6 @@ GITIGNOREFILES += "fastbuild*.qcow2" _kola_temp/
|
||||
include libglnx/Makefile-libglnx.am.inc
|
||||
noinst_LTLIBRARIES += libglnx.la
|
||||
include Makefile-libpriv.am
|
||||
include Makefile-libdnf.am
|
||||
include Makefile-lib.am
|
||||
include Makefile-daemon.am
|
||||
include Makefile-rpm-ostree.am
|
||||
|
2
build.rs
2
build.rs
@ -25,8 +25,6 @@ fn main() -> Result<()> {
|
||||
cwd
|
||||
);
|
||||
println!("cargo:rustc-link-lib=cap");
|
||||
println!("cargo:rustc-link-search={}/libdnf-build/libdnf", cwd);
|
||||
println!("cargo:rustc-link-lib=dnf");
|
||||
println!("cargo:rustc-link-lib=rt");
|
||||
println!("cargo:rustc-link-lib=stdc++");
|
||||
// https://github.com/ostreedev/ostree/commit/1f832597fc83fda6cb8daf48c4495a9e1590774c
|
||||
|
32
configure.ac
32
configure.ac
@ -163,38 +163,6 @@ AM_COND_IF([BUILDOPT_ROJIG], [
|
||||
AC_DEFINE([BUILDOPT_ROJIG], 1, [Define if rojig is enabled])
|
||||
])
|
||||
|
||||
dnl And propagate the release/debug type to cmake
|
||||
cmake_args=-DCMAKE_BUILD_TYPE=RelWithDebugInfo
|
||||
if test ${debug_release} = debug; then
|
||||
cmake_args="-DCMAKE_BUILD_TYPE=Debug"
|
||||
fi
|
||||
if test x${have_zchunk} = xno; then
|
||||
cmake_args="${cmake_args} -DWITH_ZCHUNK:BOOL=0"
|
||||
fi
|
||||
export cmake_args
|
||||
|
||||
dnl I picked /usr/libexec/rpm-ostree just because we need an
|
||||
dnl arbitrary path - we don't actually install there.
|
||||
dnl Use `WITH_GIR=0`; it's our private libdnf bundle and we don't need the bindings.
|
||||
dnl -fPIE for hardening
|
||||
(set -euo pipefail; mkdir -p libdnf-build && cd libdnf-build &&
|
||||
set -x &&
|
||||
export CXXFLAGS="-fPIE $CXXFLAGS" &&
|
||||
cmake \
|
||||
-DCMAKE_INSTALL_PREFIX:PATH=/usr/libexec/rpm-ostree \
|
||||
-DINCLUDE_INSTALL_DIR:PATH=/usr/libexec/rpm-ostree/include \
|
||||
-DLIB_INSTALL_DIR:PATH=/usr/libexec/rpm-ostree \
|
||||
-DSYSCONF_INSTALL_DIR:PATH=/usr/libexec/rpm-ostree/etc \
|
||||
-DSHARE_INSTALL_PREFIX:PATH=/usr/libexec/rpm-ostree/share \
|
||||
-DENABLE_STATIC:BOOL=1 \
|
||||
-DCMAKE_POSITION_INDEPENDENT_CODE=ON \
|
||||
-DWITH_SWDB:BOOL=0 \
|
||||
-DWITH_BINDINGS:BOOL=0 \
|
||||
-DWITH_HTML:BOOL=0 \
|
||||
-DWITH_MAN:BOOL=0 \
|
||||
-DWITH_GIR:BOOL=0 \
|
||||
${cmake_args} ../libdnf) || exit 1
|
||||
|
||||
AC_CONFIG_FILES([
|
||||
Makefile
|
||||
api-doc/Makefile
|
||||
|
@ -3,6 +3,7 @@ name = "libdnf-sys"
|
||||
version = "0.1.0"
|
||||
authors = ["Colin Walters <walters@verbum.org>", "Jonathan Lebon <jonathan@jlebon.com>"]
|
||||
edition = "2018"
|
||||
links = "dnf"
|
||||
|
||||
[dependencies]
|
||||
libc = "0.2"
|
||||
@ -12,6 +13,7 @@ name = "libdnf_sys"
|
||||
path = "lib.rs"
|
||||
|
||||
[build-dependencies]
|
||||
cmake = "0.1.45"
|
||||
system-deps = "2.0"
|
||||
anyhow = "1.0"
|
||||
|
||||
|
@ -2,5 +2,36 @@ use anyhow::Result;
|
||||
|
||||
fn main() -> Result<()> {
|
||||
system_deps::Config::new().probe()?;
|
||||
use cmake::Config;
|
||||
let libdnf = Config::new("../../libdnf")
|
||||
// Needed for hardened builds
|
||||
.cxxflag("-fPIC")
|
||||
// I picked /usr/libexec/rpm-ostree just because we need an
|
||||
// arbitrary path - we don't actually install there.
|
||||
.define("CMAKE_INSTALL_PREFIX:PATH", "/usr/libexec/rpm-ostree")
|
||||
.define(
|
||||
"INCLUDE_INSTALL_DIR:PATH",
|
||||
"/usr/libexec/rpm-ostree/include",
|
||||
)
|
||||
.define("LIB_INSTALL_DIR:PATH", "/usr/libexec/rpm-ostree")
|
||||
.define("SYSCONF_INSTALL_DIR:PATH", "/usr/libexec/rpm-ostree/etc")
|
||||
.define("SHARE_INSTALL_PREFIX:PATH", "/usr/libexec/rpm-ostree/share")
|
||||
.define("ENABLE_STATIC:BOOL", "1")
|
||||
.define("CMAKE_POSITION_INDEPENDENT_CODE", "ON")
|
||||
// rpm-ostree maintains its own state
|
||||
.define("WITH_SWDB:BOOL", "0")
|
||||
// We don't need docs
|
||||
.define("WITH_HTML:BOOL", "0")
|
||||
.define("WITH_MAN:BOOL", "0")
|
||||
// Don't need bindings
|
||||
.define("WITH_BINDINGS:BOOL", "0")
|
||||
.define("WITH_GIR:BOOL", "0")
|
||||
.build_target("all")
|
||||
.build();
|
||||
println!(
|
||||
"cargo:rustc-link-search=native={}/build/libdnf",
|
||||
libdnf.display()
|
||||
);
|
||||
println!("cargo:rustc-link-lib=static=dnf");
|
||||
Ok(())
|
||||
}
|
||||
|
7
src/libpriv/libdnf/dnf-version.h
Normal file
7
src/libpriv/libdnf/dnf-version.h
Normal file
@ -0,0 +1,7 @@
|
||||
// This is an awful hack necessary because this header file
|
||||
// is generated in the libdnf build, but we don't want to serialize
|
||||
// our C++ build waiting for that. Since we don't define the macros
|
||||
// like LIBDNF_MAJOR_VERSION, if anything depends on them it will
|
||||
// fail at build time.
|
||||
#pragma once
|
||||
|
Loading…
Reference in New Issue
Block a user