From 61184163ea5cb5f1652dd4e9eb8de151a58d9c45 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Thu, 18 Mar 2021 21:54:52 +0000 Subject: [PATCH 1/2] Drop minimal rust/ library This was my first experiment with using Rust in this way; I gained a lot of knowledge from it. But, we don't really gain anything from the code as it is today - while it is "bit fiddling" code, the C code is well tested. We have a lot of compile-time options, and trimming them will be helpful. We've also gotten pushback on hard requiring Rust client side. Instead, what I'd like to do is hopefully soon create an `ostree-system` crate that uses the existing `ostree` library and can contain code drained from the rpm-ostree Rust and used by other projects perhaps. So the goal here is really more Rust, but we need to focus our efforts on where it's most valuable. --- .cci.jenkinsfile | 5 -- Makefile-libostree.am | 12 ---- Makefile.am | 24 ------- configure.ac | 34 ---------- rust/.gitignore | 2 - rust/Cargo.toml | 16 ----- rust/cargo-vendor-config | 8 --- rust/src/bupsplit.rs | 137 --------------------------------------- 8 files changed, 238 deletions(-) delete mode 100644 rust/.gitignore delete mode 100644 rust/Cargo.toml delete mode 100644 rust/cargo-vendor-config delete mode 100644 rust/src/bupsplit.rs diff --git a/.cci.jenkinsfile b/.cci.jenkinsfile index ac65b9c8..6a51594a 100644 --- a/.cci.jenkinsfile +++ b/.cci.jenkinsfile @@ -107,11 +107,6 @@ buildopts: { shwrap(""" git submodule update --init - git worktree add build-rust && cd build-rust - env MAKE_JOBS=${n} CONFIGOPTS="--enable-rust" SKIP_INSTALLDEPS=1 ./ci/build.sh - make check TESTS=tests/test-rollsum - cd .. && rm -rf build-rust - git worktree add build-libsoup && cd build-libsoup env MAKE_JOBS=${n} CONFIGOPTS="--without-curl --without-openssl --with-soup" SKIP_INSTALLDEPS=1 ./ci/build.sh make check diff --git a/Makefile-libostree.am b/Makefile-libostree.am index 98fbb289..6dbd00f5 100644 --- a/Makefile-libostree.am +++ b/Makefile-libostree.am @@ -21,18 +21,9 @@ include Makefile-libostree-defines.am - -if ENABLE_RUST -bupsplitpath = @abs_top_builddir@/target/@RUST_TARGET_SUBDIR@/libbupsplit_rs.a -BUPSPLIT_RUST_SRCS = rust/src/bupsplit.rs -EXTRA_DIST += $(BUPSPLIT_RUST_SRCS) -$(bupsplitpath): Makefile $(BUPSPLIT_RUST_SRCS) - cd $(top_srcdir)/rust && CARGO_TARGET_DIR=@abs_top_builddir@/target cargo build --verbose $(CARGO_RELEASE_ARGS) -else bupsplitpath = libbupsplit.la noinst_LTLIBRARIES += libbupsplit.la libbupsplit_la_SOURCES = src/libostree/bupsplit.h src/libostree/bupsplit.c -endif # ENABLE_RUST lib_LTLIBRARIES += libostree-1.la @@ -206,9 +197,6 @@ libostree_1_la_LDFLAGS = -version-number 1:0:0 -Bsymbolic-functions $(addprefix libostree_1_la_LIBADD = libotutil.la libglnx.la libbsdiff.la $(OT_INTERNAL_GIO_UNIX_LIBS) $(OT_INTERNAL_GPGME_LIBS) \ $(OT_DEP_LZMA_LIBS) $(OT_DEP_ZLIB_LIBS) $(OT_DEP_CRYPTO_LIBS) # Some change between rust-1.21.0-1.fc27 and rust-1.22.1-1.fc27.x86_64 -if ENABLE_RUST -libostree_1_la_LIBADD += -ldl -endif libostree_1_la_LIBADD += $(bupsplitpath) EXTRA_libostree_1_la_DEPENDENCIES = $(symbol_files) diff --git a/Makefile.am b/Makefile.am index 87a705cc..b2588ad7 100644 --- a/Makefile.am +++ b/Makefile.am @@ -71,30 +71,6 @@ GIRS = TYPELIBS = $(GIRS:.gir=.typelib) endif -# These bits based on gnome:librsvg/Makefile.am -if ENABLE_RUST -if RUST_DEBUG -CARGO_RELEASE_ARGS= -else -CARGO_RELEASE_ARGS=--release -endif - -check-local: - cd $(srcdir)/rust && CARGO_TARGET_DIR=$(abs_top_builddir)/target cargo test - -clean-local: - cd $(srcdir)/rust && CARGO_TARGET_DIR=$(abs_top_builddir)/target cargo clean - -dist-hook: - (cd $(distdir)/rust && \ - cp $(abs_top_srcdir)/rust/Cargo.lock . && \ - cargo vendor -q && \ - mkdir .cargo && \ - cp cargo-vendor-config .cargo/config) - -EXTRA_DIST += $(srcdir)/rust/Cargo.toml $(srcdir)/rust/cargo-vendor-config -endif # end ENABLE_RUST - libglnx_srcpath := $(srcdir)/libglnx libglnx_cflags := $(OT_DEP_GIO_UNIX_CFLAGS) "-I$(libglnx_srcpath)" libglnx_libs := $(OT_DEP_GIO_UNIX_LIBS) diff --git a/configure.ac b/configure.ac index 3a982f53..f7448a45 100644 --- a/configure.ac +++ b/configure.ac @@ -287,39 +287,6 @@ AS_IF([test "$enable_man" != no], [ ]) AM_CONDITIONAL(ENABLE_MAN, test "$enable_man" != no) -AC_ARG_ENABLE(rust, - [AS_HELP_STRING([--enable-rust], - [Compile Rust code instead of C [default=no]])],, - [enable_rust=no; rust_debug_release=no]) - -AS_IF([test "$enable_rust" = yes], [ - AC_PATH_PROG([cargo], [cargo]) - 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 These bits based on gnome:librsvg/configure.ac - - dnl By default, we build in public release mode. - AC_ARG_ENABLE(rust-debug, - AC_HELP_STRING([--enable-rust-debug], - [Build Rust code with debugging information [default=no]]), - [rust_debug_release=$enableval], - [rust_debug_release=release]) - - AC_MSG_CHECKING(whether to build Rust code with debugging information) - if test "x$rust_debug_release" = "xyes" ; then - rust_debug_release=debug - AC_MSG_RESULT(yes) - else - AC_MSG_RESULT(no) - fi - RUST_TARGET_SUBDIR=${rust_debug_release} - AC_SUBST([RUST_TARGET_SUBDIR]) -]) -AM_CONDITIONAL(RUST_DEBUG, [test "x$rust_debug_release" = "xdebug"]) -AM_CONDITIONAL(ENABLE_RUST, [test "$enable_rust" != no]) - AC_ARG_WITH(libarchive, AS_HELP_STRING([--without-libarchive], [Do not use libarchive]), :, with_libarchive=maybe) @@ -628,7 +595,6 @@ echo " introspection: $found_introspection - Rust (internal oxidation): $rust_debug_release rofiles-fuse: $enable_rofiles_fuse HTTP backend: $fetcher_backend \"ostree trivial-httpd\": $enable_trivial_httpd_cmdline diff --git a/rust/.gitignore b/rust/.gitignore deleted file mode 100644 index 1e7caa9e..00000000 --- a/rust/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -Cargo.lock -target/ diff --git a/rust/Cargo.toml b/rust/Cargo.toml deleted file mode 100644 index 4da5ac32..00000000 --- a/rust/Cargo.toml +++ /dev/null @@ -1,16 +0,0 @@ -[package] -name = "bupsplit" -version = "0.0.1" -authors = ["Colin Walters "] - -[dependencies] -libc = "0.2" - -[lib] -name = "bupsplit_rs" -path = "src/bupsplit.rs" -crate-type = ["staticlib"] - -[profile.release] -panic = "abort" -lto = true diff --git a/rust/cargo-vendor-config b/rust/cargo-vendor-config deleted file mode 100644 index 5407266e..00000000 --- a/rust/cargo-vendor-config +++ /dev/null @@ -1,8 +0,0 @@ -# This is used after `cargo vendor` is run from `make dist` - -[source.crates-io] -registry = 'https://github.com/rust-lang/crates.io-index' -replace-with = 'vendored-sources' - -[source.vendored-sources] -directory = './vendor' diff --git a/rust/src/bupsplit.rs b/rust/src/bupsplit.rs deleted file mode 100644 index 73dc9ee1..00000000 --- a/rust/src/bupsplit.rs +++ /dev/null @@ -1,137 +0,0 @@ -/* - * Copyright 2017 Colin Walters - * Based on original bupsplit.c: - * Copyright 2011 Avery Pennarun. All rights reserved. - * - * (This license applies to bupsplit.c and bupsplit.h only.) - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * THIS SOFTWARE IS PROVIDED BY AVERY PENNARUN ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -extern crate libc; - -use std::slice; - -// According to librsync/rollsum.h: -// "We should make this something other than zero to improve the -// checksum algorithm: tridge suggests a prime number." -// apenwarr: I unscientifically tried 0 and 7919, and they both ended up -// slightly worse than the librsync value of 31 for my arbitrary test data. -const ROLLSUM_CHAR_OFFSET: u32 = 31; - -// Previously in the header file -const BUP_BLOBBITS: u32 = 13; -const BUP_BLOBSIZE: u32 = 1 << BUP_BLOBBITS; -const BUP_WINDOWBITS: u32 = 7; -const BUP_WINDOWSIZE: u32 = 1 << BUP_WINDOWBITS - 1; - -struct Rollsum { - s1: u32, - s2: u32, - window: [u8; BUP_WINDOWSIZE as usize], - wofs: i32, -} - -impl Rollsum { - pub fn new() -> Rollsum { - Rollsum { - s1: BUP_WINDOWSIZE * ROLLSUM_CHAR_OFFSET, - s2: BUP_WINDOWSIZE * (BUP_WINDOWSIZE - 1) * ROLLSUM_CHAR_OFFSET, - window: [0; 64], - wofs: 0, - } - } - - // These formulas are based on rollsum.h in the librsync project. - pub fn add(&mut self, drop: u8, add: u8) -> () { - let drop_expanded = u32::from(drop); - let add_expanded = u32::from(add); - self.s1 = self - .s1 - .wrapping_add(add_expanded.wrapping_sub(drop_expanded)); - self.s2 = self.s2.wrapping_add( - self.s1 - .wrapping_sub(BUP_WINDOWSIZE * (drop_expanded + ROLLSUM_CHAR_OFFSET)), - ); - } - - pub fn roll(&mut self, ch: u8) -> () { - let wofs = self.wofs as usize; - let dval = self.window[wofs]; - self.add(dval, ch); - self.window[wofs] = ch; - self.wofs = (self.wofs + 1) % (BUP_WINDOWSIZE as i32); - } - - pub fn digest(&self) -> u32 { - (self.s1 << 16) | (self.s2 & 0xFFFF) - } -} - -#[no_mangle] -pub extern "C" fn bupsplit_sum(buf: *const u8, ofs: libc::size_t, len: libc::size_t) -> u32 { - let sbuf = unsafe { - assert!(!buf.is_null()); - slice::from_raw_parts(buf.offset(ofs as isize), (len - ofs) as usize) - }; - - let mut r = Rollsum::new(); - for x in sbuf { - r.roll(*x); - } - r.digest() -} - -#[no_mangle] -pub extern "C" fn bupsplit_find_ofs( - buf: *const u8, - len: libc::size_t, - bits: *mut libc::c_int, -) -> libc::c_int { - if buf.is_null() { - return 0; - } - - let sbuf = unsafe { slice::from_raw_parts(buf, len as usize) }; - let mut r = Rollsum::new(); - for x in sbuf { - r.roll(*x); - if (r.s2 & (BUP_BLOBSIZE - 1)) == ((u32::max_value()) & (BUP_BLOBSIZE - 1)) { - if !bits.is_null() { - let mut sum = r.digest() >> BUP_BLOBBITS; - let mut rbits: libc::c_int = BUP_BLOBBITS as i32; - while sum & 1 != 0 { - sum >>= 1; - rbits += 1; - } - unsafe { - *bits = rbits; - } - } - return len as i32; - } - } - 0 -} From b69a4180b838a5646ef93cb7ef19398f50b1a0cf Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Fri, 19 Mar 2021 21:45:54 +0000 Subject: [PATCH 2/2] tests/inst: Patch to use my PR for openat Fixes the build. --- tests/inst/Cargo.toml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/inst/Cargo.toml b/tests/inst/Cargo.toml index 0986c0a7..3301616d 100644 --- a/tests/inst/Cargo.toml +++ b/tests/inst/Cargo.toml @@ -46,3 +46,7 @@ with-procspawn-tempdir = { git = "https://github.com/cgwalters/with-procspawn-te # Internal crate for the test macro itest-macro = { path = "itest-macro" } + +[patch.crates-io] +# PR openat (pun intended) https://github.com/tailhook/openat/pull/36 +openat = { git = 'https://github.com/cgwalters/openat', branch = 'libc-rename-signed' }