Skip to content

Commit 1095a41

Browse files
committed
Validate the prerequisites before building
To prevent users from building shecc without certain required packages, these changes modify the build system to check for prerequisites when building. The build system now lists all necessary tools, verify the existence of their executables, and prints warning messages if any required tool is missing. If qemu is required but missing, the build process will proceed only up to stage 0, print warning messages and stop at the beginning of stage 1. Additionally, these changes modify main.yml to install all necessary tools for the host-arm build, so the build won't fail due to missing packages. Close #44
1 parent 8477c87 commit 1095a41

File tree

5 files changed

+26
-16
lines changed

5 files changed

+26
-16
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jobs:
3939
githubToken: ${{ github.token }}
4040
install: |
4141
apt-get update -qq -y
42-
apt-get install -yqq build-essential
42+
apt-get install -yqq build-essential graphviz jq
4343
run: |
4444
make config ARCH=arm
4545
make check || exit 1

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ CFLAGS := -O -g \
1616

1717
BUILD_SESSION := .session.mk
1818

19-
include mk/common.mk
2019
-include $(BUILD_SESSION)
2120

2221
STAGE0 := shecc
@@ -26,6 +25,7 @@ STAGE2 := shecc-stage2.elf
2625
OUT ?= out
2726
ARCHS = arm riscv
2827
ARCH ?= $(firstword $(ARCHS))
28+
HOST_ARCH = $(shell arch 2>/dev/null)
2929
SRCDIR := $(shell find src -type d)
3030
LIBDIR := $(shell find lib -type d)
3131

@@ -42,12 +42,14 @@ ifeq (,$(filter $(ARCH),$(ARCHS)))
4242
$(error Support ARM and RISC-V only. Select the target with "ARCH=arm" or "ARCH=riscv")
4343
endif
4444
include mk/$(ARCH).mk
45+
include mk/common.mk
4546

4647
config:
4748
$(Q)ln -s $(PWD)/$(SRCDIR)/$(ARCH)-codegen.c $(SRCDIR)/codegen.c
4849
$(call $(ARCH)-specific-defs) > $@
4950
$(VECHO) "Target machine code switch to %s\n" $(ARCH)
5051
$(Q)$(MAKE) $(BUILD_SESSION) --silent
52+
$(CONFIG_CHECK_CMD)
5153

5254
$(OUT)/tests/%.elf: tests/%.c $(OUT)/$(STAGE0)
5355
$(VECHO) " SHECC\t$@\n"
@@ -103,6 +105,7 @@ $(OUT)/$(STAGE0): $(OUT)/libc.inc $(OBJS)
103105
$(Q)$(CC) $(OBJS) -o $@
104106

105107
$(OUT)/$(STAGE1): $(OUT)/$(STAGE0)
108+
$(STAGE1_CHECK_CMD)
106109
$(VECHO) " SHECC\t$@\n"
107110
$(Q)$(OUT)/$(STAGE0) --dump-ir -o $@ $(SRCDIR)/main.c > $(OUT)/shecc-stage1.log
108111
$(Q)chmod a+x $@

mk/arm.mk

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
ifeq ($(HOST_ARCH),armv7l) # detect ARMv7-A only and assume Linux-compatible
22
TARGET_EXEC :=
33
else
4-
TARGET_EXEC = qemu-arm
5-
TARGET_EXEC := $(shell which $(TARGET_EXEC))
6-
ifndef TARGET_EXEC
7-
$(warning "no qemu-arm found. Please check package installation")
8-
ARM_EXEC = echo WARN: unable to run
9-
endif
4+
ARCH_EXEC = qemu-arm
5+
TARGET_EXEC := $(shell which $(ARCH_EXEC))
106
endif
117

128
export TARGET_EXEC

mk/common.mk

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ else
55
PRINTF = env printf
66
endif
77

8-
HOST_ARCH = $(shell arch 2>/dev/null)
9-
108
# Control the build verbosity
119
ifeq ("$(VERBOSE)","1")
1210
Q :=
@@ -23,3 +21,20 @@ PASS_COLOR = \e[32;01m
2321
NO_COLOR = \e[0m
2422

2523
pass = $(PRINTF) "$(PASS_COLOR)$1 Passed$(NO_COLOR)\n"
24+
25+
# Check the prerequisites
26+
PREREQ_LIST := dot jq $(ARCH_EXEC)
27+
PREREQ_EXEC := $(shell which $(PREREQ_LIST))
28+
PREREQ_MISSING := $(filter-out $(notdir $(PREREQ_EXEC)),$(PREREQ_LIST))
29+
30+
ifdef PREREQ_MISSING
31+
CONFIG_WARN_MSG := "Warning: missing packages: $(PREREQ_MISSING)\nWarning: Please check package installation\n"
32+
CONFIG_CHECK_CMD := $(Q)$(VECHO) $(CONFIG_WARN_MSG)
33+
endif
34+
35+
ifdef ARCH_EXEC
36+
ifeq ($(filter $(ARCH_EXEC),$(notdir $(PREREQ_EXEC))),)
37+
STAGE1_WARN_MSG := "Warning: failed to build the stage 1 and stage 2 compilers due to missing $(ARCH_EXEC)\n"
38+
STAGE1_CHECK_CMD := $(Q)$(VECHO) $(STAGE1_WARN_MSG) && exit 1
39+
endif
40+
endif

mk/riscv.mk

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
TARGET_EXEC = qemu-riscv32
2-
TARGET_EXEC := $(shell which $(TARGET_EXEC))
3-
ifndef TARGET_EXEC
4-
$(warning "no qemu-riscv32 found. Please check package installation")
5-
TARGET_EXEC = echo WARN: unable to run
6-
endif
1+
ARCH_EXEC = qemu-riscv32
2+
TARGET_EXEC := $(shell which $(ARCH_EXEC))
73

84
export TARGET_EXEC
95

0 commit comments

Comments
 (0)