Skip to content

Commit

Permalink
Allow overwriting default values CC, CPP, AR, LD (#245)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

* Fix environment variable handling in CI

Signed-off-by: Hanno Becker <[email protected]>

---------

Signed-off-by: Hanno Becker <[email protected]>
  • Loading branch information
hanno-becker authored Oct 16, 2024
1 parent c3433b8 commit baec037
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 21 deletions.
28 changes: 13 additions & 15 deletions .github/actions/functest/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down
5 changes: 4 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 ]
Expand Down
13 changes: 9 additions & 4 deletions mk/config.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion mk/rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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) $<

Expand Down

0 comments on commit baec037

Please sign in to comment.