From 6fb37c1e64ac8b0effe810f61eda8c6bd6ce58f1 Mon Sep 17 00:00:00 2001 From: Tommaso Negri Date: Fri, 28 Aug 2026 10:02:40 +0200 Subject: improve Makefile --- .gitignore | 2 +- Makefile | 72 ++++++++++++------------------------------- Sources/bar/bar.docc/Makefile | 55 +++++++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+), 54 deletions(-) create mode 100644 Sources/bar/bar.docc/Makefile diff --git a/.gitignore b/.gitignore index 3f976de..0d82c93 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,7 @@ .DS_Store /.build /.docc-build -/docs +/.docs /Packages xcuserdata/ DerivedData/ diff --git a/Makefile b/Makefile index 57bbcb7..e68fc3a 100644 --- a/Makefile +++ b/Makefile @@ -1,62 +1,28 @@ -PREFIX ?= $(HOME)/.local/bin +PREFIX ?= $(HOME)/.local -# Auto-detect docc binary: prefer standalone, fall back to xcrun -DOCC := $(shell which docc 2>/dev/null || echo "xcrun docc") +.PHONY: build +build: .build/release/bar -# Derive the build triple from the bin path (e.g., arm64-apple-macosx) -BUILD_DIR := $(shell swift build -c debug --show-bin-path 2>/dev/null) -TRIPLE := $(notdir $(patsubst %/,%,$(dir $(BUILD_DIR)))) -MODULE_DIR := .build/$(TRIPLE)/debug/Modules -SYMBOL_GRAPH_DIR := .build/$(TRIPLE)/symbolgraph - -.DEFAULT_GOAL := all - -all: run - -run: - swift run -c debug - -build: - swift build -c debug - -release: +.build/release/bar: swift build -c release -install: release - install -d $(PREFIX) - install ".build/release/bar" "$(PREFIX)/bar" - -uninstall: - rm -f "$(PREFIX)/bar" - +.PHONY: clean clean: - rm -rf .build .docc-build docs + @rm -rf .build .docc-build .docs -# Build the project and generate symbol graphs (prerequisite for docc targets) -# Uses -minimum-access-level internal to capture doc-commented types even when they aren't public -symbol-graphs: build - mkdir -p $(SYMBOL_GRAPH_DIR) - xcrun swift-symbolgraph-extract \ - -module-name bar \ - -target $(TRIPLE)26.0 \ - -sdk $(shell xcrun --show-sdk-path 2>/dev/null) \ - -minimum-access-level internal \ - -I $(MODULE_DIR) \ - -output-dir $(SYMBOL_GRAPH_DIR) +.PHONY: install +install: build + @install -d $(PREFIX)/bin/ + @install -Dm755 .build/release/bar $(PREFIX)/bin/ -preview-docs: symbol-graphs - $(DOCC) preview Sources/bar/bar.docc \ - --additional-symbol-graph-dir $(SYMBOL_GRAPH_DIR) \ - --output-dir .docc-build +.PHONY: uninstall +uninstall: + @rm -f $(PREFIX)/bin/bar -generate-docs: symbol-graphs - $(DOCC) convert Sources/bar/bar.docc \ - --additional-symbol-graph-dir $(SYMBOL_GRAPH_DIR) \ - --transform-for-static-hosting \ - --hosting-base-path bar \ - --output-path ./docs \ - --source-service github \ - --source-service-base-url https://github.com/paninihouse/bar/blob/master \ - --checkout-path ~/Developer/paninihouse/tools/bar/ +.PHONY: docs +docs: .build/release/bar + @$(MAKE) -C Sources/bar/bar.docc build -.PHONY: all run build release install uninstall clean symbol-graphs preview-docs generate-docs +.PHONY: docs-preview +docs-preview: .build/release/bar + @$(MAKE) -C Sources/bar/bar.docc preview diff --git a/Sources/bar/bar.docc/Makefile b/Sources/bar/bar.docc/Makefile new file mode 100644 index 0000000..5b6bcac --- /dev/null +++ b/Sources/bar/bar.docc/Makefile @@ -0,0 +1,55 @@ +MODULE := bar + +# Auto-detect docc binary: prefer standalone, fall back to xcrun +DOCC := $(shell which docc 2>/dev/null || echo "xcrun docc") + +# Resolve paths relative to the package root, regardless of where make is invoked. +PKG_ROOT := $(abspath $(dir $(firstword $(MAKEFILE_LIST)))/../../..) + +# SwiftPM emits symbol graphs for every module in the dependency graph. docc +# would then process dependency symbols too (e.g. FuzzyMatch), producing +# unrelated warnings. We emit into a staging dir and copy only our module's +# graphs into the directory docc actually reads. +SYMBOL_GRAPH_DIR := $(PKG_ROOT)/.build/symbolgraph +SYMBOL_GRAPH_STAGE := $(PKG_ROOT)/.build/symbolgraph-stage +DOCC_SOURCE := $(PKG_ROOT)/Sources/$(MODULE)/$(MODULE).docc + +.DEFAULT_GOAL := build + +# Build the project and emit symbol graphs via SwiftPM itself. +# This works for executable targets (which don't always emit a standalone +# .swiftmodule into the Modules dir), unlike invoking swift-symbolgraph-extract +# directly with -I . +.PHONY: symbol-graphs +symbol-graphs: + swift package --package-path $(PKG_ROOT) clean + rm -rf $(SYMBOL_GRAPH_DIR) $(SYMBOL_GRAPH_STAGE) + mkdir -p $(SYMBOL_GRAPH_STAGE) + swift build \ + --package-path $(PKG_ROOT) \ + -Xswiftc -emit-symbol-graph \ + -Xswiftc -emit-symbol-graph-dir \ + -Xswiftc $(SYMBOL_GRAPH_STAGE) \ + -Xswiftc -symbol-graph-minimum-access-level \ + -Xswiftc internal + mkdir -p $(SYMBOL_GRAPH_DIR) + cp $(SYMBOL_GRAPH_STAGE)/$(MODULE).symbols.json $(SYMBOL_GRAPH_STAGE)/$(MODULE)@*.symbols.json $(SYMBOL_GRAPH_DIR)/ + +.PHONY: preview +preview: symbol-graphs + $(DOCC) preview $(DOCC_SOURCE) \ + --additional-symbol-graph-dir $(SYMBOL_GRAPH_DIR) \ + --fallback-default-module-kind Tool \ + --output-dir $(PKG_ROOT)/.docc-build + +.PHONY: build +build: symbol-graphs + $(DOCC) convert $(DOCC_SOURCE) \ + --additional-symbol-graph-dir $(SYMBOL_GRAPH_DIR) \ + --fallback-default-module-kind Tool \ + --transform-for-static-hosting \ + --hosting-base-path $(MODULE) \ + --output-path $(PKG_ROOT)/.docs \ + --source-service github \ + --source-service-base-url https://github.com/paninihouse/$(MODULE)/blob/master \ + --checkout-path ~/Developer/paninihouse/tools/$(MODULE)/ -- cgit v1.2.3