move Rust sources to top level, C sources into c_src

This moves the Rust sources out of rust_src/ and into the top level.
Running the bcachefs executable out of the development tree is now:

$ ./target/release/bcachefs command
or
$ cargo run --profile release -- command

instead of "./bcachefs command".

Building and installing is still:

$ make && make install

Signed-off-by: Thomas Bertschinger <tahbertschinger@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
Thomas Bertschinger 2024-01-15 23:41:02 -07:00 committed by Kent Overstreet
parent fb35dbfdc5
commit f5baaf48e3
470 changed files with 52 additions and 121 deletions

View File

@ -78,7 +78,7 @@ jobs:
uuid-dev zlib1g-dev valgrind libudev-dev python3-docutils libclang-dev uuid-dev zlib1g-dev valgrind libudev-dev python3-docutils libclang-dev
- name: Extract MSRV - name: Extract MSRV
run: | run: |
MSRV=$(cargo metadata --format-version 1 --no-deps --manifest-path rust-src/Cargo.toml | MSRV=$(cargo metadata --format-version 1 --no-deps |
jq -r '.packages[] | select(.name == "bcachefs-tools") | .rust_version') jq -r '.packages[] | select(.name == "bcachefs-tools") | .rust_version')
echo "MSRV=$MSRV" >> $GITHUB_ENV echo "MSRV=$MSRV" >> $GITHUB_ENV
- name: Install Rust ${{ env.MSRV }} toolchain - name: Install Rust ${{ env.MSRV }} toolchain

10
.gitignore vendored
View File

@ -20,3 +20,13 @@ tests/__pycache__/
!.editorconfig !.editorconfig
bcachefs-principles-of-operation.* bcachefs-principles-of-operation.*
# will have compiled files and executables
debug/
target/
# These are backup files generated by rustfmt
**/*.rs.bk
# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb

View File

View File

@ -30,7 +30,7 @@ CFLAGS+=-std=gnu11 -O2 -g -MMD -Wall -fPIC \
-Wno-deprecated-declarations \ -Wno-deprecated-declarations \
-fno-strict-aliasing \ -fno-strict-aliasing \
-fno-delete-null-pointer-checks \ -fno-delete-null-pointer-checks \
-I. -Iinclude -Iraid \ -Ic_src -Ic_src/include \
-D_FILE_OFFSET_BITS=64 \ -D_FILE_OFFSET_BITS=64 \
-D_GNU_SOURCE \ -D_GNU_SOURCE \
-D_LGPL_SOURCE \ -D_LGPL_SOURCE \
@ -55,12 +55,11 @@ CARGO_ARGS=${CARGO_TOOLCHAIN}
CARGO=cargo $(CARGO_ARGS) CARGO=cargo $(CARGO_ARGS)
CARGO_PROFILE=release CARGO_PROFILE=release
# CARGO_PROFILE=debug # CARGO_PROFILE=debug
CARGO_MANIFEST=--manifest-path rust-src/Cargo.toml
CARGO_BUILD_ARGS=--$(CARGO_PROFILE) CARGO_BUILD_ARGS=--$(CARGO_PROFILE)
CARGO_BUILD=$(CARGO) build $(CARGO_BUILD_ARGS) $(CARGO_MANIFEST) CARGO_BUILD=$(CARGO) build $(CARGO_BUILD_ARGS)
CARGO_CLEAN=$(CARGO) clean $(CARGO_CLEAN_ARGS) $(CARGO_MANIFEST) CARGO_CLEAN=$(CARGO) clean $(CARGO_CLEAN_ARGS)
include Makefile.compiler include Makefile.compiler
@ -172,13 +171,13 @@ OBJS:=$(SRCS:.c=.o)
@echo " [CC] $@" @echo " [CC] $@"
$(Q)$(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $< $(Q)$(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $<
BCACHEFS_DEPS=libbcachefs.a BCACHEFS_DEPS=c_src/libbcachefs.a
RUST_SRCS:=$(shell find rust-src/src rust-src/bch_bindgen/src -type f -iname '*.rs') RUST_SRCS:=$(shell find src bch_bindgen/src -type f -iname '*.rs')
bcachefs: $(BCACHEFS_DEPS) $(RUST_SRCS) bcachefs: $(BCACHEFS_DEPS) $(RUST_SRCS)
$(CARGO_BUILD) $(Q)$(CARGO_BUILD)
libbcachefs.a: $(filter-out ./tests/%.o, $(OBJS)) c_src/libbcachefs.a: $(filter-out ./tests/%.o, $(OBJS))
@echo " [AR] $@" @echo " [AR] $@"
$(Q)ar -rc $@ $+ $(Q)ar -rc $@ $+
@ -201,7 +200,7 @@ cmd_version.o : .version
install: INITRAMFS_HOOK=$(INITRAMFS_DIR)/hooks/bcachefs install: INITRAMFS_HOOK=$(INITRAMFS_DIR)/hooks/bcachefs
install: INITRAMFS_SCRIPT=$(INITRAMFS_DIR)/scripts/local-premount/bcachefs install: INITRAMFS_SCRIPT=$(INITRAMFS_DIR)/scripts/local-premount/bcachefs
install: bcachefs $(optional_install) install: bcachefs $(optional_install)
$(INSTALL) -m0755 -D rust-src/target/release/bcachefs -t $(DESTDIR)$(ROOT_SBINDIR) $(INSTALL) -m0755 -D target/release/bcachefs -t $(DESTDIR)$(ROOT_SBINDIR)
$(INSTALL) -m0644 -D bcachefs.8 -t $(DESTDIR)$(PREFIX)/share/man/man8/ $(INSTALL) -m0644 -D bcachefs.8 -t $(DESTDIR)$(PREFIX)/share/man/man8/
$(INSTALL) -m0755 -D initramfs/script $(DESTDIR)$(INITRAMFS_SCRIPT) $(INSTALL) -m0755 -D initramfs/script $(DESTDIR)$(INITRAMFS_SCRIPT)
$(INSTALL) -m0755 -D initramfs/hook $(DESTDIR)$(INITRAMFS_HOOK) $(INSTALL) -m0755 -D initramfs/hook $(DESTDIR)$(INITRAMFS_HOOK)
@ -224,7 +223,7 @@ install_systemd: $(systemd_services) $(systemd_libexecfiles)
.PHONY: clean .PHONY: clean
clean: clean:
@echo "Cleaning all" @echo "Cleaning all"
$(Q)$(RM) libbcachefs.a tests/test_helper .version *.tar.xz $(OBJS) $(DEPS) $(DOCGENERATED) $(Q)$(RM) c_src/libbcachefs.a tests/test_helper .version *.tar.xz $(OBJS) $(DEPS) $(DOCGENERATED)
$(Q)$(CARGO_CLEAN) $(Q)$(CARGO_CLEAN)
$(Q)$(RM) -f $(built_scripts) $(Q)$(RM) -f $(built_scripts)
@ -244,8 +243,8 @@ doc: bcachefs-principles-of-operation.pdf
.PHONY: cargo-update-msrv .PHONY: cargo-update-msrv
cargo-update-msrv: cargo-update-msrv:
cargo +nightly generate-lockfile --manifest-path rust-src/Cargo.toml -Zmsrv-policy cargo +nightly generate-lockfile -Zmsrv-policy
cargo +nightly generate-lockfile --manifest-path rust-src/bch_bindgen/Cargo.toml -Zmsrv-policy cargo +nightly generate-lockfile --manifest-path bch_bindgen/Cargo.toml -Zmsrv-policy
.PHONY: update-bcachefs-sources .PHONY: update-bcachefs-sources
update-bcachefs-sources: update-bcachefs-sources:

View File

@ -19,9 +19,8 @@ fn main() {
.expect("ENV Var 'CARGO_MANIFEST_DIR' Expected") .expect("ENV Var 'CARGO_MANIFEST_DIR' Expected")
.into(); .into();
let libbcachefs_inc_dir = std::path::Path::new("../.."); let libbcachefs_inc_dir = std::path::Path::new("../c_src");
let _libbcachefs_dir = top_dir.join("libbcachefs").join("libbcachefs");
let bindings = bindgen::builder() let bindings = bindgen::builder()
.header( .header(
top_dir top_dir

View File

@ -0,0 +1,22 @@
#include "libbcachefs/super-io.h"
#include "libbcachefs/checksum.h"
#include "libbcachefs/bcachefs_format.h"
#include "libbcachefs/btree_cache.h"
#include "libbcachefs/btree_iter.h"
#include "libbcachefs/debug.h"
#include "libbcachefs/errcode.h"
#include "libbcachefs/error.h"
#include "libbcachefs/opts.h"
#include "libbcachefs.h"
#include "crypto.h"
#include "include/linux/bio.h"
#include "include/linux/blkdev.h"
#include "cmds.h"
#include "raid/raid.h"
#define MARK_FIX_753(req_name) const blk_mode_t Fix753_##req_name = req_name;
MARK_FIX_753(BLK_OPEN_READ);
MARK_FIX_753(BLK_OPEN_WRITE);
MARK_FIX_753(BLK_OPEN_EXCL);

View File

@ -35,12 +35,12 @@ in stdenv.mkDerivation {
BCACHEFS_FUSE = if fuseSupport then "1" else ""; BCACHEFS_FUSE = if fuseSupport then "1" else "";
cargoRoot = "rust-src"; cargoRoot = ".";
# when git-based crates are updated, run: # when git-based crates are updated, run:
# nix run github:Mic92/nix-update -- --version=skip --flake default # nix run github:Mic92/nix-update -- --version=skip --flake default
# to update the hashes # to update the hashes
cargoDeps = rustPlatform.importCargoLock { cargoDeps = rustPlatform.importCargoLock {
lockFile = "${src}/rust-src/Cargo.lock"; lockFile = "${src}/Cargo.lock";
outputHashes = { outputHashes = {
"bindgen-0.64.0" = "sha256-GNG8as33HLRYJGYe0nw6qBzq86aHiGonyynEM7gaEE4="; "bindgen-0.64.0" = "sha256-GNG8as33HLRYJGYe0nw6qBzq86aHiGonyynEM7gaEE4=";
}; };

View File

@ -1,6 +1,6 @@
fn main() { fn main() {
println!("cargo:rustc-link-search=.."); println!("cargo:rustc-link-search=c_src");
println!("cargo:rerun-if-changed=../libbcachefs.a"); println!("cargo:rerun-if-changed=c_src/libbcachefs.a");
println!("cargo:rustc-link-lib=static:+whole-archive=bcachefs"); println!("cargo:rustc-link-lib=static:+whole-archive=bcachefs");
println!("cargo:rustc-link-lib=urcu"); println!("cargo:rustc-link-lib=urcu");

Some files were not shown because too many files have changed in this diff Show More