You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

181 lines
5.3 KiB
Makefile

# although this is exported by cargo, we'll export it again to use it in the Makefile
export ROOT_DIR:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
export MSYS_NO_PATHCONV:=1
3 years ago
SKYTEST_S1_FILE := $(ROOT_DIR)/ci/server1.toml
SKYTEST_S2_FILE := $(ROOT_DIR)/ci/server2.toml
3 years ago
# no additional software note
NO_ADDITIONAL_SOFTWARE := echo "No additional software required for this target"
# target argument
TARGET_ARG :=
# target folder path
TARGET_FOLDER := target/
# additional software installation
ADDITIONAL_SOFTWARE :=
# update variables depending on target
ifneq ($(origin TARGET),undefined)
3 years ago
ifeq ($(TARGET),x86_64-unknown-linux-musl)
# for MUSL builds, we need to install musl-tools
ADDITIONAL_SOFTWARE += sudo apt-get update && sudo apt install musl-tools -y
else ifeq ($(TARGET),i686-unknown-linux-gnu)
# for 32-bit we need multilib
ADDITIONAL_SOFTWARE += sudo apt-get update && sudo apt install gcc-multilib -y
else
ADDITIONAL_SOFTWARE += ${NO_ADDITIONAL_SOFTWARE}
endif
TARGET_ARG += --target ${TARGET}
TARGET_FOLDER := $(addsuffix ${TARGET}/,${TARGET_FOLDER})
else
ADDITIONAL_SOFTWARE += ${NO_ADDITIONAL_SOFTWARE}
endif
3 years ago
TARGET_FOLDER := $(addsuffix release/,${TARGET_FOLDER})
# cargo build
CBUILD := cargo build $(TARGET_ARG)
# cargo test
CTEST := cargo test $(TARGET_ARG)
3 years ago
# cargo run
CRUN := cargo run $(TARGET_ARG)
3 years ago
# binary file paths
BINARY_SKYSH := $(TARGET_FOLDER)skysh
BINARY_SKYD := $(TARGET_FOLDER)skyd
BINARY_SKYBENCH := $(TARGET_FOLDER)sky-bench
BINARY_SKYMIGRATE := $(TARGET_FOLDER)sky-migrate
# archive command
ARCHIVE :=
# start background server command
START_SERVER := $(CRUN) -p skyd -- --withconfig "$(SKYTEST_S1_FILE)"
3 years ago
STOP_SERVER :=
ifeq ($(OS),Windows_NT)
3 years ago
# on windows, so we need exe
ARCHIVE += 7z a ourbundle.zip $(BINARY_SKYSH).exe $(BINARY_SKYD).exe $(BINARY_SKYBENCH).exe $(BINARY_SKYMIGRATE).exe
# also add RUSTFLAGS
export RUSTFLAGS = -Ctarget-feature=+crt-static
# now add start command
START_SERVER := cmd /C START /B $(START_SERVER)
# windows is funky with OpenSSL, so add these
CBUILD := cmd /C $(CBUILD)
CTEST := cmd /C $(CTEST)
# finally add stop command
STOP_SERVER := Powershell.exe -executionpolicy remotesigned -File ci\windows\stop.ps1
else
3 years ago
# not windows, so archive is easy
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
3 years ago
START_SERVER2 := $(subst $(SKYTEST_S1_FILE),$(SKYTEST_S2_FILE),$(START_SERVER))
3 years ago
# update the archive command if we have a version and artifact name
RENAME_ARTIFACT :=
ifneq ($(origin ARTIFACT),undefined)
# so we have an artifact name
ifneq ($(origin VERSION),undefined)
# we also have the version name
RENAME_ARTIFACT := sky-bundle-${VERSION}-${ARTIFACT}.zip
else
# no version name
RENAME_ARTIFACT := sky-bundle-${ARTIFACT}.zip
endif
else
3 years ago
# no artifact (hack)
RENAME_ARTIFACT := bundle.zip
endif
3 years ago
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:
3 years ago
@${SEP}
@echo "Installing additional dependencies ..."
@${ADDITIONAL_SOFTWARE}
@${SEP}
build: .pre
3 years ago
@${SEP}
@echo "Building all binaries (debug) ..."
@${DEBUG}
@${SEP}
release: .pre
3 years ago
@${SEP}
@echo "Building all binaries (release) ..."
@${RELEASE}
@${SEP}
release-bundle: .pre
@${SEP}
@echo "Building binaries for packaging (release) ..."
@${RELEASE_BUNDLE}
@${SEP}
bundle: release-bundle
@${SEP}
@echo "Building and packaging bundle (release) ..."
@${ARCHIVE}
@${RENAME_ARTIFACT}
3 years ago
@${SEP}
test: .pre
@${SEP}
@echo "Building and starting server in debug mode ..."
@chmod +x ci/ssl.sh && bash ci/ssl.sh
@${CBUILD} -p skyd
@mkdir -p server1 && cd server1 && ${START_SERVER}
@mkdir -p server2 && cd server2 && ${START_SERVER2}
3 years ago
@echo "Sleeping for 10 seconds to let the server start up ..."
@sleep 10
@echo "Finished sleeping"
@${SEP}
@${SEP}
@echo "Running all tests ..."
3 years ago
@${TEST}
3 years ago
@echo "Waiting for server to shut down ..."
@${STOP_SERVER}
3 years ago
@sleep 10
# now run persistence suite
@${SEP}
@echo "Running persistence suite ..."
@${SEP}
@mkdir -p server1 && cd server1 && ${START_SERVER}
@mkdir -p server2 && cd server2 && ${START_SERVER2}
@echo "Sleeping for 10 seconds to let the server start up ..."
@sleep 10
@echo "Finished sleeping"
@${SEP}
@${SEP}
@echo "Running all persistence tests ..."
@${TEST} --features persist-suite
@echo "Waiting for server to shut down ..."
@${STOP_SERVER}
@sleep 10
3 years ago
@echo "Removing temporary files ..."
3 years ago
@rm -rf .sky_pid server1 server2 .skytest_*
3 years ago
@${SEP}
clean:
3 years ago
@${SEP}
@echo "Cleaning up target folder ..."
cargo clean
3 years ago
@${SEP}
3 years ago
testclean:
@rm -rf server1 server2
deb: release-bundle
@${SEP}
@echo "Making a debian package (release) ..."
@echo "Installing tools for packaging ..."
@cargo install cargo-deb
@echo "Packaging ..."
@cargo deb $(TARGET_ARG) --no-build --manifest-path=server/Cargo.toml --output skytable-${VERSION}-${ARTIFACT}.deb
@${SEP}
3 years ago
checkcmd:
@echo $(START_SERVER)
@echo $(START_SERVER2)
@echo $(TARGET_FOLDER)