From 4abbcbf8480eb8329989c61fed72b0fa24a536ed Mon Sep 17 00:00:00 2001 From: Maschell Date: Fri, 4 Feb 2022 22:49:31 +0100 Subject: [PATCH] Add a very basic example module and build it in the CI --- .github/workflows/pr.yml | 23 +++- .github/workflows/push_image.yml | 19 +++- Dockerfile.buildexamples | 15 +++ README.MD | 2 +- example/example_module/.gitignore | 10 ++ example/example_module/Makefile | 146 +++++++++++++++++++++++++ example/example_module/source/main.cpp | 39 +++++++ 7 files changed, 251 insertions(+), 3 deletions(-) create mode 100644 Dockerfile.buildexamples create mode 100644 example/example_module/.gitignore create mode 100644 example/example_module/Makefile create mode 100644 example/example_module/source/main.cpp diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index c57cc35..9fabc1b 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -22,4 +22,25 @@ jobs: - uses: actions/upload-artifact@master with: name: binary - path: "/lib/*.a" \ No newline at end of file + path: "/lib/*.a" + clang-format-examples: + runs-on: ubuntu-18.04 + steps: + - uses: actions/checkout@v2 + - name: clang-format + run: | + docker run --rm -v ${PWD}:/src wiiuenv/clang-format:13.0.0-2 -r ./example/example_module/source + build-examples: + runs-on: ubuntu-18.04 + needs: clang-format-examples + steps: + - uses: actions/checkout@v2 + - name: build binary + run: | + docker build . -f Dockerfile.buildexamples -t builder + cd ./example/example_module + docker run --rm -v ${PWD}:/project builder make + - uses: actions/upload-artifact@master + with: + name: binary + path: "*.wms" \ No newline at end of file diff --git a/.github/workflows/push_image.yml b/.github/workflows/push_image.yml index ab5253e..261e919 100644 --- a/.github/workflows/push_image.yml +++ b/.github/workflows/push_image.yml @@ -20,9 +20,26 @@ jobs: run: | docker build . -f Dockerfile.buildlocal -t builder docker run --rm -v ${PWD}:/project builder make + clang-format-examples: + runs-on: ubuntu-18.04 + steps: + - uses: actions/checkout@v2 + - name: clang-format + run: | + docker run --rm -v ${PWD}:/src wiiuenv/clang-format:13.0.0-2 -r ./example/example_module/source + build-examples: + runs-on: ubuntu-18.04 + needs: clang-format-examples + steps: + - uses: actions/checkout@v2 + - name: build binary + run: | + docker build . -f Dockerfile.buildexamples -t builder + cd ./example/example_module + docker run --rm -v ${PWD}:/project builder make push_image: runs-on: ubuntu-latest - needs: build-lib + needs: [build-lib, build-examples] steps: - uses: actions/checkout@master - name: Get release version diff --git a/Dockerfile.buildexamples b/Dockerfile.buildexamples new file mode 100644 index 0000000..44bcb21 --- /dev/null +++ b/Dockerfile.buildexamples @@ -0,0 +1,15 @@ +FROM wiiuenv/devkitppc:20211229 + +WORKDIR build +COPY . . +RUN make clean && make && mkdir -p /artifacts/wums && cp -r lib /artifacts/wums && cp -r include /artifacts/wums && cp -r share /artifacts/wums +WORKDIR /artifacts + +FROM scratch as libwums +COPY --from=0 /artifacts /artifacts + +FROM wiiuenv/devkitppc:20211229 + +COPY --from=libwums /artifacts $DEVKITPRO + +WORKDIR project diff --git a/README.MD b/README.MD index 77d0912..a041ec0 100644 --- a/README.MD +++ b/README.MD @@ -76,5 +76,5 @@ It's highly recommended to pin the version to the **latest date** instead of usi ## Format the code via docker ```bash -docker run --rm -v ${PWD}:/src wiiuenv/clang-format:13.0.0-2 -r ./include ./libraries -i +docker run --rm -v ${PWD}:/src wiiuenv/clang-format:13.0.0-2 -r ./include ./libraries ./example/example_module/source -i ``` diff --git a/example/example_module/.gitignore b/example/example_module/.gitignore new file mode 100644 index 0000000..ba57c28 --- /dev/null +++ b/example/example_module/.gitignore @@ -0,0 +1,10 @@ +*.cbp +*.elf +*.layout +*.rpx +build/ +*.save-failed +.idea/ +cmake-build-debug/ +CMakeLists.txt +*.wms diff --git a/example/example_module/Makefile b/example/example_module/Makefile new file mode 100644 index 0000000..29e3a67 --- /dev/null +++ b/example/example_module/Makefile @@ -0,0 +1,146 @@ +#------------------------------------------------------------------------------- +.SUFFIXES: +#------------------------------------------------------------------------------- + +ifeq ($(strip $(DEVKITPRO)),) +$(error "Please set DEVKITPRO in your environment. export DEVKITPRO=/devkitpro") +endif + +TOPDIR ?= $(CURDIR) + +include $(DEVKITPRO)/wums/share/wums_rules + +WUMS_ROOT := $(DEVKITPRO)/wums +WUT_ROOT := $(DEVKITPRO)/wut +#------------------------------------------------------------------------------- +# TARGET is the name of the output +# BUILD is the directory where object files & intermediate files will be placed +# SOURCES is a list of directories containing source code +# DATA is a list of directories containing data files +# INCLUDES is a list of directories containing header files +#------------------------------------------------------------------------------- +TARGET := ExampleModule +BUILD := build +SOURCES := source +DATA := data +INCLUDES := source + +#------------------------------------------------------------------------------- +# options for code generation +#------------------------------------------------------------------------------- +CFLAGS := -Wall -Wextra -O2 -ffunction-sections\ + $(MACHDEP) + +CFLAGS += $(INCLUDE) -D__WIIU__ -D__WUT__ + +CXXFLAGS := $(CFLAGS) -std=c++17 + +ASFLAGS := -g $(ARCH) +LDFLAGS = -g $(ARCH) $(RPXSPECS) -Wl,-Map,$(notdir $*.map) $(WUMSSPECS) + +ifeq ($(DEBUG),1) +CXXFLAGS += -DDEBUG -g +CFLAGS += -DDEBUG -g +endif + +LIBS := -lwums -lwut + +#------------------------------------------------------------------------------- +# list of directories containing libraries, this must be the top level +# containing include and lib +#------------------------------------------------------------------------------- +LIBDIRS := $(PORTLIBS) $(WUT_ROOT) $(WUMS_ROOT) + +#------------------------------------------------------------------------------- +# no real need to edit anything past this point unless you need to add additional +# rules for different file extensions +#------------------------------------------------------------------------------- +ifneq ($(BUILD),$(notdir $(CURDIR))) +#------------------------------------------------------------------------------- + +export OUTPUT := $(CURDIR)/$(TARGET) +export TOPDIR := $(CURDIR) + +export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ + $(foreach dir,$(DATA),$(CURDIR)/$(dir)) + +export DEPSDIR := $(CURDIR)/$(BUILD) + +CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) +CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) +SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) +BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) + +#------------------------------------------------------------------------------- +# use CXX for linking C++ projects, CC for standard C +#------------------------------------------------------------------------------- +ifeq ($(strip $(CPPFILES)),) +#------------------------------------------------------------------------------- + export LD := $(CC) +#------------------------------------------------------------------------------- +else +#------------------------------------------------------------------------------- + export LD := $(CXX) +#------------------------------------------------------------------------------- +endif +#------------------------------------------------------------------------------- + +export OFILES_BIN := $(addsuffix .o,$(BINFILES)) +export OFILES_SRC := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o) +export OFILES := $(OFILES_BIN) $(OFILES_SRC) +export HFILES_BIN := $(addsuffix .h,$(subst .,_,$(BINFILES))) + +export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ + $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ + -I$(CURDIR)/$(BUILD) + +export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) + +.PHONY: $(BUILD) clean all + +#------------------------------------------------------------------------------- +all: $(BUILD) + +$(BUILD): + @[ -d $@ ] || mkdir -p $@ + @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile + +#------------------------------------------------------------------------------- +clean: + @echo clean ... + @rm -fr $(BUILD) $(TARGET).wms $(TARGET).elf + +#------------------------------------------------------------------------------- +else +.PHONY: all + +DEPENDS := $(OFILES:.o=.d) + +#------------------------------------------------------------------------------- +# main targets +#------------------------------------------------------------------------------- +all : $(OUTPUT).wms + +$(OUTPUT).wms : $(OUTPUT).elf +$(OUTPUT).elf : $(OFILES) + +$(OFILES_SRC) : $(HFILES_BIN) + +#------------------------------------------------------------------------------- +# you need a rule like this for each extension you use as binary data +#------------------------------------------------------------------------------- +%.bin.o %_bin.h : %.bin +#------------------------------------------------------------------------------- + @echo $(notdir $<) + @$(bin2o) + +#--------------------------------------------------------------------------------- +%.o: %.s + @echo $(notdir $<) + @$(CC) -MMD -MP -MF $(DEPSDIR)/$*.d -x assembler-with-cpp $(ASFLAGS) -c $< -o $@ $(ERROR_FILTER) + +-include $(DEPENDS) + +#------------------------------------------------------------------------------- +endif +#------------------------------------------------------------------------------- diff --git a/example/example_module/source/main.cpp b/example/example_module/source/main.cpp new file mode 100644 index 0000000..3309648 --- /dev/null +++ b/example/example_module/source/main.cpp @@ -0,0 +1,39 @@ +#include +#include + +WUMS_MODULE_EXPORT_NAME("homebrew_examplemodule"); +WUMS_MODULE_AUTHOR("Maschell"); +WUMS_MODULE_VERSION("0.1"); +WUMS_MODULE_LICENSE("GPL"); +WUMS_MODULE_DESCRIPTION("Just an example module"); + +WUMS_INITIALIZE(/*wums_app_init_args_t*/ args) { + /* Called once when the module has been loaded */ + + // Information about the module can be get via the (optional) argument + module_information_t *module_information = args.module_information; + + if (module_information == nullptr) { + OSFatal("Failed to get module_information pointer."); + } + // Make sure the module is using a compatible version with the loader + if (module_information->version != MODULE_INFORMATION_VERSION) { + OSFatal("The module information struct version does not match."); + } +} + +WUMS_APPLICATION_STARTS() { + /* Called whenever a new application has been started */ +} + +WUMS_APPLICATION_REQUESTS_EXIT() { + /* Called whenever a application wants to exit */ +} + +WUMS_APPLICATION_ENDS() { + /* Called whenever a application actually ends */ +} + +WUMS_RELOCATIONS_DONE() { + /* Called whenever the relocations have been updated, but before WUMS_APPLICATION_STARTS() */ +} \ No newline at end of file