From baec03797878cdae1a5b80275520aa13b8d4045c Mon Sep 17 00:00:00 2001 From: Hanno Becker Date: Wed, 16 Oct 2024 09:13:16 +0100 Subject: [PATCH] Allow overwriting default values CC, CPP, AR, LD (#245) * Allow overwriting default values CC, CPP, AR This commit changes the Makefiles so that the developer can write ``` CC=XXX make ... ``` to overwrite the default compiler choice `gcc` with `XXX`. This is useful for quick exploration of different compiler choices. Signed-off-by: Hanno Becker * Fix environment variable handling in CI Signed-off-by: Hanno Becker --------- Signed-off-by: Hanno Becker --- .github/actions/functest/action.yml | 28 +++++++++++++--------------- flake.nix | 5 ++++- mk/config.mk | 13 +++++++++---- mk/rules.mk | 2 +- 4 files changed, 27 insertions(+), 21 deletions(-) diff --git a/.github/actions/functest/action.yml b/.github/actions/functest/action.yml index 2f0ff0079..71ad6104b 100644 --- a/.github/actions/functest/action.yml +++ b/.github/actions/functest/action.yml @@ -41,19 +41,22 @@ runs: shell: bash run: | arch=$(uname -m) - if [[ $arch == "x86_64" ]]; then + _cross_prefix= + if [[ ${{ inputs.mode }} == "cross" && $arch == "x86_64" ]]; then _cross_prefix="aarch64-unknown-linux-gnu-" - elif [[ $arch == "aarch64" ]]; then + elif [[ ${{ inputs.mode }} == "cross" && $arch == "aarch64" ]]; then _cross_prefix="x86_64-unknown-linux-gnu-" fi - if [[ ${{ inputs.mode }} == "cross" ]]; then - cross_prefix="$_cross_prefix" + _cc=$CC + if [[ $_cc == "" ]]; then + _cc=gcc fi - echo _CROSS_PREFIX="$_cross_prefix" >> $GITHUB_ENV # this is for printing summary only, which doesn't depend on inputs.mode - echo CROSS_PREFIX="$cross_prefix" >> $GITHUB_ENV - echo OPT="${{ inputs.opt == 'true' && 'opt' || 'no-opt' }}" >> $GITHUB_ENV + echo _CROSS_PREFIX="$_cross_prefix" >> $GITHUB_ENV + echo _CC="$_cc" >> $GITHUB_ENV + + echo OPT="${{ inputs.opt == 'true' && 'opt' || 'no-opt' }}" >> $GITHUB_ENV echo FUNC="${{ inputs.func == 'true' && 'func' || 'no-func' }}" >> $GITHUB_ENV echo KAT="${{ inputs.kat == 'true' && 'kat' || 'no-kat' }}" >> $GITHUB_ENV echo NISTKAT="${{ inputs.nistkat == 'true' && 'nistkat' || 'no-nistkat' }}" >> $GITHUB_ENV @@ -74,23 +77,18 @@ runs: - $(uname -a) - $(nix --version) - $(bash --version | grep -m1 "") - - $(gcc --version | grep -m1 "") + - $(${_CROSS_PREFIX}${_CC} --version | grep -m1 "") EOF - - # no cross gcc in darwin - if [[ $(uname -s) != "Darwin" ]]; then - echo "- $(${{ env._CROSS_PREFIX }}gcc --version | grep -m1 '')" >> $GITHUB_STEP_SUMMARY - fi fi - name: Compile ${{ inputs.mode }} ${{ env.OPT }} tests (${{ env.FUNC }}, ${{ env.KAT }}, ${{ env.NISTKAT }}) shell: ${{ env.SHELL }} run: | - tests all --cross-prefix="${{ env.CROSS_PREFIX }}" --cflags="${{ inputs.cflags }}" --${{ env.OPT }} --${{ env.FUNC }} --${{ env.KAT }} --${{ env.NISTKAT }} --compile --no-run -v + tests all --cross-prefix="${{ env._CROSS_PREFIX }}" --cflags="${{ inputs.cflags }}" --${{ env.OPT }} --${{ env.FUNC }} --${{ env.KAT }} --${{ env.NISTKAT }} --compile --no-run -v - name: Run ${{ inputs.mode }} ${{ env.OPT }} tests (${{ env.FUNC }}, ${{ env.KAT }}, ${{ env.NISTKAT }}) shell: ${{ env.SHELL }} run: | - tests all --cross-prefix="${{ env.CROSS_PREFIX }}" --cflags="${{ inputs.cflags }}" --${{ env.OPT }} --${{ env.FUNC }} --${{ env.KAT }} --${{ env.NISTKAT }} --no-compile --run -v + tests all --cross-prefix="${{ env._CROSS_PREFIX }}" --cflags="${{ inputs.cflags }}" --${{ env.OPT }} --${{ env.FUNC }} --${{ env.KAT }} --${{ env.NISTKAT }} --no-compile --run -v - name: Post ${{ inputs.mode }} Tests shell: ${{ env.SHELL }} if: success() || failure() diff --git a/flake.nix b/flake.nix index 6bfda9ebc..641d9df9a 100644 --- a/flake.nix +++ b/flake.nix @@ -54,7 +54,10 @@ then [ ] else if cross - then [ aarch64-gcc x86_64-gcc ] + then + if pkgs.stdenv.isAarch64 + then [ x86_64-gcc aarch64-gcc ] + else [ aarch64-gcc x86_64-gcc ] else if pkgs.stdenv.isAarch64 then [ aarch64-gcc ] diff --git a/mk/config.mk b/mk/config.mk index b08c8e7a6..0644e5c0b 100644 --- a/mk/config.mk +++ b/mk/config.mk @@ -7,11 +7,16 @@ SRCDIR := $(CURDIR) ############## # GCC config # ############## + CROSS_PREFIX ?= -CC := $(CROSS_PREFIX)gcc -CPP := $(CROSS_PREFIX)cpp -AR := $(CROSS_PREFIX)ar -LD := $(CC) +CC ?= gcc +CPP ?= cpp +AR ?= ar + +CC := $(CROSS_PREFIX)$(CC) +CPP := $(CROSS_PREFIX)$(CPP) +AR := $(CROSS_PREFIX)$(AR) +LD := $(CC) OBJCOPY := $(CROSS_PREFIX)objcopy SIZE := $(CROSS_PREFIX)size diff --git a/mk/rules.mk b/mk/rules.mk index 30ee90180..36519837d 100644 --- a/mk/rules.mk +++ b/mk/rules.mk @@ -22,7 +22,7 @@ $(LIB_DIR)/%.a: $(CONFIG) $(BUILD_DIR)/%.c.o: %.c $(CONFIG) $(Q)echo " CC $@" - $(Q)echo " CC $(CFLAGS)" + $(Q)echo " $(CC) -c -o $@ $(CFLAGS) $<" $(Q)[ -d $(@D) ] || mkdir -p $(@D) $(Q)$(CC) -c -o $@ $(CFLAGS) $<