Trying a little C from Rust and while at it might as well trying building an rpm.
make
This should build the rust package in release mode, and also use cbindgen to genereate a c header file in the include
folder.
This basically just runs the following commands: Mac:
cargo build --release
mkdir -p include
cbindgen --config cbindgen.toml --crate chedrpack --output include/chedrpack.h
On linux (tried with almalinux):
mkdir -p $(SOURCE_DIR)
tar czvf $(SOURCE_DIR)/$(TAR_NAME) --exclude=target --exclude=.git --transform 's,^,chedrpack-$(VERSION)/,' *
rpmbuild --define "_topdir /build/build/rpmbuild" -bb packaging/package.spec
Simply run:
make install
Which runs the below commands to install: Mac:
install -m 755 target/release/$(LIB_NAME) $(LIB_DIR)/$(LIB_NAME)
install -m 644 include/$(HEADER_NAME) $(INCLUDE_DIR)/$(HEADER_NAME)
where the variables are:
LIB_NAME = libchedrpack.a
HEADER_NAME = chedrpack.h
LIB_DIR = /usr/local/lib
INCLUDE_DIR = /usr/local/include
Linux: make install runs the following:
yum -y localinstall build/rpmbuild/RPMS/aarch64/chedrpack-0.1.0-1.el9.aarch64.rpm
make uninstall
Runs the following commands: Mac:
rm -f $(LIB_DIR)/$(LIB_NAME)
rm -f $(INCLUDE_DIR)/$(HEADER_NAME)
Linux:
yum -y remove chedrpack
make test
Runs:
gcc -o tests/test_add tests/test_add.c -l chedrpack && tests/test_add && rm tests/test_add
make clean
Cleans the cargo and rpm build directories.