Skip to content

Commit

Permalink
add support to build standalone artifacts
Browse files Browse the repository at this point in the history
  • Loading branch information
mkannwischer committed Jul 12, 2024
1 parent 56ec599 commit 8526688
Show file tree
Hide file tree
Showing 10 changed files with 79 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/run.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ jobs:
submodules: true
- name: install dependencies
run: sudo apt install gcc-arm-none-eabi qemu-system
- name: Make all
- name: Make all and run
run: |
make -j$(nproc) run
19 changes: 19 additions & 0 deletions .github/workflows/standalone.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Package standalone artifacts and build
on:
pull_request:
branches: [ "main" ]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: true
- name: install dependencies
run: sudo apt install gcc-arm-none-eabi qemu-system
- name: Package standalone artificats
run: |
make -j$(nproc) standalone
- name: Make sure all standalone artifacts build
run: |
for standlone in standalone/*; do make -C $standalone; done
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
**/build/
**/*.elf
standalone
28 changes: 20 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,50 @@ include tests/ntt_dilithium/ntt_dilithium.mk
include tests/ntt_kyber/ntt_kyber.mk

totestname = $(shell echo $(1) | tr '[a-z]' '[A-Z]')
totestsources = $(addprefix ../../tests/$(1)/,$($(call totestname,$(1))_SOURCES))
totestasm = $(addprefix ../../tests/$(1)/,$($(call totestname,$(1))_ASMS))
totestsources = $(addprefix $(2),$(addprefix tests/$(1)/,$($(call totestname,$(1))_SOURCES)))
totestasm = $(addprefix $(2),$(addprefix tests/$(1)/,$($(call totestname,$(1))_ASMS)))
totestother = $(addprefix $(2),$(addprefix tests/$(1)/,$($(call totestname,$(1))_OTHER)))
toplatform = $(addsuffix --$(1),$($(call totestname,$(1))_PLATFORMS))
toelfname = $(addsuffix -test.elf,$(1))

platformtests := $(foreach test,$(TESTS), $(call toplatform,$(test)))

builds := $(addprefix build-, $(platformtests))
runs := $(addprefix run-, $(platformtests))
cleans := $(addprefix clean-, $(platformtests))
builds := $(addprefix build-, $(platformtests))
runs := $(addprefix run-, $(platformtests))
cleans := $(addprefix clean-, $(platformtests))
standalones := $(addprefix standalone-, $(platformtests))

.PHONY: all
all: ${builds}

platform = $(firstword $(subst --, ,$*))
test = $(lastword $(subst --, ,$*))


.PHONY: ${builds}
${builds}: build-%:
make -j$(shell nproc) -C envs/$(platform) build SOURCES='$(call totestsources,$(test))' ASMS='$(call totestasm,$(test))' TARGET=$(call toelfname,$(test))
make -j$(shell nproc) -C envs/$(platform) build SOURCES='$(call totestsources,$(test),../../)' ASMS='$(call totestasm,$(test),../../)' TARGET=$(call toelfname,$(test))

.PHONY: ${runs}
${runs}: run-%:
make -C envs/$(platform) run SOURCES='$(call totestsources,$(test))' ASMS='$(call totestasm,$(test))' TARGET=$(call toelfname,$(test))
make -C envs/$(platform) run SOURCES='$(call totestsources,$(test),../../)' ASMS='$(call totestasm,$(test),../../)' TARGET=$(call toelfname,$(test))

.PHONY: run
run: ${runs}

.PHONY: ${standalones}
${standalones}: standalone-%:
make -C envs/$(platform) clean
mkdir -p standalone/$@/test_src/
cp -rL envs/$(platform)/* standalone/$@/
cp -rL $(call totestsources,$(test),./) $(call totestasm,$(test),./) $(call totestother,$(test),./) standalone/$@/test_src/

.PHONY: standalone
standalone: ${standalones}

.PHONY: ${cleans}
${cleans}: clean-%:
make -C envs/$(platform) clean

.PHONY: clean
clean: ${cleans}
rm -rf standalone
9 changes: 7 additions & 2 deletions envs/m55-an547/Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
# Makefile for images for AN547

# default values (when not called from the root Makefile - used in standalone artifacts)
TARGET ?= test.elf
SOURCES ?= $(wildcard test_src/*.c)
ASMS ?= $(wildcard test_src/*.s)

CC = arm-none-eabi-gcc
LD := $(CC)

SRC_DIR=./src
BUILD_DIR=./build

COMMON_INC=../common/inc/
COMMON_INC=common/inc/
ENV_INC=./inc/

SYSROOT := $(shell $(CC) --print-sysroot)
Expand Down Expand Up @@ -49,7 +54,7 @@ LDFLAGS += \

all: $(TARGET)

HAL_SOURCES = $(wildcard $(SRC_DIR)/*.c) $(wildcard $(SRC_DIR)/*/*.c) $(wildcard ../common/src/*.c)
HAL_SOURCES = $(wildcard $(SRC_DIR)/*.c) $(wildcard $(SRC_DIR)/*/*.c) $(wildcard common/src/*.c)
OBJECTS_HAL = $(patsubst %.c, $(BUILD_DIR)/%.c.o, $(abspath $(HAL_SOURCES)))
OBJECTS_SOURCES=$(patsubst %.c, $(BUILD_DIR)/%.c.o, $(abspath $(SOURCES)))
OBJECTS_C = $(OBJECTS_SOURCES) $(OBJECTS_HAL)
Expand Down
1 change: 1 addition & 0 deletions envs/m55-an547/common
9 changes: 7 additions & 2 deletions envs/m85-an555/Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
# Makefile for images for AN555

# default values (when not called from the root Makefile - used in standalone artifacts)
TARGET ?= test.elf
SOURCES ?= $(wildcard test_src/*.c)
ASMS ?= $(wildcard test_src/*.s)

CC = arm-none-eabi-gcc
LD := $(CC)

SRC_DIR=./src
BUILD_DIR=./build

COMMON_INC=../common/inc/
COMMON_INC=common/inc/
ENV_INC=./inc/

SYSROOT := $(shell $(CC) --print-sysroot)
Expand Down Expand Up @@ -49,7 +54,7 @@ LDFLAGS += \

all: $(TARGET)

HAL_SOURCES = $(wildcard $(SRC_DIR)/*.c) $(wildcard $(SRC_DIR)/*/*.c) $(wildcard ../common/src/*.c)
HAL_SOURCES = $(wildcard $(SRC_DIR)/*.c) $(wildcard $(SRC_DIR)/*/*.c) $(wildcard common/src/*.c)
OBJECTS_HAL = $(patsubst %.c, $(BUILD_DIR)/%.c.o, $(abspath $(HAL_SOURCES)))
OBJECTS_SOURCES=$(patsubst %.c, $(BUILD_DIR)/%.c.o, $(abspath $(SOURCES)))
OBJECTS_C = $(OBJECTS_SOURCES) $(OBJECTS_HAL)
Expand Down
1 change: 1 addition & 0 deletions envs/m85-an555/common
12 changes: 11 additions & 1 deletion tests/ntt_dilithium/ntt_dilithium.mk
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
# Test name - needs to match the directory name
TESTS += ntt_dilithium

# All further variables must be prefixed with the capitalized test name

# Platforms this test should run on (matching the directory name in envs/)
NTT_DILITHIUM_PLATFORMS += m55-an547
NTT_DILITHIUM_PLATFORMS += m85-an555

# C sources required for this test
NTT_DILITHIUM_SOURCES += main.c

# Assembly sources required for this test
NTT_DILITHIUM_ASM_DIR = ../../asm/manual/ntt_dilithium
NTT_DILITHIUM_ASMS += $(NTT_DILITHIUM_ASM_DIR)/ntt_dilithium_12_34_56_78_no_trans_vld4_opt_m55.s
NTT_DILITHIUM_ASMS += $(NTT_DILITHIUM_ASM_DIR)/ntt_dilithium_12_34_56_78_no_trans_vld4_opt_m85.s
Expand All @@ -14,4 +20,8 @@ NTT_DILITHIUM_ASMS += $(NTT_DILITHIUM_ASM_DIR)/ntt_dilithium_12_34_56_78_opt_m85
NTT_DILITHIUM_ASMS += $(NTT_DILITHIUM_ASM_DIR)/ntt_dilithium_12_34_56_78.s
NTT_DILITHIUM_ASMS += $(NTT_DILITHIUM_ASM_DIR)/ntt_dilithium_123_456_78_opt_size_m55.s
NTT_DILITHIUM_ASMS += $(NTT_DILITHIUM_ASM_DIR)/ntt_dilithium_123_456_78_opt_size_m85.s
NTT_DILITHIUM_ASMS += $(NTT_DILITHIUM_ASM_DIR)/ntt_dilithium_123_456_78.s
NTT_DILITHIUM_ASMS += $(NTT_DILITHIUM_ASM_DIR)/ntt_dilithium_123_456_78.s

# Additional required files (needed for packaging a standalone artifact)
NTT_DILITHIUM_OTHER += $(NTT_DILITHIUM_ASM_DIR)/ntt_dilithium_12_34_56_78_twiddles.s
NTT_DILITHIUM_OTHER += $(NTT_DILITHIUM_ASM_DIR)/ntt_dilithium_123_456_78_twiddles.s
12 changes: 11 additions & 1 deletion tests/ntt_kyber/ntt_kyber.mk
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
# Test name - needs to match the directory name
TESTS += ntt_kyber

# All further variables must be prefixed with the capitalized test name

# Platforms this test should run on (matching the directory name in envs/)
NTT_KYBER_PLATFORMS += m55-an547
NTT_KYBER_PLATFORMS += m85-an555

# C sources required for this test
NTT_KYBER_SOURCES += main.c

# Assembly sources required for this test
NTT_KYBER_ASM_DIR=../../asm/manual/ntt_kyber
NTT_KYBER_ASMS += $(NTT_KYBER_ASM_DIR)/ntt_kyber_1_23_45_67_no_trans_opt_m55.s
NTT_KYBER_ASMS += $(NTT_KYBER_ASM_DIR)/ntt_kyber_1_23_45_67_no_trans_opt_m85.s
Expand All @@ -14,4 +20,8 @@ NTT_KYBER_ASMS += $(NTT_KYBER_ASM_DIR)/ntt_kyber_1_23_45_67_no_trans_vld4.s
NTT_KYBER_ASMS += $(NTT_KYBER_ASM_DIR)/ntt_kyber_1_23_45_67_no_trans.s
NTT_KYBER_ASMS += $(NTT_KYBER_ASM_DIR)/ntt_kyber_12_345_67_opt_size_m55.s
NTT_KYBER_ASMS += $(NTT_KYBER_ASM_DIR)/ntt_kyber_12_345_67_opt_size_m85.s
NTT_KYBER_ASMS += $(NTT_KYBER_ASM_DIR)/ntt_kyber_12_345_67.s
NTT_KYBER_ASMS += $(NTT_KYBER_ASM_DIR)/ntt_kyber_12_345_67.s

# Additional required files (needed for packaging a standalone artifact)
NTT_KYBER_OTHER += $(NTT_KYBER_ASM_DIR)/ntt_kyber_1_23_45_67_twiddles.s
NTT_KYBER_OTHER += $(NTT_KYBER_ASM_DIR)/ntt_kyber_12_345_67_twiddles.s

0 comments on commit 8526688

Please sign in to comment.