Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rewrite external projects support #1847

Merged
merged 16 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 43 additions & 31 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,46 @@ jobs:
MAKEFLAGS: 'OUTPUT_DIR=build'

steps:

# Install dependencies. {{{

- name: XCode version
run: xcode-select -p

- name: Install dependencies
run: |
wget -O ninjatracing.zip https://github.com/nico/ninjatracing/archive/a669e3644cf22b29cbece31dbed2cfbf34e5f48e.zip
unzip -j ninjatracing.zip '*/ninjatracing'
install -m755 ninjatracing /usr/local/bin/
rm ninjatracing*
packages=(
autoconf
automake
binutils
cmake
coreutils
findutils
jq
libtool
make
nasm
ninja
pkg-config
sdl2
util-linux
)
brew install --formula --quiet "${packages[@]}"

- name: Update PATH
run: >
printf '%s\n'
"$(brew --prefix)/opt/findutils/libexec/gnubin"
"$(brew --prefix)/opt/make/libexec/gnubin"
"$(brew --prefix)/opt/util-linux/bin"
| tee "${GITHUB_PATH}"

# }}}

# Checkout / fetch. {{{

- name: Checkout
Expand Down Expand Up @@ -81,42 +118,17 @@ jobs:

# }}}

# Install dependencies. {{{

- name: Setup Python
if: steps.ccache-restore.outputs.cache-hit != 'true'
uses: actions/setup-python@v5
with:
# Note: Python 3.12 removal of `distutils` breaks GLib's build.
python-version: '3.11'

- name: Install homebrew dependencies
if: steps.ccache-restore.outputs.cache-hit != 'true'
run: |
packages=(
nasm binutils coreutils libtool autoconf automake cmake make
sdl2 gettext pkg-config wget gnu-getopt grep ninja
)
brew install --formula --quiet "${packages[@]}"

- name: Update PATH
if: steps.ccache-restore.outputs.cache-hit != 'true'
run: >
printf '%s\n'
"$(brew --prefix)/opt/gettext/bin"
"$(brew --prefix)/opt/gnu-getopt/bin"
"$(brew --prefix)/opt/grep/libexec/gnubin"
"$(brew --prefix)/opt/make/libexec/gnubin"
| tee "${GITHUB_PATH}"

# }}}

# Build. {{{

- name: Build
id: build
if: steps.ccache-restore.outputs.cache-hit != 'true'
run: make

- name: Dump build timings
if: contains('failure success', steps.build.conclusion) && !cancelled()
run: make buildstats

- name: Dump binaries runtime path & dependencies
if: steps.ccache-restore.outputs.cache-hit != 'true'
run: make bindeps
Expand All @@ -126,7 +138,7 @@ jobs:
# Clean / save caches. {{{

- name: Clean build cache
if: steps.ccache-restore.outputs.cache-hit != 'true' && always()
if: contains('failure success', steps.build.conclusion) && !cancelled()
run: |
set -x
ccache --cleanup >/dev/null
Expand Down
49 changes: 35 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ include Makefile.defs
DO_STRIP := $(if $(or $(EMULATE_READER),$(KODEBUG)),,1)
DO_STRIP := $(if $(or $(DO_STRIP),$(APPIMAGE),$(LINUX)),1,)

define build_info
$(info ************ Building for MACHINE: "$(MACHINE)" **********)
$(info ************ PATH: "$(PATH)" **********)
$(info ************ CHOST: "$(CHOST)" **********)
$(info ************ NINJA: $(strip $(NINJA) $(PARALLEL_JOBS:%=-j%) $(PARALLEL_LOAD:%=-l%)) **********)
$(info ************ MAKE: $(strip $(MAKE) $(PARALLEL_JOBS:%=-j%) $(PARALLEL_LOAD:%=-l%)) **********)
endef

PHONY = all bindeps clean distclean fetchthirdparty libcheck %-re re setup skeleton test test-data
PHONY = all bindeps buildstats clean distclean fetchthirdparty info libcheck %-re re reinstall setup skeleton test test-data uninstall

.PHONY: $(PHONY)

Expand All @@ -28,47 +30,51 @@ clean:
distclean:
rm -rf build $(wildcard $(THIRDPARTY_DIR)/*/build)

info:
$(strip $(build_info))

re: clean
$(MAKE) all

%-re:
$(MAKE) $*-clean
$(MAKE) $*

setup: $(BUILD_ENTRYPOINT)

fetchthirdparty:
git submodule init
git submodule sync
git submodule update --jobs 3 $(if $(CI),--depth 1)

reinstall: uninstall
$(MAKE)

uninstall:
rm -vrf $(filter-out $(CMAKE_DIR) $(OUTPUT_DIR)/thirdparty,$(wildcard $(OUTPUT_DIR)/*))
$(MAKE) rm-install-stamps

# }}}

# CMake build interface. {{{

$(BUILD_ENTRYPOINT): $(CMAKE_KOVARS) $(CMAKE_TCF)
setup $(BUILD_ENTRYPOINT): $(CMAKE_KOVARS) $(CMAKE_TCF)
$(strip $(build_info))
$(CMAKE) $(CMAKE_FLAGS) -S cmake -B $(CMAKE_DIR)

define newline


endef

define escape
'$(subst $(newline),' ',$(subst ','"'"',$(call $1)))'
define write_file
$(if $(DRY_RUN),: write $1,$(file >$1,$2))
endef

$(CMAKE_KOVARS): Makefile.defs | $(CMAKE_DIR)/
@printf '%s\n' $(call escape,cmake_koreader_vars) >'$@'
$(call write_file,$@,$(cmake_koreader_vars))

$(CMAKE_TCF): Makefile.defs | $(CMAKE_DIR)/
@printf '%s\n' $(call escape,$(if $(EMULATE_READER),cmake_toolchain,cmake_cross_toolchain)) >'$@'
$(call write_file,$@,$(if $(EMULATE_READER),$(cmake_toolchain),$(cmake_cross_toolchain)))

# Forward unknown targets to the CMake build system.
LEFTOVERS = $(filter-out $(PHONY) cache-key build/%,$(MAKECMDGOALS))
.PHONY: $(LEFTOVERS)
all $(LEFTOVERS): skeleton $(BUILD_ENTRYPOINT)
$(and $(DRY_RUN),$(wildcard $(BUILD_ENTRYPOINT)),+)$(strip $(CMAKE_MAKE_PROGRAM) -C $(CMAKE_DIR) $@)
$(and $(DRY_RUN),$(wildcard $(BUILD_ENTRYPOINT)),+)cd $(CMAKE_DIR) && $(strip $(NINJA) $(NINJAFLAGS) $@)

# }}}

Expand Down Expand Up @@ -166,6 +172,21 @@ bindeps:

# }}}

# Dump build timings for last ninja invocation. {{{

# Show external project tasks with a duration of 1s or more (descending order).
define buildstats_jq_script
sort_by(-.dur) | .[] | select(.dur >= 1e6) | (.dur*1e-5 | round | ./10), "\n",
(.name | sub("(.*[/ ])?(?<p>[^/]*)/stamp/(?<t>[^/]*)$$"; "\(.p) \(.t)")), "\n"
endef

buildstats: $(CMAKE_DIR)/.ninja_log
ninjatracing $< | jq -j '$(strip $(buildstats_jq_script))' | \
xargs -n3 printf '%6.2fs %s %s\n' | \
git column --mode=row

# }}}

# Checking libraries for missing dependencies. {{{

# NOTE: the extra `$(filter %/,…)` is to work around some older versions
Expand Down
57 changes: 20 additions & 37 deletions Makefile.defs
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
ifneq (4.1,$(firstword $(sort $(MAKE_VERSION) 4.1)))
$(error you're version of make is too old: $(MAKE_VERSION), need at least 4.1)
benoit-pierre marked this conversation as resolved.
Show resolved Hide resolved
endif

# Note: ensure our possibly updated `PATH` variable is picked up by
# `$(shell …)` invocations when using older (<4.4) make versions.
SHELL = env PATH='$(PATH)' bash -eo pipefail
ifeq (,$(filter shell-export,$(.FEATURES)))
SHELL = env PATH='$(PATH)' bash -eo pipefail
else
SHELL = bash -eo pipefail
endif

ifeq (,$(V)$(VERBOSE))
.SILENT:
endif

ifeq (,$(PARALLEL_JOBS))
PARALLEL_JOBS := $(or $(patsubst -j%,%,$(filter -j%,$(MAKEFLAGS))))
Expand Down Expand Up @@ -36,9 +48,6 @@ else
CCACHE := $(or $(CCACHE),$(shell command -v ccache))
endif

UNAME:=$(shell uname -s)
UNAME_ARCH:=$(shell uname -m)

# Should point at the actual directory in which *this* makefile resides, as opposed to $(CURDIR),
# which is simply $PWD *at the time of the original make call*, which is not necessarily the same thing.
# NOTE: Will only behave as long as there aren't any spaces in the paths involved!
Expand Down Expand Up @@ -71,16 +80,7 @@ endif

# CMAKE:=cmake --no-warn-unused-cli
CMAKE := cmake

ifeq ($(NINJA),)
NINJA := $(shell command -v ninja)
endif

ifneq ($(NINJA),)
ifeq ($(USE_MAKE),)
USE_NINJA := 1
endif
endif
NINJA := $(or $(NINJA),ninja)

ifneq (,$(or $(VERBOSE),$(V)))
ifeq (4.4,$(firstword $(sort $(MAKE_VERSION) 4.4)))
Expand All @@ -89,6 +89,7 @@ ifneq (,$(or $(VERBOSE),$(V)))
MAKEFLAGS += --trace
endif
NINJAFLAGS += -v
export KOVERBOSE=1
endif
ifneq (,$(PARALLEL_JOBS))
NINJAFLAGS += -j$(PARALLEL_JOBS)
Expand All @@ -106,23 +107,15 @@ ifneq (,$(DRY_RUN))
endif

ifneq ($(or $(CLICOLOR_FORCE),$(MAKE_TERMOUT)),)
export CLICOLOR_FORCE=1
NINJA_STATUS := $(shell printf '\33[32;1m▸%%p\33[0m | ')
else
NINJA_STATUS := $(empty) %p | $(empty)
endif
export NINJA_STATUS
export NINJAFLAGS

ifneq ($(USE_NINJA),)
CMAKE_FLAGS = -G Ninja
CMAKE_MAKE_PROGRAM = $(NINJA) $(NINJAFLAGS)
else
CMAKE_FLAGS = -DCMAKE_TARGET_MESSAGES:BOOL=OFF
CMAKE_MAKE_PROGRAM = $(abspath $(THIRDPARTY_DIR)/cmake_modules/komake.sh) $(MAKE)
ifeq (,$(or $(VERBOSE),$(V)))
CMAKE_MAKE_PROGRAM += --no-print-directory
endif
endif
CMAKE_FLAGS = -G Ninja

# set this to your ARM cross compiler:
# set CC CXX AR LD RANLIB
Expand Down Expand Up @@ -241,9 +234,9 @@ else
$(error Invalid TARGET: "$(TARGET)")
endif

ifneq (,$(filter $(UNAME), Darwin))
ifneq (,$(findstring darwin,$(MAKE_HOST)))
DARWINHOST=1
ifneq (,$(filter $(UNAME_ARCH), arm64))
ifneq (,$(findstring aarch64,$(MAKE_HOST)))
DARWIN_AARCH64_HOST=1
endif
ifdef EMULATE_READER
Expand Down Expand Up @@ -286,12 +279,6 @@ endef
# ln --symbolic --no-dereference --force --relative
SYMLINK = ln -snf$(if $(DARWINHOST),,r)

# unknown device
ifdef SBOX_UNAME_MACHINE
CC:=gcc
CXX:=g++
endif

# set cross-compiler/host CC and CXX
ifneq (,$(findstring clang, $(CC)))
ifdef CHOST
Expand Down Expand Up @@ -643,11 +630,7 @@ OUTPUT_DIR ?= build/$(MACHINE)
CMAKE_DIR = $(OUTPUT_DIR)/cmake
STAGING_DIR = $(OUTPUT_DIR)/staging

ifneq ($(USE_NINJA),)
BUILD_ENTRYPOINT = $(CMAKE_DIR)/build.ninja
else
BUILD_ENTRYPOINT = $(CMAKE_DIR)/Makefile
endif
BUILD_ENTRYPOINT = $(CMAKE_DIR)/build.ninja

# you can configure an emulation for the (eink) framebuffer here.
# the application won't use the framebuffer (and the special e-ink ioctls)
Expand Down
Loading