-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathMakefile
More file actions
164 lines (134 loc) · 6 KB
/
Copy pathMakefile
File metadata and controls
164 lines (134 loc) · 6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# Makefile for aura project
-include .config.mk
-include .local.mk
slugify = $(shell echo '$(1)' | tr '[:upper:]' '[:lower:]' | sed -E 's/[^a-z0-9]+/-/g' | sed 's/^-//;s/-$$//')
# Provide standard defaults - set overrides in .config.mk
SHELL=/bin/bash -o pipefail
TARGET_DIR = $(or $(CARGO_TARGET_DIR),target)
COVERAGE_DIR := report
REPORT_DIR = $(COVERAGE_DIR)/ci
AURA_AUTO_DOWNLOAD ?= true
CI ?=
BUILD_TAG ?= 1
IS_CI := $(if $(filter true, $(CI)), true,)
ALWAYS_TIMESTAMP_VERSION ?= false
APP_NAME ?= $(shell git remote -v 2>/dev/null | awk '/origin/ && /fetch/ { sub(/\.git/, ""); n=split($$2, origin, "/"); print origin[n]}')
## Define sources for rendering and templating
GIT_SHA1 ?= $(shell git log --pretty=format:'%h' -n 1 2>/dev/null)
GIT_BRANCH ?= $(shell git branch --show-current 2>/dev/null)
GIT_URL ?= $(shell git remote get-url origin 2>/dev/null)
GIT_INFO ?= $(TMP_DIR)/.git-info.$(GIT_SHA1)
BUILD_URL ?= localbuild://${USER}@$(shell uname -n | sed "s/'//g")
BUILD_DATESTAMP ?= $(shell date -u '+%Y%m%dT%H%M%SZ')
ENABLE_DOCKER ?=
TMP_DIR ?= tmp
BUILD_ENV ?= $(TMP_DIR)/build-env
VERSION_INFO ?= $(TMP_DIR)/version-info
PROJECT_ROOT := $(abspath $(dir $(lastword $(MAKEFILE_LIST))))
# Define commands via docker
DOCKER ?= docker
DOCKER_FILE := $(PROJECT_ROOT)/Dockerfile
DOCKER_RUN := $(DOCKER) run --rm -i
DOCKER_ENV = $(TARGET_DIR)/aura-env
# The env-file CARGO_HOME/RUSTUP_HOME paths are host-side and invalid inside
# the container, so pin them to the mounted workspace. -e overrides the
# env-file values.
RUNNER_TOOLCHAIN_ENV := -e CARGO_HOME=/home/aura/.cargo -e RUSTUP_HOME=/home/aura/.rustup
# Compiler-cache passthrough, gated on the CI toggle so local $(RUN) is
# unchanged. Bare -e copies AWS values from the host environment.
SCCACHE_RUN_ENV = $(if $(AURA_RUSTC_WRAPPER),-e RUSTC_WRAPPER=$(AURA_RUSTC_WRAPPER) -e SCCACHE_BUCKET -e SCCACHE_REGION -e SCCACHE_S3_KEY_PREFIX -e AWS_ACCESS_KEY_ID -e AWS_SECRET_ACCESS_KEY,)
# Native (non-Docker) builds run cargo directly in this process's environment,
# so translate the AURA_RUSTC_WRAPPER toggle into the RUSTC_WRAPPER cargo reads.
# The SCCACHE_* and AWS values are inherited from the host env alongside it.
# Docker builds inject the wrapper into the container via SCCACHE_RUN_ENV.
ifneq ($(filter true, $(ENABLE_DOCKER)),true)
ifneq ($(AURA_RUSTC_WRAPPER),)
RUSTC_WRAPPER := $(AURA_RUSTC_WRAPPER)
endif
endif
RUNNER_CMD = $(DOCKER_RUN) --env-file=$(DOCKER_ENV) $(RUNNER_TOOLCHAIN_ENV) $(SCCACHE_RUN_ENV) $(if $(filter true, $(IS_CI)), ,-t) -v $(PWD):/home/aura $(AURA_RUNNER_IMAGE)
RUNNER_NO_ENV_CMD = $(DOCKER_RUN) $(if $(filter true, $(IS_CI)),,-t) -v $(PWD):/home/aura $(AURA_RUNNER_IMAGE)
DOCKER_RUN_BUILD_ENV := $(RUNNER_CMD)
BUILD_SLUG := $(call slugify, $(BUILD_TAG))
AURA_RUNNER_IMAGE := local/aura-runner:$(BUILD_SLUG)
DIST_DIR ?= $(PROJECT_ROOT)/dist
RUN := $(if $(filter true, $(ENABLE_DOCKER)), $(RUNNER_CMD),)
RUN_NO_ENV := $(if $(filter true, $(ENABLE_DOCKER)), $(RUNNER_NO_ENV_CMD),)
# Handle versioning
ifeq ("$(VERSION_INFO)", "$(wildcard $(VERSION_INFO))")
# if tmp/version-info exists on disk, use it
include $(VERSION_INFO)
else
# Extract version from Cargo.toml
CARGO_VERSION := $(shell grep -m1 '^version' Cargo.toml | sed 's/version = "\(.*\)"/\1/')
BUILD_VERSION := $(CARGO_VERSION)-$(BUILD_DATESTAMP)
ifneq ("$(GIT_BRANCH)", $(filter "$(GIT_BRANCH)", "master" "main"))
# Feature branch - use timestamped version
RELEASE_VERSION := $(BUILD_VERSION)
else ifeq ("$(ALWAYS_TIMESTAMP_VERSION)", "true")
# Always use timestamp
RELEASE_VERSION := $(BUILD_VERSION)
else
# Release branch - use semantic version from Cargo.toml
RELEASE_VERSION := $(CARGO_VERSION)
endif
endif
# Exports the variables for shell use
export
# Source in repository specific environment variables
MAKEFILE_LIB ?= .makefiles
MAKEFILE_INCLUDES=$(wildcard $(MAKEFILE_LIB)/*.mk)
include $(MAKEFILE_INCLUDES)
$(BUILD_ENV):: $(GIT_INFO) $(VERSION_INFO)
@cat $(VERSION_INFO) $(GIT_INFO) | sort > $(@)
$(VERSION_INFO):: $(GIT_INFO)
@env | awk '!/TOKEN/ && /^(BUILD|CARGO_VERSION|RELEASE_VERSION)/ { print }' | sort > $(@)
$(GIT_INFO):: $(TMP_DIR)
@env | awk '!/TOKEN/ && /^(GIT)/ { print }' | sort > $(@)
$(TMP_DIR)::
@mkdir -p $(@)
$(TARGET_DIR):
@mkdir -p $(@)
# This helper function makes debugging much easier.
.PHONY:debug-%
debug-%: ## Debug a variable by calling `make debug-VARIABLE`
@echo $(*) = $($(*))
.PHONY:help
.SILENT:help
help: ## Show this help, includes list of all actions.
@awk 'BEGIN {FS = ":.*?## "}; /^.+: .*?## / && !/awk/ {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' ${MAKEFILE_LIST}
.PHONY:build
build:: $(BUILD_ENV) ## Build all workspace binaries
.PHONY:test
test:: ## Run all tests targets
.PHONY:setup
setup:: ## Setup local depencies for development
.PHONY:fmt
fmt:: ## Format code with rustfmt
cargo fmt --all
.PHONY:fmt-check
fmt-check:: ## Check code formatting (CI)
cargo fmt --all -- --check
.PHONY:lint
lint:: ## Apply all lint targets
.PHONY:ci
ci:: fmt-check test lint ## Run CI checks locally (fmt + test + lint)
@echo "✅ All CI checks passed!"
.PHONY:clean
clean:: ## Cleanup the local checkout
.PHONY:docker-build
docker-build:: ## Build Docker image (full release)
$(DOCKER) build -t $(APP_NAME):latest .
.PHONY:docker-test
docker-test:: ## Run Docker build with test stage (base)
$(DOCKER) build --target lint-test -t $(APP_NAME):test .
.PHONY:docker-build-release
docker-build-release:: ## Build Docker release stage only
$(DOCKER) build --target release -t $(APP_NAME):$(RELEASE_VERSION) .
.PHONY:publish
publish:: ## Placeholder for publishing artifacts
$(DOCKER_ENV): $(TARGET_DIR) $(REPORT_DIR) ## Set up docker info
@env | awk '!/TOKEN|KEY/ && /^(AURA_|CI|LLVM|RUST|GRCOV|CARGO|NEXTEST)/ { print }' | sort > $(@)
.PHONY:version
version:: ## Show version information
@MAKEFLAGS+=--no-print-directory $(MAKE) debug-RELEASE_VERSION debug-BUILD_VERSION debug-GIT_SHA1 debug-GIT_BRANCH