Simplify recipes
parent
b1123a6de9
commit
e9369a40ef
@ -1,168 +1,142 @@
|
|||||||
|
# set ROOT_DIR as our test suite uses it
|
||||||
export ROOT_DIR:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
|
export ROOT_DIR:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
|
||||||
ADDITIONAL_SOFTWARE=
|
# no additional software note
|
||||||
# (DEF) Either prepare --target triple-x-y OR have an empty value
|
NO_ADDITIONAL_SOFTWARE := echo "No additional software required for this target"
|
||||||
TARGET_ARG =
|
# target argument
|
||||||
|
TARGET_ARG :=
|
||||||
|
# target folder path
|
||||||
|
TARGET_FOLDER := target/
|
||||||
|
# additional software installation
|
||||||
|
ADDITIONAL_SOFTWARE :=
|
||||||
|
# update variables depending on target
|
||||||
ifneq ($(origin TARGET),undefined)
|
ifneq ($(origin TARGET),undefined)
|
||||||
TARGET_ARG +=--target ${TARGET}
|
ifeq ($(TARGET),x86_64-unknown-linux-musl)
|
||||||
ifeq ($(TARGET),x86_64-unknown-linux-musl)
|
# for MUSL builds, we need to install musl-tools
|
||||||
# we need musl-tools for 64-bit musl targets
|
ADDITIONAL_SOFTWARE += sudo apt-get update && sudo apt install musl-tools -y
|
||||||
ADDITIONAL_SOFTWARE += sudo apt-get update && sudo apt install musl-tools -y
|
else ifeq ($(TARGET),i686-unknown-linux-gnu)
|
||||||
endif
|
# for 32-bit we need multilib
|
||||||
ifeq ($(TARGET),i686-unknown-linux-gnu)
|
ADDITIONAL_SOFTWARE += sudo apt-get update && sudo apt install gcc-multilib -y
|
||||||
# we need gcc-multilib on 32-bit linux targets
|
else
|
||||||
ADDITIONAL_SOFTWARE += sudo apt-get update && sudo apt install gcc-multilib -y
|
ADDITIONAL_SOFTWARE += ${NO_ADDITIONAL_SOFTWARE}
|
||||||
endif
|
endif
|
||||||
endif
|
TARGET_ARG += --target ${TARGET}
|
||||||
|
TARGET_FOLDER := $(addsuffix ${TARGET}/,${TARGET_FOLDER})
|
||||||
# (DEF) display a message if no additional packages are required for this target
|
else
|
||||||
ifeq ($(ADDITIONAL_SOFTWARE),)
|
ADDITIONAL_SOFTWARE += ${NO_ADDITIONAL_SOFTWARE}
|
||||||
ADDITIONAL_SOFTWARE += echo "info: No additional software required for this target"
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
BUILD_VERBOSE = cargo build --verbose $(TARGET_ARG)
|
TARGET_FOLDER := $(addsuffix release/,${TARGET_FOLDER})
|
||||||
|
# cargo build
|
||||||
|
CBUILD := cargo build $(TARGET_ARG)
|
||||||
|
# cargo test
|
||||||
|
CTEST := cargo test $(TARGET_ARG)
|
||||||
|
|
||||||
# (DEF) Create empty commands
|
# binary file paths
|
||||||
STOP_SERVER =
|
BINARY_SKYSH := $(TARGET_FOLDER)skysh
|
||||||
BUILD_COMMAND =
|
BINARY_SKYD := $(TARGET_FOLDER)skyd
|
||||||
BUILD_SERVER_COMMAND =
|
BINARY_SKYBENCH := $(TARGET_FOLDER)sky-bench
|
||||||
TEST_COMMAND =
|
BINARY_SKYMIGRATE := $(TARGET_FOLDER)sky-migrate
|
||||||
RELEASE_COMMAND =
|
# archive command
|
||||||
START_COMMAND =
|
ARCHIVE :=
|
||||||
|
# start background server command
|
||||||
|
START_SERVER := cargo run $(TARGET_ARG) -p skyd -- --noart --sslchain cert.pem --sslkey key.pem
|
||||||
|
STOP_SERVER :=
|
||||||
|
|
||||||
# (DEF) Add cmd /c for windows due to OpenSSL issues or just add cargo run for non-windows
|
|
||||||
ifeq ($(OS),Windows_NT)
|
ifeq ($(OS),Windows_NT)
|
||||||
# export windows specifc rustflags
|
# on windows, so we need exe
|
||||||
export RUSTFLAGS = -Ctarget-feature=+crt-static
|
ARCHIVE += 7z a ourbundle.zip $(BINARY_SKYSH).exe $(BINARY_SKYD).exe $(BINARY_SKYBENCH).exe $(BINARY_SKYMIGRATE).exe
|
||||||
# add command to use cmd because OpenSSL can't build on Windows bash
|
# also add RUSTFLAGS
|
||||||
BUILD_COMMAND += cmd /C set RUSTFLAGS = -Ctarget-feature=+crt-static
|
export RUSTFLAGS = -Ctarget-feature=+crt-static
|
||||||
# same thing here
|
# now add start command
|
||||||
BUILD_SERVER_COMMAND += cmd /C
|
START_SERVER := cmd /C START /B $(START_SERVER)
|
||||||
TEST_COMMAND += cmd /C
|
# windows is funky with OpenSSL, so add these
|
||||||
STOP_SERVER += taskkill.exe /F /IM skyd.exe
|
CBUILD := cmd /C $(CBUILD)
|
||||||
RELEASE_COMMAND += cmd /C
|
CTEST := cmd /C $(CTEST)
|
||||||
START_COMMAND += cmd /C START /B
|
# finally add stop command
|
||||||
|
STOP_SERVER := taskkill.exe /F /IM skyd.exe
|
||||||
else
|
else
|
||||||
STOP_SERVER += pkill skyd
|
# not windows, so archive is easy
|
||||||
# make sure to set executable permissions
|
ARCHIVE += zip -j ourbundle.zip $(BINARY_SKYSH) $(BINARY_SKYD) $(BINARY_SKYBENCH) $(BINARY_SKYMIGRATE)
|
||||||
|
# now add start command
|
||||||
|
START_SERVER := $(START_SERVER) &
|
||||||
|
# add stop command
|
||||||
|
STOP_SERVER := pkill skyd
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# (DEF) Assemble the commands
|
# update the archive command if we have a version and artifact name
|
||||||
BUILD_SERVER_COMMAND += $(BUILD_VERBOSE)
|
RENAME_ARTIFACT :=
|
||||||
BUILD_SERVER_COMMAND += -p skyd
|
ifneq ($(origin ARTIFACT),undefined)
|
||||||
RELEASE_SERVER_COMMAND =
|
# so we have an artifact name
|
||||||
RELEASE_SERVER_COMMAND += $(BUILD_SERVER_COMMAND)
|
ifneq ($(origin VERSION),undefined)
|
||||||
RELEASE_SERVER_COMMAND += --release
|
# we also have the version name
|
||||||
RELEASE_COMMAND += cargo build --release $(TARGET_ARG)
|
RENAME_ARTIFACT := sky-bundle-${VERSION}-${ARTIFACT}.zip
|
||||||
BUILD_COMMAND += $(BUILD_VERBOSE)
|
else
|
||||||
TEST_COMMAND += cargo test $(TARGET_ARG)
|
# no version name
|
||||||
START_COMMAND += cargo run $(TARGET_ARG) -p skyd
|
RENAME_ARTIFACT := sky-bundle-${ARTIFACT}.zip
|
||||||
START_COMMAND_RELEASE =
|
endif
|
||||||
START_COMMAND_RELEASE += ${START_COMMAND}
|
|
||||||
START_COMMAND_RELEASE += --release
|
|
||||||
START_COMMAND += -- --noart --nosave
|
|
||||||
START_COMMAND += --sslchain cert.pem --sslkey key.pem
|
|
||||||
START_COMMAND_RELEASE += -- --noart --nosave
|
|
||||||
ifneq ($(OS),Windows_NT)
|
|
||||||
START_COMMAND += &
|
|
||||||
START_COMMAND_RELEASE += &
|
|
||||||
endif
|
|
||||||
# (DEF) Prepare release bundle commands
|
|
||||||
BUNDLE=
|
|
||||||
ifeq ($(origin TARGET),undefined)
|
|
||||||
# no target defined. but check for windows
|
|
||||||
ifeq ($(OS),Windows_NT)
|
|
||||||
# windows, so we need exe
|
|
||||||
BUNDLE += cd target/release &&
|
|
||||||
BUNDLE += 7z a ../../../bundle.zip skysh.exe skyd.exe sky-bench.exe sky-migrate.exe
|
|
||||||
else
|
|
||||||
# not windows, so no exe
|
|
||||||
BUNDLE+=zip -j bundle.zip target/release/skysh target/release/skyd target/release/sky-bench target/release/sky-migrate
|
|
||||||
endif
|
|
||||||
else
|
else
|
||||||
# target was defined, but check for windows
|
# no artifact (hack)
|
||||||
ifeq ($(OS),Windows_NT)
|
RENAME_ARTIFACT := bundle.zip
|
||||||
# windows, so we need exe
|
|
||||||
BUNDLE += cd target/${TARGET}/release &&
|
|
||||||
BUNDLE+=7z a ../../../sky-bundle-${VERSION}-${ARTIFACT}.zip skysh.exe skyd.exe sky-bench.exe sky-migrate.exe
|
|
||||||
else
|
|
||||||
# not windows, so no exe
|
|
||||||
ifneq ($(origin CARGO_TARGET_DIR),undefined)
|
|
||||||
# target defined and target dir. use this instead of target/
|
|
||||||
BUNDLE+=zip -j sky-bundle-${VERSION}-${ARTIFACT}.zip ${CARGO_TARGET_DIR}/${TARGET}/release/skysh ${CARGO_TARGET_DIR}/${TARGET}/release/skyd ${CARGO_TARGET_DIR}/${TARGET}/release/sky-bench ${CARGO_TARGET_DIR}/${TARGET}/release/sky-migrate
|
|
||||||
else
|
|
||||||
# just the plain old target/${TARGET} path
|
|
||||||
BUNDLE+=zip -j sky-bundle-${VERSION}-${ARTIFACT}.zip target/${TARGET}/release/skysh target/${TARGET}/release/skyd target/${TARGET}/release/sky-bench target/${TARGET}/release/sky-migrate
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
RENAME_ARTIFACT := $(addprefix mv ourbundle.zip ,${RENAME_ARTIFACT})
|
||||||
|
|
||||||
|
# cargo build (debug)
|
||||||
|
DEBUG := $(CBUILD)
|
||||||
|
# cargo test
|
||||||
|
TEST := $(CTEST)
|
||||||
|
# cargo build (release)
|
||||||
|
RELEASE := $(CBUILD) --release
|
||||||
|
# cargo build (release) for skyd,skysh,sky-migrate and sky-bench
|
||||||
|
RELEASE_BUNDLE := $(RELEASE) -p skyd -p sky-bench -p skysh -p sky-migrate
|
||||||
|
SEP=echo "============================================================"
|
||||||
|
|
||||||
.pre:
|
.pre:
|
||||||
@echo "===================================================================="
|
@${SEP}
|
||||||
@echo "Installing any additional dependencies"
|
@echo "Installing additional dependencies ..."
|
||||||
@echo "===================================================================="
|
@${ADDITIONAL_SOFTWARE}
|
||||||
@$(ADDITIONAL_SOFTWARE)
|
@${SEP}
|
||||||
deb: release
|
|
||||||
@echo "===================================================================="
|
|
||||||
@echo "Building Debian package (optimized)"
|
|
||||||
@echo "===================================================================="
|
|
||||||
@cargo $(TARGET_ARG) install cargo-deb
|
|
||||||
@cargo deb $(TARGET_ARG) --manifest-path=server/Cargo.toml --output .
|
|
||||||
build: .pre
|
build: .pre
|
||||||
@echo "===================================================================="
|
@${SEP}
|
||||||
@echo "Building all binaries in debug mode (unoptimized)"
|
@echo "Building all binaries (debug) ..."
|
||||||
@echo "===================================================================="
|
@${DEBUG}
|
||||||
@$(BUILD_COMMAND)
|
@${SEP}
|
||||||
.build-server: .pre
|
|
||||||
@echo "===================================================================="
|
|
||||||
@echo "Building server binary in debug mode (unoptimized)"
|
|
||||||
@echo "===================================================================="
|
|
||||||
@$(BUILD_SERVER_COMMAND)
|
|
||||||
release: .pre
|
release: .pre
|
||||||
@echo "===================================================================="
|
@${SEP}
|
||||||
@echo "Building all binaries in release mode (optimized)"
|
@echo "Building all binaries (release) ..."
|
||||||
@echo "===================================================================="
|
@${RELEASE}
|
||||||
cargo build --release --verbose $(TARGET_ARG)
|
@${SEP}
|
||||||
.release-server:
|
release-bundle: .pre
|
||||||
@echo "===================================================================="
|
@${SEP}
|
||||||
@echo "Building server binary in release mode (optimized)"
|
@echo "Building binaries for packaging (release) ..."
|
||||||
@echo "===================================================================="
|
@${RELEASE_BUNDLE}
|
||||||
@$(RELEASE_SERVER_COMMAND)
|
@${SEP}
|
||||||
test: .build-server
|
bundle: release-bundle
|
||||||
@echo "===================================================================="
|
@${SEP}
|
||||||
@echo "Starting database server in background"
|
@echo "Building and packaging bundle (release) ..."
|
||||||
@echo "===================================================================="
|
@${ARCHIVE}
|
||||||
@chmod +x ci/ssl.sh && bash ci/ssl.sh
|
@-${RENAME_ARTIFACT}
|
||||||
@${START_COMMAND}
|
@${SEP}
|
||||||
# sleep for 5s to let the server start up
|
test: .pre
|
||||||
@sleep 5
|
@${SEP}
|
||||||
@echo "===================================================================="
|
@echo "Building and starting server in debug mode ..."
|
||||||
@echo "Running all tests"
|
@${CBUILD} -p skyd
|
||||||
@echo "===================================================================="
|
|
||||||
cargo test $(TARGET_ARG)
|
|
||||||
@$(STOP_SERVER)
|
|
||||||
@sleep 2
|
|
||||||
@rm -f .sky_pid cert.pem key.pem
|
|
||||||
stress: .release-server
|
|
||||||
@echo "===================================================================="
|
|
||||||
@echo "Starting database server in background"
|
|
||||||
@echo "===================================================================="
|
|
||||||
@chmod +x ci/ssl.sh && bash ci/ssl.sh
|
@chmod +x ci/ssl.sh && bash ci/ssl.sh
|
||||||
@${START_COMMAND_RELEASE}
|
@${START_SERVER}
|
||||||
# sleep for 5s to let the server start up
|
@echo "Sleeping for 10 seconds to let the server start up ..."
|
||||||
@sleep 5
|
@sleep 10
|
||||||
cargo run $(TARGET_ARG) --release -p stress-test
|
@echo "Finished sleeping"
|
||||||
@echo "===================================================================="
|
@${SEP}
|
||||||
@echo "Stress testing (all)"
|
@${SEP}
|
||||||
@echo "===================================================================="
|
@echo "Running all tests ..."
|
||||||
@$(STOP_SERVER)
|
@${TEST}
|
||||||
|
@echo "Waiting for server to shut down ..."
|
||||||
|
@${STOP_SERVER}
|
||||||
|
@echo "Removing temporary files ..."
|
||||||
@rm -f .sky_pid cert.pem key.pem
|
@rm -f .sky_pid cert.pem key.pem
|
||||||
bundle: release
|
@${SEP}
|
||||||
@echo "===================================================================="
|
|
||||||
@echo "Creating bundle for platform"
|
|
||||||
@echo "===================================================================="
|
|
||||||
@$(BUNDLE)
|
|
||||||
clean:
|
clean:
|
||||||
@echo "===================================================================="
|
@${SEP}
|
||||||
@echo "Cleaning up target folder"
|
@echo "Cleaning up target folder ..."
|
||||||
@echo "===================================================================="
|
|
||||||
cargo clean
|
cargo clean
|
||||||
|
@${SEP}
|
||||||
|
Loading…
Reference in New Issue