diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 8695b3079f..6543827086 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -3,54 +3,69 @@ image: "redoxos/redoxer:latest" variables: GIT_SUBMODULE_STRATEGY: recursive +workflow: + rules: + - if: '$CI_COMMIT_BRANCH == "master" && $CI_PROJECT_NAMESPACE == "redox-os"' + - if: '$CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "master"' + stages: - build + - cross-build - test before_script: cargo install cbindgen -default: - cache: - paths: - - target/ - -build:linux: - stage: build - script: - - rustup show # Ensure correct toolchain is downloaded and installed - - make -j "$(nproc)" all - -build:redox: - stage: build - variables: - TARGET: x86_64-unknown-redox - script: - - ./redoxer.sh -j "$(nproc)" all - -test:linux: - stage: test - needs: - - build:linux - dependencies: - - build:linux - script: - - make test - -test:redox: - stage: test - needs: - - build:redox - dependencies: - - build:redox - variables: - TARGET: x86_64-unknown-redox - script: - # TODO: sigaction and sigaltstack sometimes hangs with multi core - - REDOXER_QEMU_ARGS="-smp 1" ./redoxer.sh test SKIP_REDOX=1 - fmt: - stage: test + stage: build needs: [] script: - rustup component add rustfmt-preview - ./fmt.sh -- --check + +linux: + stage: build + script: + - ./check.sh --host + +x86_64: + stage: build + script: + - ./check.sh --arch=x86_64 + +i586: + stage: cross-build + script: + - ./check.sh --arch=i586 + +aarch64: + stage: cross-build + script: + - ./check.sh --arch=aarch64 + +riscv64gc: + stage: cross-build + script: + - ./check.sh --arch=riscv64gc + +test:linux: + stage: test + needs: [linux] + dependencies: [linux] + script: + - ./check.sh --host --test + +test:x86_64: + stage: test + needs: [x86_64] + dependencies: [x86_64] + script: + - ./check.sh --arch=x86_64 --test + +test:aarch64: + stage: test + needs: [aarch64] + dependencies: [aarch64] + script: + - ./check.sh --arch=aarch64 --test + +#TODO: Enable more arch once dynamic linker working diff --git a/Makefile b/Makefile index bf5570fc5e..d06a41e73b 100644 --- a/Makefile +++ b/Makefile @@ -33,20 +33,20 @@ all: | headers libs headers: $(HEADERS_DEPS) rm -rf $(TARGET_HEADERS) - mkdir -pv $(TARGET_HEADERS) - cp -rv include/* $(TARGET_HEADERS) - cp -v "openlibm/include"/*.h $(TARGET_HEADERS) - cp -v "openlibm/src"/*.h $(TARGET_HEADERS) - set -e ; \ + mkdir -p $(TARGET_HEADERS) + cp -r include/* $(TARGET_HEADERS) + cp "openlibm/include"/*.h $(TARGET_HEADERS) + cp "openlibm/src"/*.h $(TARGET_HEADERS) + @set -e ; \ for header in $(HEADERS_UNPARSED); do \ - echo "Header $$header"; \ + echo "\033[0;36;49mWriting Header $$header\033[0m"; \ if test -f "src/header/$$header/cbindgen.toml"; then \ out=`echo "$$header" | sed 's/_/\//g'`; \ out="$(TARGET_HEADERS)/$$out.h"; \ cat "src/header/$$header/cbindgen.toml" cbindgen.globdefs.toml \ | cbindgen "src/header/$$header/mod.rs" --config=/dev/stdin --output "$$out"; \ fi \ - done + done; echo "\033[0;36;49mAll headers written\033[0m"; clean: $(CARGO) clean @@ -178,8 +178,8 @@ $(BUILD)/release/libc.a: $(BUILD)/release/librelibc.a $(BUILD)/openlibm/libopenl $(BUILD)/release/librelibc.a: $(SRC) $(CARGO) rustc --release $(CARGOFLAGS) -- --emit link=$@ $(RUSTCFLAGS) - # TODO: Better to only allow a certain whitelisted set of symbols? Perhaps - # use some cbindgen hook, specify them manually, or grep for #[unsafe(no_mangle)]. + @# TODO: Better to only allow a certain whitelisted set of symbols? Perhaps + @# use some cbindgen hook, specify them manually, or grep for #[unsafe(no_mangle)]. ./renamesyms.sh "$@" "$(BUILD)/release/deps/" ./stripcore.sh "$@" touch $@ diff --git a/bindgen_transform.sh b/bindgen_transform.sh deleted file mode 100755 index 0aee57a319..0000000000 --- a/bindgen_transform.sh +++ /dev/null @@ -1,4 +0,0 @@ -sed -i 's/::std::os::raw:://g' $1 -perl -i -p0e 's/extern "C" \{\n pub fn/#[unsafe(no_mangle)]\npub extern "C" fn/g' $1 -perl -i -p0e 's/;\n\}/ {\n unimplemented!();\n\}\n/g' $1 -rustfmt $1 diff --git a/check.sh b/check.sh new file mode 100755 index 0000000000..ceeeb4ba3f --- /dev/null +++ b/check.sh @@ -0,0 +1,150 @@ +#!/bin/bash + +RED='\033[1;38;5;196m' +GREEN='\033[1;38;5;46m' +NC='\033[0m' + +show_help() { + echo "Usage: $(basename "$0") [OPTIONS]" + echo "" + echo "Description:" + echo " Wrapper for Makefile / Cargo to run checks or tests on Redox OS targets." + echo "" + echo "Options:" + echo " --test Run 'make test' instead of 'make all'" + echo " --cargo Run 'cargo check' / 'cargo test' instead" + echo " (note: cargo test is currently not maintained for relibc)" + echo " --host Run the command on host (linux) target" + echo " --all-target Run the command on all supported Redox architectures" + echo " --target= Override the target architecture (e.g., i586-unknown-redox)" + echo " --arch= Override the target architecture using arch (e.g., i586)" + echo " --help Show this help message" + echo "" + echo "Supported Targets:" + for t in "${SUPPORTED_TARGETS[@]}"; do + echo " - $t" + done + echo " - $(uname -m)-unknown-linux-gnu" + echo "" + echo "Environment:" + echo " TARGET Sets the default target (overridden by --target)" +} + +if ! command -v redoxer &> /dev/null; then + echo "Error: 'redoxer' CLI not found." + echo "Please install it: cargo install redoxer" + exit 1 +fi + +if ! command -v cbindgen &> /dev/null; then + echo "Error: 'cbindgen' CLI not found." + echo "Please install it: cargo install cbindgen" + exit 1 +fi + +SUPPORTED_TARGETS=( + "x86_64-unknown-redox" + "i586-unknown-redox" + "aarch64-unknown-redox" + "riscv64gc-unknown-redox" +) + +CURRENT_TARGET="${TARGET:-x86_64-unknown-redox}" +CHECK_ALL=false +CMD_ACTION="make" +CARGO_ACTION="check" +MAKE_ACTION="all" +IS_HOST=0 + +while [[ $# -gt 0 ]]; do + case "$1" in + --all-target) + CHECK_ALL=true + ;; + --test) + MAKE_ACTION="test" + CARGO_ACTION="test" + ;; + --cargo) + CMD_ACTION="cargo" + ;; + --host) + CURRENT_TARGET="$(uname -m)-unknown-linux-gnu" + IS_HOST=1 + ;; + --target=*) + CURRENT_TARGET="${1#*=}" + ;; + --arch=*) + CURRENT_TARGET="${1#*=}-unknown-redox" + ;; + --help) + show_help + exit 0 + ;; + *) + echo -e "${RED}Error: Unknown option '$1'${NC}" + show_help + exit 1 + ;; + esac + shift +done + +run_redoxer() { + export TARGET=$1 + REDOXER_ENV="redoxer env" + if [ "$IS_HOST" -eq 0 ]; then + redoxer toolchain || { echo -e "${RED}Fail: redoxer toolchain for: $target.${NC}" && exit 1; } + export CARGOFLAGS="" + export CARGO_TEST="redoxer" + export TEST_RUNNER="redoxer exec --folder . --" + MAKE_ACTION="$MAKE_ACTION SKIP_REDOX=1" + else + REDOXER_ENV="" + fi + + if [ "$CMD_ACTION" == "make" ]; then + CMD_OPT="-j $(nproc) $MAKE_ACTION" + else + CMD_OPT="$CARGO_ACTION" + fi + + echo "----------------------------------------" + echo "Running $REDOXER_ENV $CMD_ACTION $CMD_OPT for: $TARGET" + + if $REDOXER_ENV $CMD_ACTION $CMD_OPT; then + return 0 + else + echo -e "${RED}Fail: $CMD_ACTION $CMD_OPT for $TARGET failed.${NC}" + return 1 + fi +} + +if [ "$CHECK_ALL" = true ]; then + echo "Running $CMD_ACTION for all supported Redox targets..." + + has_error=false + + for target in "${SUPPORTED_TARGETS[@]}"; do + if ! run_redoxer "$target"; then + has_error=true + fi + done + + echo "----------------------------------------" + if [ "$has_error" = true ]; then + echo -e "${RED}Summary: One or more targets failed.${NC}" + exit 1 + else + echo -e "${GREEN}Summary: All targets passed!${NC}" + exit 0 + fi +else + if run_redoxer "$CURRENT_TARGET"; then + echo -e "${GREEN}Success: $CARGO_ACTION for $CURRENT_TARGET passed.${NC}" + exit 0 + else + exit 1 + fi +fi diff --git a/ci.sh b/ci.sh deleted file mode 100755 index 81b4d6ed20..0000000000 --- a/ci.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env bash -set -ex - -./fmt.sh -- --check -if [ -z "$TARGET" ] -then - make all - make test -else - make libs -fi diff --git a/redoxer.sh b/redoxer.sh deleted file mode 100755 index da7aebded5..0000000000 --- a/redoxer.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/usr/bin/env bash - -set -e - -if ! which redoxer -then - cargo install redoxer -fi - -if [ ! -d "$HOME/.redoxer/toolchain" ] -then - redoxer toolchain -fi - -export CARGOFLAGS="" -export CARGO_TEST="redoxer" -export TEST_RUNNER="redoxer exec --folder . --" -redoxer env make "$@" diff --git a/tests/Makefile b/tests/Makefile index 8fceefdbe1..556706c193 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -327,9 +327,10 @@ clean: rm -rf bins_* gen *.out run: | $(BINS) $(EXPECT_INPUT_BINS) - for bin in $(BINS); \ + @echo "\033[1;36;49mRunning tests\033[0m" + @for bin in $(BINS); \ do \ - echo "# $${bin} #"; \ + echo "\033[0;96;49m# $${bin} #\033[0m"; \ ${TEST_RUNNER} "$${bin}" test args || exit $$?; \ done for exp in $(EXPECT_INPUT_BINS); \ @@ -408,30 +409,30 @@ endif $(BUILD)/bins_static/%: %.c $(DEPS) mkdir -p "$$(dirname "$@")" - $(CC) "$<" -o "$@" $(FLAGS) $(STATIC_FLAGS) + @$(CC) "$<" -o "$@" $(FLAGS) $(STATIC_FLAGS) $(BUILD)/bins_expect_input/%: %.c %.exp $(DEPS) mkdir -p "$$(dirname "$@")" - $(CC) "$<" -o "$@" $(FLAGS) $(STATIC_FLAGS) + @$(CC) "$<" -o "$@" $(FLAGS) $(STATIC_FLAGS) cp $(word 2, "$^") $(addsuffix .exp,"$@") $(BUILD)/bins_dynamic/%.so: %.c $(DEPS) mkdir -p "$$(dirname "$@")" - $(CC) "$<" -o "$@" -shared -fpic $(FLAGS) $(DYNAMIC_FLAGS) + @$(CC) "$<" -o "$@" -shared -fpic $(FLAGS) $(DYNAMIC_FLAGS) # foobar depends on foo $(BUILD)/bins_dynamic/libfoobar.so: libfoobar.c $(BUILD)/bins_dynamic/libfoo.so $(DEPS) mkdir -p "$$(dirname "$@")" - $(CC) "$<" -o "$@" -shared -fpic $(FLAGS) $(DYNAMIC_FLAGS) -L $(BUILD)/bins_dynamic -lfoo + @$(CC) "$<" -o "$@" -shared -fpic $(FLAGS) $(DYNAMIC_FLAGS) -L $(BUILD)/bins_dynamic -lfoo $(BUILD)/bins_dynamic/dlfcn: dlfcn.c $(BUILD)/bins_dynamic/sharedlib.so $(DEPS) mkdir -p "$$(dirname "$@")" - $(CC) "$<" -o "$@" $(FLAGS) $(DYNAMIC_FLAGS) + @$(CC) "$<" -o "$@" $(FLAGS) $(DYNAMIC_FLAGS) $(BUILD)/bins_dynamic/dlopen_scopes: dlopen_scopes.c $(BUILD)/bins_dynamic/libfoobar.so $(BUILD)/bins_dynamic/libfoo.so $(DEPS) mkdir -p "$$(dirname "$@")" - $(CC) "$<" -o "$@" $(FLAGS) $(DYNAMIC_FLAGS) + @$(CC) "$<" -o "$@" $(FLAGS) $(DYNAMIC_FLAGS) $(BUILD)/bins_dynamic/%: %.c $(DEPS) mkdir -p "$$(dirname "$@")" - $(CC) "$<" -o "$@" $(FLAGS) $(DYNAMIC_FLAGS) + @$(CC) "$<" -o "$@" $(FLAGS) $(DYNAMIC_FLAGS)