From 8159137f8b89192f631f7c51f3ad075c24fc2a16 Mon Sep 17 00:00:00 2001 From: Eric Coissac Date: Tue, 1 Dec 2026 11:13:02 +0100 Subject: [PATCH] chore: add crate-kit build system and CeCILL license Introduce the `.crate-kit` infrastructure to standardize build, testing, and release workflows using Jujutsu and Cargo. Add CeCILL-2.1 license files and update all workspace crate manifests with license and repository metadata. - Add `.crate-kit/` directory with `VERSION`, `crate.mk`, `dev-patch.mk`, `jj.mk`, and `org.mk` to define build targets, Jujutsu helpers, and registry configuration for the workspace. - Add 21 shell scripts in `.crate-kit/scripts/` for API tracking, dependency checking, version bumping, publishing, tagging, and wiki generation, including `common.sh` with shared utility functions. - Add `scripts/jj-tag.sh` to support tagging commits with version strings derived from the current crate version. - Add `LICENSE` and `LICENSE.en` files containing the CeCILL-2.1 free software license agreement in French and English. - Update `Makefile` with new targets for building, testing, formatting, CI, and releasing, integrating with `.crate-kit` scripts and updating the wiki directory path to `obiskim`. - Update `.gitignore` to ignore `.cargo/config.toml` files generated by the development patch system. - Add `license = "CECILL-2.1"` and `repository = "https://forge.metabarcoding.org/obi/obiskim"` to all `Cargo.toml` files in the workspace, including `obicompactvec`, `obidebruinj`, `obifastwrite`, `obikalgorithm`, `obikdump`, `obikentropy`, `obikfilter`, `obikidxcache`, `obikindex`, `obikindexer`, `obikmer`, `obikmerge`, `obikphylo`, `obikquery`, `obikrebuild`, `obikrope`, `obikselect`, `obikseq`, `obiksession`, `obikstats`, `obipipeline`, `obiread`, `obiskbuilder`, `obiskio`, `obisys`, and `obitaxonomy`. - Update `src/obikrope/Cargo.toml` to use `criterion2` version 3 with the `cargo_bench_support` feature. - Update `src/obikseq/Cargo.toml` to replace the "OnceLock-based params" feature with a new feature description involving thread-local storage. - Update `src/Cargo.lock` to reflect the version bump of `obikmer` from 1.4.7 to 1.4.8. --- .crate-kit/VERSION | 1 + .crate-kit/crate.mk | 240 ++++++++++ .crate-kit/dev-patch.mk | 42 ++ .crate-kit/jj.mk | 22 + .crate-kit/kinds/crate.mk | 3 + .crate-kit/org.mk | 9 + .crate-kit/scripts/api-level.sh | 96 ++++ .crate-kit/scripts/api-snapshot.sh | 20 + .crate-kit/scripts/bookmark-check.sh | 14 + .crate-kit/scripts/bump-version.sh | 67 +++ .crate-kit/scripts/common.sh | 266 +++++++++++ .crate-kit/scripts/deps-check-external.sh | 193 ++++++++ .crate-kit/scripts/deps-check.sh | 166 +++++++ .crate-kit/scripts/deps-lib.sh | 75 +++ .crate-kit/scripts/dev-patch.sh | 70 +++ .crate-kit/scripts/forgejo-release.sh | 56 +++ .crate-kit/scripts/jjfetch.sh | 74 +++ .crate-kit/scripts/kit-check.sh | 68 +++ .crate-kit/scripts/needs-commit.sh | 77 +++ .crate-kit/scripts/new-commit.sh | 14 + .crate-kit/scripts/publish-guard.sh | 12 + .crate-kit/scripts/publish.sh | 38 ++ .crate-kit/scripts/push-main.sh | 16 + .crate-kit/scripts/release-notes.sh | 24 + .crate-kit/scripts/tag-exists.sh | 17 + .crate-kit/scripts/tag.sh | 20 + .crate-kit/scripts/wiki.sh | 141 ++++++ .gitignore | 3 + LICENSE | 550 ++++++++++++++++++++++ LICENSE.en | 519 ++++++++++++++++++++ Makefile | 137 +++++- scripts/jj-tag.sh | 15 + src/Cargo.lock | 2 +- src/obicompactvec/Cargo.toml | 2 + src/obidebruinj/Cargo.toml | 2 + src/obifastwrite/Cargo.toml | 2 + src/obikalgorithm/Cargo.toml | 2 + src/obikdump/Cargo.toml | 2 + src/obikentropy/Cargo.toml | 2 + src/obikfilter/Cargo.toml | 2 + src/obikidxcache/Cargo.toml | 2 + src/obikindex/Cargo.toml | 2 + src/obikindexer/Cargo.toml | 2 + src/obikmer/Cargo.toml | 2 + src/obikmerge/Cargo.toml | 2 + src/obikphylo/Cargo.toml | 2 + src/obikquery/Cargo.toml | 2 + src/obikrebuild/Cargo.toml | 2 + src/obikrope/Cargo.toml | 2 + src/obikselect/Cargo.toml | 2 + src/obikseq/Cargo.toml | 2 + src/obiksession/Cargo.toml | 2 + src/obikstats/Cargo.toml | 2 + src/obipipeline/Cargo.toml | 2 + src/obiread/Cargo.toml | 2 + src/obiskbuilder/Cargo.toml | 2 + src/obiskio/Cargo.toml | 2 + src/obisys/Cargo.toml | 2 + src/obitaxonomy/Cargo.toml | 2 + 59 files changed, 3102 insertions(+), 17 deletions(-) create mode 100644 .crate-kit/VERSION create mode 100644 .crate-kit/crate.mk create mode 100644 .crate-kit/dev-patch.mk create mode 100644 .crate-kit/jj.mk create mode 100644 .crate-kit/kinds/crate.mk create mode 100644 .crate-kit/org.mk create mode 100755 .crate-kit/scripts/api-level.sh create mode 100755 .crate-kit/scripts/api-snapshot.sh create mode 100755 .crate-kit/scripts/bookmark-check.sh create mode 100755 .crate-kit/scripts/bump-version.sh create mode 100755 .crate-kit/scripts/common.sh create mode 100755 .crate-kit/scripts/deps-check-external.sh create mode 100755 .crate-kit/scripts/deps-check.sh create mode 100644 .crate-kit/scripts/deps-lib.sh create mode 100755 .crate-kit/scripts/dev-patch.sh create mode 100755 .crate-kit/scripts/forgejo-release.sh create mode 100755 .crate-kit/scripts/jjfetch.sh create mode 100755 .crate-kit/scripts/kit-check.sh create mode 100755 .crate-kit/scripts/needs-commit.sh create mode 100755 .crate-kit/scripts/new-commit.sh create mode 100755 .crate-kit/scripts/publish-guard.sh create mode 100755 .crate-kit/scripts/publish.sh create mode 100755 .crate-kit/scripts/push-main.sh create mode 100755 .crate-kit/scripts/release-notes.sh create mode 100755 .crate-kit/scripts/tag-exists.sh create mode 100755 .crate-kit/scripts/tag.sh create mode 100755 .crate-kit/scripts/wiki.sh create mode 100644 LICENSE create mode 100644 LICENSE.en create mode 100755 scripts/jj-tag.sh diff --git a/.crate-kit/VERSION b/.crate-kit/VERSION new file mode 100644 index 00000000..ccd34e0b --- /dev/null +++ b/.crate-kit/VERSION @@ -0,0 +1 @@ +0.3.3+0.1.1 diff --git a/.crate-kit/crate.mk b/.crate-kit/crate.mk new file mode 100644 index 00000000..88146c5e --- /dev/null +++ b/.crate-kit/crate.mk @@ -0,0 +1,240 @@ +# crate-kit: common targets for the crates of a multi-crate Rust project. +# +# This directory (.crate-kit/) is a COPY of the kit/ folder of the crate-kit repository: do not +# modify it here, fix it in crate-kit then run `make kit-update`. +# +# Usage, in the crate's Makefile: +# RELEASE_PROJECT_DESC = acmexxx (short description) # optional +# include .crate-kit/crate.mk +# +# Adjustable variables (before the include or on the command line): +# CARGO, CARGO_TOML, FEATURES, API_DIR, RELEASE_NOTES_DIR, REGISTRY, KIT_SRC +# KIT_LANG language of LLM-generated documents (default en; any language name or ISO code) +# RELEASE=x.y.z forces the version of bump-version / jjrelease +# DRY_RUN=1 publish: checks the package without sending it +# +# Crate kind: CRATE_KIND (default "crate"). kinds/.mk sets, before the targets, the generic variables +# that the kit reads: BUILD_TARGET (--target of the builds), EXTRA_TARGETS (targets that check and clippy +# go through in addition to the host), PUBLISH, API_TRACKED, WIKI (yes|no: publication to the registry, +# API snapshot and version verdict, wiki), AFTER_RELEASE (command run after the tag). A kind +# can also add its own targets. Kinds specific to an organization come from its overlay (org.mk +# sets REGISTRY and REGISTRY_INDEX); see tools/kit-assemble.sh. + +KIT_DIR := $(patsubst %/,%,$(dir $(lastword $(MAKEFILE_LIST)))) +KIT_SRC ?= ../crate-kit + +CARGO ?= cargo +CARGO_TOML ?= Cargo.toml +FEATURES ?= +API_DIR ?= api +RELEASE_NOTES_DIR ?= ReleaseNotes +CRATE_KIND ?= crate +BUILD_TARGET ?= +PUBLISH ?= yes +API_TRACKED ?= yes +WIKI ?= yes +AFTER_RELEASE ?= +# Additional targets that check and clippy go through (e.g. EXTRA_TARGETS = wasm32-unknown-unknown). +EXTRA_TARGETS ?= +RELEASE_PROJECT_DESC ?= $(shell sed -n 's/^name = "\(.*\)"/\1/p' $(CARGO_TOML) | head -n 1) + + +GREEN = \033[0;32m +YELLOW = \033[1;33m +BLUE = \033[1;34m +NC = \033[0m + +include $(KIT_DIR)/dev-patch.mk +include $(KIT_DIR)/jj.mk + +# Language of the documents an LLM generates (release notes). Default English; an extension kit +# overrides it in its org.mk (KIT_LANG ?= fr), included above, or the user on the command line. +KIT_LANG ?= en +# Language of the commit messages written by `jj auto-doc` (pmojj reads PMOJJ_LANG). +export PMOJJ_LANG = $(KIT_LANG) + +ifeq ($(wildcard $(KIT_DIR)/kinds/$(CRATE_KIND).mk),) +$(error unknown crate kind: CRATE_KIND = $(CRATE_KIND) (kinds: $(patsubst $(KIT_DIR)/kinds/%.mk,%,$(wildcard $(KIT_DIR)/kinds/*.mk)))) +endif +include $(KIT_DIR)/kinds/$(CRATE_KIND).mk +export KIT_LANG CARGO CARGO_TOML API_DIR RELEASE_NOTES_DIR REGISTRY RELEASE_PROJECT_DESC KIT_SRC CRATE_KIND PUBLISH API_TRACKED WIKI + +.DEFAULT_GOAL := build + +.PHONY: help build release debug test test-doc doc doc-build clean check fmt fmt-check clippy \ + watch ci deps update bench coverage bump-version api-level api-snapshot publish wiki \ + jjnew jjpush jjfetch jjrelease bookmark-check kit-check needs-commit kit-update kit-version + +help: + @echo "$(GREEN)Available commands:$(NC)" + @sed -n "s/^## *\([^:]*\): */\1$$(printf '\t')/p" $(MAKEFILE_LIST) | column -t -s "$$(printf '\t')" | sed -e 's/^/ /' + +## build: Release build (alias of release) +build: release + +## release: Release build (the kind's BUILD_TARGET, if it sets one) +release: + @echo "$(YELLOW)→ Building (release)...$(NC)" + $(CARGO) build --release $(if $(BUILD_TARGET),--target $(BUILD_TARGET)) $(FEATURES) + @echo "$(GREEN)✓ Build finished$(NC)" + +## debug: Debug build (the kind's BUILD_TARGET, if it sets one) +debug: + @echo "$(YELLOW)→ Building (debug)...$(NC)" + $(CARGO) build $(if $(BUILD_TARGET),--target $(BUILD_TARGET)) $(FEATURES) + @echo "$(GREEN)✓ Build finished$(NC)" + +## test: All tests +test: + @echo "$(YELLOW)→ Running the tests...$(NC)" + $(CARGO) test --all --all-features + @echo "$(GREEN)✓ Tests finished$(NC)" + +## test-doc: Documentation example tests +test-doc: + @echo "$(YELLOW)→ Testing the documentation examples...$(NC)" + $(CARGO) test --doc --all-features + @echo "$(GREEN)✓ Documentation tests finished$(NC)" + +## doc: Generates the documentation and opens it +doc: + @echo "$(YELLOW)→ Generating the documentation...$(NC)" + $(CARGO) doc --no-deps --document-private-items --all-features --open + +## doc-build: Generates the documentation without opening it +doc-build: + @echo "$(YELLOW)→ Generating the documentation...$(NC)" + $(CARGO) doc --no-deps --document-private-items --all-features + +## clean: Cleanup +clean: + @echo "$(YELLOW)→ Cleaning...$(NC)" + $(CARGO) clean + +## check: Code check (host, then EXTRA_TARGETS) +check: + @$(KIT_DIR)/scripts/publish-guard.sh + @echo "$(YELLOW)→ Checking the code...$(NC)" + $(CARGO) check --all + @for t in $(EXTRA_TARGETS); do $(CARGO) check --all --target $$t || exit 1; done + @echo "$(GREEN)✓ Code valid$(NC)" + +## fmt: Code formatting +fmt: + $(CARGO) fmt --all + +## fmt-check: Formatting check +fmt-check: + $(CARGO) fmt --all -- --check + +## clippy: Static analysis on the host then EXTRA_TARGETS (warnings = errors) +clippy: + @echo "$(YELLOW)→ Analysing with clippy...$(NC)" + $(CARGO) clippy --all-targets --all-features -- -D warnings + @for t in $(EXTRA_TARGETS); do $(CARGO) clippy --lib --all-features --target $$t -- -D warnings || exit 1; done + @echo "$(GREEN)✓ Clippy analysis finished$(NC)" + +## watch: Continuous check +watch: + $(CARGO) watch -x check + +## ci: Verification pipeline (deps-check fmt-check clippy test doc-build) +ci: deps-check fmt-check clippy test doc-build + @echo "$(GREEN)✓ All CI checks passed$(NC)" + +## deps: Outdated dependencies +deps: + $(CARGO) outdated + +## update: Updates the dependencies +update: + $(CARGO) update + +## bench: Benchmarks +bench: + $(CARGO) bench + +## coverage: Coverage report (cargo-llvm-cov) +coverage: + @echo "$(YELLOW)→ Generating the coverage report...$(NC)" + @mkdir -p target/coverage + $(CARGO) llvm-cov --json --output-path target/coverage/llvm-cov-report.json + $(CARGO) llvm-cov report + @echo "$(GREEN)✓ Report: target/coverage/llvm-cov-report.json$(NC)" + +## api-level: Compares the public API to the last snapshot (initial, unchanged, additive or breaking) +api-level: + @$(KIT_DIR)/scripts/api-level.sh + +## api-snapshot: Records the public API of the current version (api/.txt and .json.gz) +api-snapshot: + @$(KIT_DIR)/scripts/api-snapshot.sh + +## bump-version: Next version according to the API (breaking: x.y+1.0 in 0.x), or fixed RELEASE=x.y.z +bump-version: + @$(KIT_DIR)/scripts/bump-version.sh + +## publish: Publishes to the $(REGISTRY) registry (done by the CI after the tag; manual troubleshooting, DRY_RUN=1: without sending) +publish: + @$(KIT_DIR)/scripts/publish.sh + +## wiki: Publishes the API doc to the wiki (done by the CI after the tag; manual troubleshooting, DRY_RUN=1: without push) +wiki: + @$(KIT_DIR)/scripts/wiki.sh + +## jjpush: Version bump, API snapshot, documentation, then main advances to the commit and is pushed +jjpush: bookmark-check deps-check bump-version api-snapshot + @echo "$(YELLOW)→ Pushing the commit to main...$(NC)" + @jj auto-doc + @$(KIT_DIR)/scripts/push-main.sh + @$(KIT_DIR)/scripts/new-commit.sh + @echo "$(GREEN)✓ main pushed; new working commit created on top of it$(NC)" + +## jjrelease: Release (ci, version according to the API, snapshot, notes, push of main, tag; the CI then publishes) +jjrelease: bookmark-check kit-check ci bump-version api-snapshot + @echo "$(BLUE)→ Documenting the undocumented commits...$(NC)" + @jj auto-doc + @echo "$(BLUE)→ Synchronizing the tags with the remote repository...$(NC)" + @jj git fetch + @$(KIT_DIR)/scripts/release-notes.sh + @echo "$(BLUE)→ Documenting the current commit...$(NC)" + @jj auto-doc + @echo "$(BLUE)→ Pushing main...$(NC)" + @$(KIT_DIR)/scripts/push-main.sh + @$(KIT_DIR)/scripts/tag.sh + @$(KIT_DIR)/scripts/new-commit.sh + @echo "$(GREEN)✓ Tag pushed: the CI (Release workflow) publishes the crate, updates the wiki and creates the release$(NC)" +ifneq ($(strip $(AFTER_RELEASE)),) + @echo "$(BLUE)→ After the release: $(AFTER_RELEASE)$(NC)" + @$(AFTER_RELEASE) +endif + @name=$$(sed -n 's/^name = "\(.*\)"/\1/p' $(CARGO_TOML) | head -n 1); \ + v=$$(sed -n 's/^version = "\(.*\)"/\1/p' $(CARGO_TOML) | head -n 1); \ + case "$$v" in 0.*) req=$$(echo "$$v" | cut -d. -f1,2);; *) req=$$(echo "$$v" | cut -d. -f1);; esac; \ + echo "$(YELLOW)⚠ Dependent projects: the requirement must accept $$v. If it does not, the local [patch] is ignored: raise it in their Cargo.toml $$name = { version = \"$$req\", registry = \"$(REGISTRY)\" } then cargo update -p $$name$(NC)" + +## bookmark-check: Does main track main@origin? Otherwise the push of main would fail at the end of the release (read-only) +bookmark-check: + @$(KIT_DIR)/scripts/bookmark-check.sh + +## kit-check: Is this crate's kit and release workflow identical to crate-kit's? (read-only) +kit-check: + @$(KIT_DIR)/scripts/kit-check.sh + +## needs-commit: Are there changes other than the kit's to commit? (read-only, code 1 if not) +needs-commit: + @$(KIT_DIR)/scripts/needs-commit.sh + +## kit-update: Updates .crate-kit/ from the extension kit (KIT_SRC) +kit-update: + @test -x "$(KIT_SRC)/tools/kit-copy.sh" || { echo "crate-kit not found: $(KIT_SRC) (set KIT_SRC=...)"; exit 1; } + @"$(KIT_SRC)/tools/kit-copy.sh" $(KIT_DIR) + @echo "$(GREEN)✓ .crate-kit/ up to date: crate-kit $$(cat $(KIT_DIR)/VERSION)$(NC)" + +## print-%: Value of a make variable (e.g. make print-PUBLISH); for the tools +print-%: + @echo '$($*)' + +## kit-version: Kit version installed in this crate +kit-version: + @cat $(KIT_DIR)/VERSION diff --git a/.crate-kit/dev-patch.mk b/.crate-kit/dev-patch.mk new file mode 100644 index 00000000..184bcd9b --- /dev/null +++ b/.crate-kit/dev-patch.mk @@ -0,0 +1,42 @@ +# Private registry and local Cargo configuration (joint development). +# Fragment included by crate.mk and by the Makefiles that are not crates (workspace): +# include .crate-kit/dev-patch.mk + +DEVPATCH_DIR := $(patsubst %/,%,$(dir $(lastword $(MAKEFILE_LIST)))) +CARGO_TOML ?= Cargo.toml + +# Values specific to the organization (REGISTRY, REGISTRY_INDEX, FORGE_URL…): org.mk, provided by the +# extension that the crate declares (KIT_OVERLAY, tools/kit-assemble.sh). REGISTRY = crates-io: crates.io, without +# index or [patch]. Without org.mk, no registry: publish and deps-check fail saying so. +-include $(DEVPATCH_DIR)/org.mk +REGISTRY ?= +REGISTRY_INDEX ?= +export CARGO_TOML REGISTRY REGISTRY_INDEX FORGE_TOKEN_FILE + +# Private registry: the index comes from the environment, never from a file tracked by the repository (CI, +# Docker and a repository cloned alone therefore work without configuration). +ifneq ($(filter-out crates-io,$(strip $(REGISTRY))),) +REGISTRY_UP := $(shell echo '$(REGISTRY)' | tr 'a-z-' 'A-Z_') +CARGO_REGISTRIES_$(REGISTRY_UP)_INDEX := $(REGISTRY_INDEX) +export CARGO_REGISTRIES_$(REGISTRY_UP)_INDEX +endif + +# Joint development: .cargo/config.toml (local, ignored) is regenerated at EVERY invocation of +# make, whatever the target, from the project's actual dependencies. Nothing to remember. +DEV_PATCH_RUN := $(shell CARGO_TOML='$(CARGO_TOML)' REGISTRY='$(REGISTRY)' REGISTRY_INDEX='$(REGISTRY_INDEX)' $(DEVPATCH_DIR)/scripts/dev-patch.sh) + +.PHONY: dev-patch +## dev-patch: Regenerates .cargo/config.toml (registry + local patches); already done at every make +dev-patch: + @$(DEVPATCH_DIR)/scripts/dev-patch.sh + @echo "ok: .cargo/config.toml up to date" + +.PHONY: deps-check deps-bump +## deps-check: Dependencies up to date? from the private registry (requirement, lock, neighbour, duplicates) and external (requirement, minor, lock) +deps-check: + @rc=0; $(DEVPATCH_DIR)/scripts/deps-check.sh || rc=1; $(DEVPATCH_DIR)/scripts/deps-check-external.sh || rc=1; exit $$rc + +## deps-bump: Raises the outdated requirements (private registry and external) to the latest version, then cargo update -p +deps-bump: + @$(DEVPATCH_DIR)/scripts/deps-check.sh bump + @$(DEVPATCH_DIR)/scripts/deps-check-external.sh bump diff --git a/.crate-kit/jj.mk b/.crate-kit/jj.mk new file mode 100644 index 00000000..9ac1b48d --- /dev/null +++ b/.crate-kit/jj.mk @@ -0,0 +1,22 @@ +# Jujutsu targets common to all the crates and to crate-kit itself. +# Included by crate.mk; a repository that is not a crate includes it directly. + +JJ_KIT_DIR := $(patsubst %/,%,$(dir $(lastword $(MAKEFILE_LIST)))) +GREEN ?= \033[0;32m +YELLOW ?= \033[1;33m +BLUE ?= \033[1;34m +NC ?= \033[0m + +## jjnew: Documents the current commit then creates a new one +jjnew: + @echo "$(YELLOW)→ Creating a new commit...$(NC)" + @jj auto-doc + @$(JJ_KIT_DIR)/scripts/new-commit.sh + @echo "$(GREEN)✓ Done$(NC)" + +## jjfetch: Fetches the origin and rebases the local work on top of main@origin (nothing is lost) +jjfetch: + @$(JJ_KIT_DIR)/scripts/jjfetch.sh + @# Reruns make to resynchronize .crate-kit/: the Makefile does it at startup, before the rebase, and + @# the rebase may have left conflict markers there (kit copy newer than the origin's). + @$(MAKE) --no-print-directory -s help >/dev/null diff --git a/.crate-kit/kinds/crate.mk b/.crate-kit/kinds/crate.mk new file mode 100644 index 00000000..07fb7191 --- /dev/null +++ b/.crate-kit/kinds/crate.mk @@ -0,0 +1,3 @@ +# "crate" kind (default): ordinary Rust crate, published to the private registry, API tracked, wiki. +# The default values of BUILD_TARGET, EXTRA_TARGETS, PUBLISH, API_TRACKED, WIKI and AFTER_RELEASE +# (crate.mk) describe this kind: nothing to set here. diff --git a/.crate-kit/org.mk b/.crate-kit/org.mk new file mode 100644 index 00000000..2bfa7905 --- /dev/null +++ b/.crate-kit/org.mk @@ -0,0 +1,9 @@ +# Values specific to obi, read by dev-patch.mk (hence by every Makefile of the cluster) and by crate-kit. +# The cargo registry to publish to (a private name, or crates-io) and the forge hosting it. +REGISTRY ?= obi +FORGE_URL ?= https://forge.metabarcoding.org +REGISTRY_INDEX ?= sparse+$(FORGE_URL)/api/packages/$(REGISTRY)/cargo/ +# No token here: the forge tokens of a workstation are files of the cluster, in secrets/ next to the +# repositories (secrets/forge.metabarcoding.org.token, ...), outside every repository. FORGETOKEN (CI) overrides them. +# Language of the documents an LLM generates (release notes, commit messages, Claude agents' notes). +KIT_LANG ?= en diff --git a/.crate-kit/scripts/api-level.sh b/.crate-kit/scripts/api-level.sh new file mode 100755 index 00000000..b90594b4 --- /dev/null +++ b/.crate-kit/scripts/api-level.sh @@ -0,0 +1,96 @@ +#!/usr/bin/env bash +# Compares the current public API to the last snapshot and prints on standard output: +# initial no snapshot: first tracked version +# unchanged no change in the public API +# additive additions only (nothing removed or modified) +# breaking break: element removed/modified, or break seen by cargo-semver-checks +# All the detail goes to standard error. +# +# Two combined checks: cargo-semver-checks is the reference for breaks, but it does not +# report plain additions; the text diff of cargo public-api acts as a safety net (any removed +# or modified line = break) and provides the count of additions. +set -euo pipefail +. "$(dirname "$0")/common.sh" + +if [ "${API_TRACKED:-yes}" = no ]; then + echo unchanged # no tracked Rust API: the version advances by patch (or RELEASE=x.y.z) + exit 0 +fi + +require_cargo_tool public-api cargo-public-api +require_cargo_tool semver-checks cargo-semver-checks + +# A proc-macro crate has no library target: cargo-semver-checks cannot analyse it. +# Its API (the exported macros) is still tracked by the text diff of cargo public-api; this diff does +# not see a change in the macro's behaviour (rejected inputs, generated code): to be judged by hand. +is_proc_macro() { + "$CARGO" metadata --format-version 1 --no-deps | grep -q '"kind":\["proc-macro"\]' +} + +last=$(latest_snapshot) +if [ -z "$last" ]; then + info " No snapshot in $API_DIR/: first tracked version" + echo initial + exit 0 +fi + +# A snapshot written with other tools (rustc, cargo-public-api) than today's is no longer +# comparable: cargo-semver-checks crashes on another rustdoc format, and the text diff sees +# breaks where only the rendering changed. It is regenerated from the tag of its version (no stamp = +# written before stamps existed, hence unknown). +if [ "$(cat "$API_DIR/$last.stamp" 2>/dev/null || true)" != "$(toolchain_stamp)" ]; then + info " Snapshot $last written with other tools: regenerating from tag version-$last" + regenerate_snapshot "$last" || { + err "✗ cannot regenerate snapshot $last: the comparison would be wrong" + exit 1 + } +fi + +tmp=$(mktemp -d) +trap 'rm -r "$tmp"' EXIT +info " Reference: API published in version $last" + +"$CARGO" public-api -s >"$tmp/current.txt" 2>/dev/null || { + err "✗ cargo public-api failed" + exit 1 +} +# `filter_unstable` (common.sh) removes from the cargo public-api text whatever is not the crate's API. +diff_out=$(diff <(filter_unstable "$API_DIR/$last.txt") <(filter_unstable "$tmp/current.txt") || true) +removed=$(printf '%s\n' "$diff_out" | grep -c '^<' || true) +added=$(printf '%s\n' "$diff_out" | grep -c '^>' || true) + +# Code 100 = break; 0 = nothing to report; other = tool failure. +set +e +if is_proc_macro; then + info " proc-macro crate: cargo-semver-checks not applicable, text diff only" + rc=0 +else + gzip -d -c "$API_DIR/$last.json.gz" >"$tmp/baseline.json" + "$CARGO" semver-checks --baseline-rustdoc "$tmp/baseline.json" --release-type minor >"$tmp/semver.log" 2>&1 + rc=$? +fi +set -e + +level=unchanged +if [ "$rc" -eq 100 ]; then + level=breaking + warn " Break detected by cargo-semver-checks:" + grep -E '^ +[A-Za-z0-9_]+::|^--- failure' "$tmp/semver.log" >&2 || true +elif [ "$rc" -ne 0 ]; then + err "✗ cargo-semver-checks failed (code $rc):" + tail -n 15 "$tmp/semver.log" >&2 + exit 1 +fi + +if [ "$removed" -gt 0 ]; then + level=breaking + warn " $removed API line(s) removed or modified compared to $last:" + printf '%s\n' "$diff_out" | grep '^<' >&2 +fi + +if [ "$level" = unchanged ] && [ "$added" -gt 0 ]; then + level=additive +fi + +info " API: +$added / -$removed lines; verdict: $level" +echo "$level" diff --git a/.crate-kit/scripts/api-snapshot.sh b/.crate-kit/scripts/api-snapshot.sh new file mode 100755 index 00000000..f040cee9 --- /dev/null +++ b/.crate-kit/scripts/api-snapshot.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash +# Records the public API of the current version: +# $API_DIR/.txt readable, diffable list (cargo public-api) +# $API_DIR/.json.gz compressed rustdoc JSON, reference of cargo-semver-checks +# $API_DIR/.stamp rustc and cargo-public-api used (api-level regenerates if they change) +set -euo pipefail +. "$(dirname "$0")/common.sh" + +if [ "${API_TRACKED:-yes}" = no ]; then + info " (kind ${CRATE_KIND:-crate}: no Rust API to record)" + exit 0 +fi + +require_cargo_tool public-api cargo-public-api + +version=$(current_version) +name=$(crate_name) +warn "→ Public API snapshot of $name $version..." +emit_snapshot "$version" "$API_DIR" +ok "✓ $API_DIR/$version.txt and $API_DIR/$version.json.gz written" diff --git a/.crate-kit/scripts/bookmark-check.sh b/.crate-kit/scripts/bookmark-check.sh new file mode 100755 index 00000000..84bd8862 --- /dev/null +++ b/.crate-kit/scripts/bookmark-check.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash +# Checks that the local `main` bookmark tracks `main@origin` (read-only). Without this tracking, jj refuses +# to push main ("Non-tracking remote bookmark"), and jjrelease would fail at the very end, +# after the tests and the version bump: this check detects it beforehand. +# Without a jj repository, without a `main` bookmark or without `main@origin`, there is nothing to check: success. +set -euo pipefail +. "$(dirname "$0")/common.sh" + +rows=$(jj bookmark list main --all-remotes -T 'remote ++ "|" ++ tracked ++ "\n"' 2>/dev/null) || exit 0 +if printf '%s\n' "$rows" | grep -qx 'origin|false'; then + err "✗ main@origin exists but the local main bookmark does not track it: the push of main would be refused" + info " Fix once and for all: jj bookmark track main@origin" + exit 1 +fi diff --git a/.crate-kit/scripts/bump-version.sh b/.crate-kit/scripts/bump-version.sh new file mode 100755 index 00000000..750724fb --- /dev/null +++ b/.crate-kit/scripts/bump-version.sh @@ -0,0 +1,67 @@ +#!/usr/bin/env bash +# Computes and applies the next version according to the public API (see api-level.sh): +# break -> x.y+1.0 while x = 0, otherwise x+1.0.0 +# additions -> x.y+1.0 once x >= 1 (SemVer: new feature), x.y.z+1 while x = 0 +# otherwise -> x.y.z+1 +# RELEASE=x.y.z forces the version. Updates Cargo.toml, version.txt and the +# dependency line ` = "x.y"` of README.md when they exist. +set -euo pipefail +. "$(dirname "$0")/common.sh" + +warn "→ Computing the next version..." +current=$(current_version) +name=$(crate_name) +info " Current version: $current" +IFS=. read -r major minor patch <<<"$current" + +if [ -n "${RELEASE:-}" ]; then + new_version="$RELEASE" +else + level=$("$(dirname "$0")/api-level.sh") + case "$level" in + breaking) + if [ "$major" = "0" ]; then + new_version="0.$((minor + 1)).0" + else + new_version="$((major + 1)).0.0" + fi + ;; + additive) + if [ "$major" = "0" ]; then + new_version="0.$minor.$((patch + 1))" + else + new_version="$major.$((minor + 1)).0" + fi + ;; + initial | unchanged) + new_version="$major.$minor.$((patch + 1))" + ;; + *) + err "✗ unexpected API verdict: '$level'" + exit 1 + ;; + esac +fi + +# No silent jump to another version: a break must never be downgraded. +rc=0 +"$(dirname "$0")/tag-exists.sh" "$new_version" || rc=$? +case "$rc" in +0) + err "✗ The release version-$new_version already exists (locally or on the server)" + info " Use RELEASE=x.y.z to force another version" + exit 1 + ;; +1) ;; +*) warn " (remote tags not checked: no jj repository or origin unreachable)" ;; +esac + +info " New version: $new_version" +sed -i.bak "s/^version = \"$current\"/version = \"$new_version\"/" "$CARGO_TOML" +rm "$CARGO_TOML.bak" +[ -f version.txt ] && echo "$new_version" >version.txt +if [ -f README.md ]; then + sed -i.bak "s/^$name = \"[0-9][0-9.]*\"/$name = \"$(echo "$new_version" | cut -d. -f1,2)\"/" README.md + rm README.md.bak +fi +ok "✓ Version $new_version written to $CARGO_TOML (and version.txt, README.md if they exist)" diff --git a/.crate-kit/scripts/common.sh b/.crate-kit/scripts/common.sh new file mode 100755 index 00000000..b89e4cbf --- /dev/null +++ b/.crate-kit/scripts/common.sh @@ -0,0 +1,266 @@ +#!/usr/bin/env bash +# Functions shared by the kit scripts. To be sourced: `. "$(dirname "$0")/common.sh"`. +# +# Parameters read from the environment (default values below); crate.mk exports +# them, the scripts also remain usable on their own from the root of a crate. + +CARGO="${CARGO:-cargo}" +CARGO_TOML="${CARGO_TOML:-Cargo.toml}" +API_DIR="${API_DIR:-api}" +RELEASE_NOTES_DIR="${RELEASE_NOTES_DIR:-ReleaseNotes}" +# Private cargo registry and its sparse index: provided by the organisation overlay (org.mk), empty otherwise. +REGISTRY="${REGISTRY:-}" +REGISTRY_INDEX="${REGISTRY_INDEX:-}" + +info() { printf '\033[1;34m%s\033[0m\n' "$*" >&2; } +warn() { printf '\033[1;33m%s\033[0m\n' "$*" >&2; } +ok() { printf '\033[0;32m%s\033[0m\n' "$*" >&2; } +err() { printf '\033[0;31m%s\033[0m\n' "$*" >&2; } + +# API call: `forge_call `. Returns the response body on standard output; +# on an HTTP response ≥ 400 (or a transport failure), states the operation, the code and the body on standard +# error and returns 1. Replaces `curl -sf`, which fails silently (code 22). +forge_call() { + local operation="$1" body code + shift + body=$(mktemp) + code=$(curl -s -o "$body" -w '%{http_code}' "$@") || code="000" + if [ "$code" -ge 400 ] || [ "$code" = "000" ]; then + err "✗ $operation : HTTP $code : $(head -c 500 "$body")" + rm -f "$body" + return 1 + fi + cat "$body" + rm -f "$body" +} + +# Directory of the forge tokens of a workstation: `secrets/` of the cluster, i.e. next to the repositories +# (the parent of the current repository), outside every repository. FORGE_SECRETS_DIR overrides it. +forge_secrets_dir() { + if [ -n "${FORGE_SECRETS_DIR:-}" ]; then + printf '%s' "$FORGE_SECRETS_DIR" + return 0 + fi + local root + root=$(jj root 2>/dev/null) || root=$(pwd) + printf '%s/secrets' "$(dirname "$root")" +} + +# "host owner repo" of a git or registry URL: ssh://git@host[:port]/owner/repo.git, git@host:owner/repo.git, +# https://host/owner/repo, sparse+https://host/api/packages/owner/cargo/ (owner of the registry, no repo). +# Fails if the URL has no known form. Fields are empty when absent. +forge_parse_url() { + local u="${1#sparse+}" host path owner repo + case "$u" in + *://*) u="${u#*://}"; u="${u#*@}"; host="${u%%/*}"; path="${u#*/}" ;; + *@*:*) u="${u#*@}"; host="${u%%:*}"; path="${u#*:}" ;; + *) return 1 ;; + esac + [ "$path" = "$u" ] && path="" + host="${host%%:*}" + path="${path%/}"; path="${path%.git}" + case "$path" in + api/packages/*) owner="${path#api/packages/}"; owner="${owner%%/*}"; repo="" ;; + *) owner="${path%%/*}"; repo="${path#*/}"; [ "$repo" = "$path" ] && repo="" ;; + esac + [ -n "$host" ] || return 1 + printf '%s %s %s\n' "$host" "$owner" "$repo" +} + +# Forge token. `forge_token [url]`: the forge is that of the URL (registry index, repository), by default that of +# the `origin` remote. Order, the first that exists wins: +# 1. $FORGETOKEN: the CI, where each forge provides its own secret to its own jobs; +# 2. the token files of the cluster, most specific first (one line, mode 0600; see forge_secrets_dir): +# ///.token, //.token, /.token; +# 3. the file $FORGE_TOKEN_FILE (former single-token layout). +# Nothing on standard output if there is none; the caller then says where to put it. Never displayed. +forge_token() { + if [ -n "${FORGETOKEN:-}" ]; then + printf '%s' "$FORGETOKEN" + return 0 + fi + local url="${1:-}" host owner repo dir f + [ -n "$url" ] || url=$(jj git remote list 2>/dev/null | awk '$1=="origin"{print $2; exit}') + if [ -n "$url" ] && read -r host owner repo < <(forge_parse_url "$url"); then + dir=$(forge_secrets_dir) + for f in ${repo:+"$dir/$host/$owner/$repo.token"} ${owner:+"$dir/$host/$owner.token"} "$dir/$host.token"; do + if [ -f "$f" ]; then + head -n 1 "$f" | tr -d '[:space:]' + return 0 + fi + done + fi + if [ -n "${FORGE_TOKEN_FILE:-}" ] && [ -f "$FORGE_TOKEN_FILE" ]; then + head -n 1 "$FORGE_TOKEN_FILE" | tr -d '[:space:]' + fi + return 0 +} + +# cargo authentication against the private registry: CARGO_REGISTRIES__TOKEN ("Bearer "), +# built from the forge token if not already defined. Needed by any cargo call that +# resolves registry dependencies (publish, wiki doc). For crates.io (REGISTRY = crates-io) nothing +# is built: the crates.io token is CARGO_REGISTRY_TOKEN, supplied by the user. +if [ -n "$REGISTRY" ] && [ "$REGISTRY" != crates-io ]; then + reg_var="CARGO_REGISTRIES_$(printf '%s' "$REGISTRY" | tr 'a-z-' 'A-Z_')_TOKEN" + if [ -z "${!reg_var:-}" ] && [ -n "$(forge_token "$REGISTRY_INDEX")" ]; then + export "$reg_var=Bearer $(forge_token "$REGISTRY_INDEX")" + fi +fi + +# Version: content of $VERSION_FILE if set (repositories that are not crates, like +# crate-kit itself), otherwise first occurrence in the crate's Cargo.toml. +current_version() { + # Source of the version: VERSION_FILE (exported by the Makefiles of the kits), else the Cargo.toml of a crate. + # Without either (script run by hand at the root of a kit, not through make): kit/VERSION (crate-kit) or + # overlay/kit/VERSION (extension kit), if present. + local file="${VERSION_FILE:-}" candidate + if [ -z "$file" ] && [ ! -f "$CARGO_TOML" ]; then + for candidate in kit/VERSION overlay/kit/VERSION; do + [ -f "$candidate" ] && { file="$candidate"; break; } + done + fi + if [ -n "$file" ]; then + head -n 1 "$file" + elif [ -f "$CARGO_TOML" ]; then + sed -n 's/^version = "\(.*\)"/\1/p' "$CARGO_TOML" | head -n 1 + else + err "✗ no source for the version: no VERSION_FILE, no $CARGO_TOML, no kit/VERSION nor overlay/kit/VERSION here" + return 1 + fi +} +# Package name: first occurrence in the crate's Cargo.toml. +# Abandons the empty commits without a description between trunk() and @ (excluding @ itself): jj refuses to +# push a commit without a description, and these carry nothing (leftovers of `jj new`). Descendants +# are rebased automatically; neither work nor an already pushed (immutable) commit is touched. +abandon_blank_commits() { + jj abandon 'trunk()..@ & mutable() & empty() & description(exact:"") ~ @' >/dev/null 2>&1 || true +} + +# The commit to publish: @, unless it is empty and without a description (the working commit that `jj new` +# leaves after a release or a push); we then go up to the first ancestor that carries work. +# Such a commit is not pushed (jj refuses a commit without a description) and deserves neither tag nor main. +release_rev() { + local rev='@' blank + while :; do + blank=$(jj log -r "$rev" --no-graph -T 'if(empty && description == "", "1", "0")') + [ "$blank" = 1 ] || break + rev="$rev-" + done + echo "$rev" +} + +crate_name() { sed -n 's/^name = "\(.*\)"/\1/p' "$CARGO_TOML" | head -n 1; } + +# Last version having an API snapshot (sorted by version number), empty if there is none. +latest_snapshot() { + ls "$API_DIR"/*.json.gz 2>/dev/null | sed 's|.*/||; s|\.json\.gz$||' | sort -V | tail -n 1 || true +} + +# Fingerprint of the tools that produce a snapshot. The rustdoc JSON (format number) and the text +# rendering of cargo public-api change with rustc and cargo-public-api: a snapshot written with other +# tools than today's is no longer comparable (cargo-semver-checks crashes, or the text diff +# announces a break where only the rendering changed). +toolchain_stamp() { + printf '%s | %s\n' "$(rustc -V)" "$("$CARGO" public-api --version)" +} + +# Writes the snapshot of version of the code in the current directory (root of a +# crate), into : .txt, .json.gz and .stamp (toolchain_stamp). +# Parameters: version, snapshot directory (absolute if the current directory is not the crate). +emit_snapshot() { + local version="$1" api_dir="$2" name target_dir + name=$(crate_name) + mkdir -p "$api_dir" + + # -s: without the blanket implementations (`impl Into for Type`…), added by rustc to + # every public type and unrelated to its API (they made up half of the file). + "$CARGO" public-api -s >"$api_dir/$version.txt" + # The rustdoc JSON is unstable; RUSTC_BOOTSTRAP makes it possible to produce it with the stable toolchain, + # the same one cargo-semver-checks uses to build the current state. + # --document-private-items: cargo-semver-checks builds the current state with private items + # (private fields included); a reference without them makes a struct with a private field look like + # it "gains a private field" and gives a break wrongly. + RUSTC_BOOTSTRAP=1 "$CARGO" rustdoc --lib -q -- -Zunstable-options --output-format json --document-private-items + + target_dir=$("$CARGO" metadata --format-version 1 --no-deps | + sed -n 's/.*"target_directory":"\([^"]*\)".*/\1/p') + # Compressed (gzip -n: reproducible output): the JSON exceeds 1 MB, jj's limit for a new file. + gzip -9 -n -c "$target_dir/doc/${name//-/_}.json" >"$api_dir/$version.json.gz" + toolchain_stamp >"$api_dir/$version.stamp" +} + +# Regenerates the snapshot of the published version with the current tools, from the code of +# its tag `version-` (read-only: `jj file list/show`, no modification of the repository). +# The tag is exported into a sibling folder of the crate (`.baseline.tmp`): the relative paths +# of `.cargo/config.toml` (`[patch.]` towards the neighbours) remain valid there. Only `.cargo/` (ignored +# by the repository, generated by `make`) is copied in addition. +regenerate_snapshot() { + local version="$1" api_dir root tmp rev="version-$1" f + api_dir="$(pwd)/$API_DIR" + root="$(pwd)" + tmp="$root.baseline.tmp" + if ! jj file list -r "$rev" >/dev/null 2>&1; then + err "✗ tag $rev not found: cannot regenerate the snapshot of $version" + return 1 + fi + rm -rf "$tmp" + mkdir -p "$tmp" + while IFS= read -r f; do + mkdir -p "$tmp/$(dirname "$f")" + jj file show -r "$rev" "$f" >"$tmp/$f" + done < <(jj file list -r "$rev") + [ -d "$root/.cargo" ] && cp -R "$root/.cargo" "$tmp/.cargo" + ( + cd "$tmp" + CARGO_TARGET_DIR="$tmp/target" emit_snapshot "$version" "$api_dir" + ) || { rm -rf "$tmp"; return 1; } + rm -rf "$tmp" +} + +# Fails with an installation message if a cargo tool is missing. +require_cargo_tool() { + local sub="$1" crate="$2" + if ! command -v "cargo-$sub" >/dev/null 2>&1; then + err "✗ cargo-$sub is required: cargo install $crate --locked" + exit 1 + fi +} + +# Lines that are not the crate's API and that the text diff must not see: +# - `impl core::marker::Freeze`: unstable auto trait, invisible on stable; it appears or +# disappears as soon as a field goes under `Mutex`/`Atomic*`, with no effect for a caller; +# - the blanket implementations (`impl other_crate::Trait for Type`) of traits of OTHER crates +# and their associated items: rustdoc lists them for every trait of the dependency graph, so +# they appear or disappear when a dependency changes (e.g. `crossbeam_epoch::Pointable`, +# `either::IntoEither`), without the crate's API having moved. Those of `core`, +# `alloc`, `std` and of the crate itself are kept. +filter_unstable() { + grep -v '^impl core::marker::Freeze for ' "$1" | awk -v crate="$(crate_name)" ' + /^impl]*> /, "", rest) + split(rest, parts, " ") + trait = parts[1] + if (trait !~ /^(core|alloc|std)::/ && index(trait, crate "::") != 1 && match($0, / for [^ ]+/)) { + self = substr($0, RSTART + 5, RLENGTH - 5) + skip = 1 + next + } + print + next + } + skip && (index($0, "pub fn " self "::") == 1 || index($0, "pub unsafe fn " self "::") == 1 || + index($0, "pub type " self "::") == 1 || index($0, "pub const " self "::") == 1) { next } + { skip = 0; print } + ' || true +} + +# API text for the release notes: `filter_unstable`, then without the auto traits +# (`Send`, `Sync`, `Unpin`, `UnwindSafe`, `RefUnwindSafe`, `Freeze`, `Forget`, `Move`, `UnsafeUnpin`, +# `StructuralPartialEq`) that cargo public-api lists for every type: a new type adds nine +# lines that drown the API. They remain in the snapshot, hence in the verdict of `make api-level` +# (losing `Send` is a break); only the readable notes omit them. +filter_notes() { + filter_unstable "$1" | grep -v -E '^impl core::(marker::(Forget|Freeze|Move|Send|Sync|Unpin|UnsafeUnpin|StructuralPartialEq)|panic::unwind_safe::(RefUnwindSafe|UnwindSafe)) for ' || true +} diff --git a/.crate-kit/scripts/deps-check-external.sh b/.crate-kit/scripts/deps-check-external.sh new file mode 100755 index 00000000..e39358b4 --- /dev/null +++ b/.crate-kit/scripts/deps-check-external.sh @@ -0,0 +1,193 @@ +#!/usr/bin/env bash +# Freshness of the EXTERNAL dependencies (crates.io) declared by the project. `cargo outdated` compares the +# Cargo.lock version to the latest published one, but not the requirement written in Cargo.toml: a +# requirement `os_info = "3.8"` with a lock up to date at 3.15 goes unnoticed, and a consumer of the +# crate may end up with a version seven minor versions old. +# +# For each direct dependency `name = "x.y"` or `name = { version = "x.y", … }` (excluding `path`, `git`, +# `registry`, `workspace`), in [dependencies], [dev-dependencies], [build-dependencies], their +# `target.*` variants and [workspace.dependencies], it checks: +# 1. the requirement accepts the latest published version (for a 0.x, `0.5` does not accept 0.6); +# 2. for a version ≥ 1, the required minor version is not behind the latest +# (`tokio = "1.35"` while 1.52 exists). A 0.x is not checked at this level: its +# patch number does not count; +# 3. Cargo.lock is on the latest version that the requirement accepts. +# Requirements that are not written `x`, `x.y` or `x.y.z` (`=1.2.3`, `~1.2`, `>=1`, ranges) are +# explicit choices: ignored. +# +# deps-check-external.sh check (read-only, except for the network) +# deps-check-external.sh bump raises the outdated requirements then `cargo update -p` +# +# Variables: DEPS_CHECK_EXTERNAL=0 disables the check (workspace too large to be kept up +# to date all at once); DEPS_CHECK_EXTERNAL_IGNORE="crate1 crate2" sets crates aside (to be justified in +# the Makefile: for example a public dependency that must move up with the neighbouring crates); CRATES_IO_INDEX (default https://index.crates.io); DEPS_CHECK_OFFLINE=1 ignores +# the absence of network (warning). +# shellcheck disable=SC2154 # manifests comes from deps-lib.sh +set -euo pipefail +. "$(dirname "$0")/common.sh" +. "$(dirname "$0")/deps-lib.sh" + +mode="${1:-check}" +case "$mode" in check | bump) ;; *) + err "usage: deps-check-external.sh [check|bump]" + exit 2 + ;; +esac + +if [ "${DEPS_CHECK_EXTERNAL:-1}" = 0 ]; then + info " (external dependencies: check disabled by DEPS_CHECK_EXTERNAL=0)" + exit 0 +fi +[ -f "$CARGO_TOML" ] || exit 0 + +crates_index="${CRATES_IO_INDEX:-https://index.crates.io}" +crates_index="${crates_index%/}" + +fail=0 +bad() { + err " ✗ $*" + fail=1 +} + +# External declarations of a manifest: "keycraterequirement" (the crate differs from the key +# when the dependency is renamed by `package = "…"`). +declarations() { + awk ' + /^\[/ { dep = ($0 ~ /^\[(workspace\.|target\..*\.)?(dev-|build-)?dependencies\]$/); next } + !dep { next } + /^[ \t]*#/ { next } + { + if (match($0, /^[A-Za-z0-9_-]+[ \t]*=/) == 0) next + key = $0; sub(/[ \t]*=.*/, "", key) + rest = $0; sub(/^[A-Za-z0-9_-]+[ \t]*=[ \t]*/, "", rest) + crate = key + if (rest ~ /^"/) { + req = rest; sub(/^"/, "", req); sub(/".*/, "", req) + } else if (rest ~ /^\{/) { + if (rest ~ /(path|git|registry|workspace)[ \t]*=/) next + if (match(rest, /version[ \t]*=[ \t]*"[^"]*"/) == 0) next + req = substr(rest, RSTART, RLENGTH) + sub(/^version[ \t]*=[ \t]*"/, "", req); sub(/"$/, "", req) + if (match(rest, /package[ \t]*=[ \t]*"[^"]*"/)) { + crate = substr(rest, RSTART, RLENGTH) + sub(/^package[ \t]*=[ \t]*"/, "", crate); sub(/"$/, "", crate) + } + } else next + print key "\t" crate "\t" req + } + ' "$1" +} + +# Replaces the requirement of the dependency `key` (in a dependencies section) of manifest $1 with $3. +rewrite_req() { + awk -v n="$2" -v r="$3" ' + /^\[/ { dep = ($0 ~ /dependencies\]$/) } + dep && $0 ~ "^" n "[ \t]*=" { + if ($0 ~ /\{/) sub(/version[ \t]*=[ \t]*"[^"]*"/, "version = \"" r "\"") + else sub(/"[^"]*"/, "\"" r "\"") + } + { print } + ' "$1" >"$1.tmp" && mv "$1.tmp" "$1" +} + +# Requirement to write for version $1: x.y (≥ 1) or 0.y. +floor_for() { echo "$1" | cut -d. -f1,2; } + +tmp=$(mktemp -d) +trap 'rm -r "$tmp"' EXIT + +info "→ Freshness of the external dependencies (crates.io)..." +count=0 +offline=0 +updates="" +for manifest in "${manifests[@]}"; do + while IFS=$'\t' read -r key crate req; do + [ -n "$crate" ] || continue + # Dependency deliberately set aside (DEPS_CHECK_EXTERNAL_IGNORE, with its reason in the Makefile). + case " ${DEPS_CHECK_EXTERNAL_IGNORE:-} " in *" $crate "*) continue ;; esac + # Explicit requirement (=, ~, >=, range): a choice, not checked (and no network request). + case "${req#^}" in '' | *[!0-9.]*) continue ;; esac + count=$((count + 1)) + + if [ ! -f "$tmp/$crate" ]; then + rc=0 + found=$(latest_published "$crate" "$crates_index") || rc=$? + printf '%s %s\n' "$rc" "$found" >"$tmp/$crate" + fi + read -r rc latest <"$tmp/$crate" + if [ "$rc" -eq 2 ]; then + offline=1 + continue + fi + if [ "$rc" -eq 1 ] || [ -z "$latest" ]; then + warn " ⚠ $crate ($manifest): not found on crates.io, not checked" + continue + fi + + acc=0 + req_accepts "$req" "$latest" || acc=$? + + + if [ "$acc" -eq 1 ]; then + # Newer than the latest published (pre-release, yank): nothing to raise. + [ "$(printf '%s\n%s\n' "$req" "$latest" | sort -V | tail -n 1)" = "$latest" ] || continue + if [ "$mode" = bump ]; then + new=$(floor_for "$latest") + rewrite_req "$manifest" "$key" "$new" + info " $crate ($manifest): \"$req\" → \"$new\" (latest version: $latest)" + updates+="$crate " + else + bad "$crate ($manifest): the requirement \"$req\" does not accept the latest version $latest → \"$(floor_for "$latest")\" (make deps-bump)" + fi + continue + fi + + # The requirement accepts the latest version: is the required minor (≥ 1.0) behind? + IFS=. read -r rmaj rmin _ <<<"${req#^}" + IFS=. read -r _ lmin _ <<<"$latest" + if [ "$rmaj" != 0 ] && [ -n "$rmin" ] && [ "$rmin" -lt "$lmin" ]; then + if [ "$mode" = bump ]; then + new=$(floor_for "$latest") + rewrite_req "$manifest" "$key" "$new" + info " $crate ($manifest): \"$req\" → \"$new\" (latest version: $latest)" + updates+="$crate " + else + bad "$crate ($manifest): the requirement \"$req\" is behind the latest version $latest → \"$(floor_for "$latest")\" (make deps-bump)" + fi + fi + + # Cargo.lock: on the latest version that the requirement accepts. + if [ -f Cargo.lock ]; then + locked=$(lock_entries | awk -v n="$crate" '$1 == n && index($3, "crates.io-index") { print $2 }' | sort -V | tail -n 1) + if [ -n "$locked" ] && [ "$locked" != "$latest" ] && + [ "$(printf '%s\n%s\n' "$locked" "$latest" | sort -V | tail -n 1)" = "$latest" ]; then + if [ "$mode" = bump ]; then + updates+="$crate " + else + bad "$crate: Cargo.lock is on $locked, the latest version is $latest → cargo update -p $crate (make deps-bump)" + fi + fi + fi + done < <(declarations "$manifest") +done + +if [ "$offline" -eq 1 ]; then + if [ "${DEPS_CHECK_OFFLINE:-}" = 1 ]; then + warn " ⚠ crates.io unreachable: freshness of the external dependencies not verified (DEPS_CHECK_OFFLINE=1)" + else + bad "crates.io unreachable ($crates_index): freshness cannot be verified (DEPS_CHECK_OFFLINE=1 to ignore)" + fi +fi + +if [ "$mode" = bump ] && [ -n "$updates" ]; then + for n in $(printf '%s\n' $updates | sort -u); do + info " cargo update -p $n" + "$CARGO" update -p "$n" >/dev/null + done +fi + +if [ "$fail" -ne 0 ]; then + err "✗ External dependencies out of date (see above)" + exit 1 +fi +ok "✓ External dependencies up to date ($count checked)" diff --git a/.crate-kit/scripts/deps-check.sh b/.crate-kit/scripts/deps-check.sh new file mode 100755 index 00000000..66749bb5 --- /dev/null +++ b/.crate-kit/scripts/deps-check.sh @@ -0,0 +1,166 @@ +#!/usr/bin/env bash +# Freshness of the dependencies between crates of the private registry: we must never keep running with an +# old version of a registry crate when a new one is published. Fails (code 1) at the slightest discrepancy. +# +# For each dependency `name = { version = "x.y", registry = "" }` declared by the project +# (same reading as dev-patch.sh), it checks: +# 1. the requirement accepts the latest version published on the registry (for a 0.x, `0.1` never +# accepts 0.2: Cargo says nothing); +# 2. Cargo.lock is on that latest version (if it points to the registry); +# 3. the neighbouring folder ../, which replaces the dependency in joint development, is not +# behind the registry (otherwise we build against stale code); +# 4. Cargo.lock contains no [[patch.unused]] (ignored local patch: requirement too low); +# 5. no registry crate appears in several versions in Cargo.lock (two copies in the build). +# A neighbour newer than the registry (pending publication) is reported without failing. +# +# deps-check.sh check (read-only, except for the network) +# deps-check.sh bump fixes the outdated requirements (rewrites the Cargo.toml) then `cargo update -p` +# +# Network: the sparse index of the registry ($REGISTRY_INDEX), public. Without network, the check +# fails; DEPS_CHECK_OFFLINE=1 explicitly ignores it (warning). +# shellcheck disable=SC2154 # index_url and manifests come from deps-lib.sh +set -euo pipefail +. "$(dirname "$0")/common.sh" +[ -n "$REGISTRY" ] || { err "✗ no registry: declare the kit extension (KIT_OVERLAY in the Makefile, org.mk) or set REGISTRY = crates-io"; exit 1; } +[ "$REGISTRY" != crates-io ] || { info " (crates.io registry: dependencies checked by deps-check-external)"; exit 0; } + +mode="${1:-check}" +case "$mode" in check | bump) ;; *) + err "usage: deps-check.sh [check|bump]" + exit 2 + ;; +esac + +[ -f "$CARGO_TOML" ] || exit 0 + +fail=0 +bad() { + err " ✗ $*" + fail=1 +} + +. "$(dirname "$0")/deps-lib.sh" + +decl="" +for m in "${manifests[@]}"; do + lines=$(grep -E "^[A-Za-z0-9_-]+[[:space:]]*=[[:space:]]*\{[^}]*registry[[:space:]]*=[[:space:]]*\"$REGISTRY\"" "$m" || true) + [ -n "$lines" ] && decl+="$(printf '%s\n' "$lines" | sed "s|^|$m |")"$'\n' +done + +if [ -z "$decl" ]; then + ok "✓ No dependency on registry $REGISTRY to check" + exit 0 +fi + +info "→ Freshness of the registry dependencies (registry $REGISTRY)..." +count=0 +updates="" +offline=0 +while IFS=$'\t' read -r manifest line; do + [ -n "$manifest" ] || continue + name=${line%%[[:space:]=]*} + req=$(printf '%s' "$line" | sed -nE 's/.*version[[:space:]]*=[[:space:]]*"([^"]*)".*/\1/p') + count=$((count + 1)) + if [ -z "$req" ]; then + bad "$name ($manifest): no \"version\" in the declaration" + continue + fi + + rc=0 + latest=$(latest_published "$name") || rc=$? + if [ "$rc" -eq 2 ]; then + offline=1 + continue + fi + if [ "$rc" -eq 1 ] || [ -z "$latest" ]; then + bad "$name ($manifest): no version published on registry $REGISTRY" + continue + fi + + acc=0 + req_accepts "$req" "$latest" || acc=$? + case "$acc" in + 2) bad "$name ($manifest): requirement \"$req\" cannot be parsed (write x.y, or x for a version ≥ 1)" ;; + 1) + if [ "$(printf '%s\n%s\n' "$req" "$latest" | sort -V | tail -n 1)" = "$latest" ]; then + if [ "$mode" = bump ]; then + new=$(req_for "$latest") + sed -E "/^${name}[[:space:]]*=.*registry[[:space:]]*=[[:space:]]*\"$REGISTRY\"/ s/(version[[:space:]]*=[[:space:]]*\")[^\"]*/\1$new/" "$manifest" >"$manifest.tmp" && + mv "$manifest.tmp" "$manifest" + info " $name ($manifest): \"$req\" → \"$new\" (latest published version: $latest)" + updates+="$name " + else + bad "$name ($manifest): the requirement \"$req\" does not accept the latest published version $latest → $name = { version = \"$(req_for "$latest")\", registry = \"$REGISTRY\" } (make deps-bump)" + fi + else + bad "$name ($manifest): the requirement \"$req\" is newer than the latest published version $latest (publication pending?)" + fi + ;; + esac + + # Cargo.lock: on the latest version if the dependency comes from the registry. + if [ -f Cargo.lock ]; then + locked=$(lock_entries | awk -v n="$name" -v r="/api/packages/$REGISTRY/" '$1 == n && index($3, r) { print $2 }' | sort -V | tail -n 1) + if [ -n "$locked" ] && [ "$locked" != "$latest" ] && [ "$acc" -eq 0 ]; then + if [ "$mode" = bump ]; then + updates+="$name " + else + bad "$name: Cargo.lock is on $locked, the latest published version is $latest → cargo update -p $name (make deps-bump)" + fi + fi + fi + + # Neighbouring folder: replaces the dependency in joint development. + if [ -f "../$name/Cargo.toml" ]; then + neighbor=$(sed -n 's/^version = "\(.*\)"/\1/p' "../$name/Cargo.toml" | head -n 1) + if [ -n "$neighbor" ] && [ "$neighbor" != "$latest" ]; then + if [ "$(printf '%s\n%s\n' "$neighbor" "$latest" | sort -V | tail -n 1)" = "$latest" ]; then + bad "$name: the neighbouring folder ../$name is at $neighbor, the registry at $latest → update the neighbour (jj git fetch)" + else + warn " ⚠ $name: the neighbouring folder ../$name ($neighbor) is newer than the published version ($latest): publication pending" + fi + fi + fi +done <<<"$decl" + +if [ "$offline" -eq 1 ]; then + if [ "${DEPS_CHECK_OFFLINE:-}" = 1 ]; then + warn " ⚠ registry unreachable: freshness of the dependencies not verified (DEPS_CHECK_OFFLINE=1)" + else + bad "registry $REGISTRY unreachable ($index_url): freshness cannot be verified (DEPS_CHECK_OFFLINE=1 to ignore)" + fi +fi + +# Cargo.lock: ignored patch and duplicates. +if [ -f Cargo.lock ]; then + unused=$(awk ' + /^\[\[patch.unused\]\]/ { u = 1; next } + /^\[/ { u = 0 } + u && /^name = / { gsub(/"/, "", $3); print $3 } + ' Cargo.lock | sort -u | paste -sd' ' -) + if [ -n "$unused" ] && [ "$mode" = check ]; then + bad "Cargo.lock: local patch ignored for $unused — the project's requirement does not accept the version of the neighbouring folder" + fi + dups=$(lock_entries | awk -v r="/api/packages/$REGISTRY/" ' + { c[$1]++; vs[$1] = vs[$1] " " $2; if ($3 == "-" || index($3, r)) p[$1] = 1 } + END { for (n in c) if (c[n] > 1 && p[n]) print n ":" vs[n] } + ') + if [ -n "$dups" ]; then + while IFS= read -r d; do + bad "Cargo.lock: several versions of ${d%%:*} in the build (${d#*: }) — align the requirements of the crates that depend on it" + done <<<"$dups" + fi +fi + +if [ "$mode" = bump ] && [ -n "$updates" ]; then + for n in $(printf '%s\n' $updates | sort -u); do + info " cargo update -p $n" + "$CARGO" update -p "$n" >/dev/null + done +fi + +if [ "$fail" -ne 0 ]; then + err "✗ Registry dependencies stale or inconsistent (see above)" + exit 1 +fi +ok "✓ Registry dependencies up to date ($count checked)" diff --git a/.crate-kit/scripts/deps-lib.sh b/.crate-kit/scripts/deps-lib.sh new file mode 100644 index 00000000..4c845480 --- /dev/null +++ b/.crate-kit/scripts/deps-lib.sh @@ -0,0 +1,75 @@ +#!/usr/bin/env bash +# Functions shared by the dependency checks (deps-check.sh, deps-check-external.sh). +# To be sourced after common.sh. Nothing here writes a file. + +index_url="${REGISTRY_INDEX#sparse+}" +index_url="${index_url%/}" + +# Path of a crate in a sparse index (1, 2, 3 characters, then two pairs). +index_path() { + local n + n=$(printf '%s' "$1" | tr 'A-Z' 'a-z') + case ${#n} in + 1) echo "1/$n" ;; + 2) echo "2/$n" ;; + 3) echo "3/${n:0:1}/$n" ;; + *) echo "${n:0:2}/${n:2:2}/$n" ;; + esac +} + +# Latest published version (not yanked, excluding pre-releases) of $1 in the sparse index $2 (default: +# the private registry); empty if not found. +# Code: 0 found, 1 absent from the index, 2 index unreachable. +latest_published() { + local body rc=0 base="${2:-$index_url}" + body=$(curl -sS -f -m 20 "$base/$(index_path "$1")" 2>/dev/null) || rc=$? + if [ "$rc" -ne 0 ]; then + case "$rc" in 22 | 37) return 1 ;; *) return 2 ;; esac + fi + printf '%s\n' "$body" | + sed -n 's/.*"vers":"\([^"]*\)".*"yanked":false.*/\1/p' | + grep -v -- '-' | sort -V | tail -n 1 +} + +# Does the requirement $1 (x, x.y or x.y.z, with optional ^) accept version $2? +# Code: 0 yes, 1 no, 2 unsupported form. +req_accepts() { + local r="${1#^}" v="$2" rmaj rmin rest vmaj vmin + case "$r" in '' | *[!0-9.]*) return 2 ;; esac + IFS=. read -r rmaj rmin rest <<<"$r" + IFS=. read -r vmaj vmin rest <<<"$v" + [ "$rmaj" = "$vmaj" ] || return 1 + if [ "$rmaj" = 0 ] && [ -n "$rmin" ]; then + [ "$rmin" = "$vmin" ] || return 1 + fi + return 0 +} + +# Minimal requirement that accepts version $1: x.y for a 0.x, x otherwise. +req_for() { + case "$1" in + 0.*) echo "$1" | cut -d. -f1,2 ;; + *) echo "$1" | cut -d. -f1 ;; + esac +} + +# Packages of Cargo.lock, one per line: "name version source" ("-" without source). The +# [[patch.unused]] blocks are excluded. +lock_entries() { + awk ' + function flush() { if (n != "") print n, v, (s == "" ? "-" : s); n = v = s = "" } + /^\[\[package\]\]/ { flush(); inpkg = 1; next } + /^\[/ { flush(); inpkg = 0; next } + inpkg && /^name = / { gsub(/"/, "", $3); n = $3 } + inpkg && /^version = / { gsub(/"/, "", $3); v = $3 } + inpkg && /^source = / { gsub(/"/, "", $3); s = $3 } + END { flush() } + ' Cargo.lock +} + +manifests=("$CARGO_TOML") +# Root of a workspace whose member CARGO_TOML designates (workspace): shared dependencies. +[ "$CARGO_TOML" != Cargo.toml ] && [ -f Cargo.toml ] && manifests+=(Cargo.toml) +for m in */Cargo.toml; do + if [ -f "$m" ]; then manifests+=("$m"); fi +done diff --git a/.crate-kit/scripts/dev-patch.sh b/.crate-kit/scripts/dev-patch.sh new file mode 100755 index 00000000..92cf2dd7 --- /dev/null +++ b/.crate-kit/scripts/dev-patch.sh @@ -0,0 +1,70 @@ +#!/usr/bin/env bash +# Generates .cargo/config.toml (local, ignored by jj) for joint development: +# - the definition of the private registry; +# - a [patch.] for each registry dependency that has a neighbouring folder +# (..//Cargo.toml), so that the project builds against the neighbouring code without publishing. +# Only the dependencies actually declared by this project are patched: no unused patch +# (Cargo complains about it), whatever the number of crates coming out of a workspace. +# +# Run by crate.mk on every make invocation. The file is rewritten only if it changes. +# Reads the root Cargo.toml and those of the direct subfolders (workspace members); +# only the dependencies on one line `name = { …, registry = "" }` are seen. +# A .cargo/config.toml that was not generated by this script is never overwritten (warning). +set -euo pipefail +. "$(dirname "$0")/common.sh" + +[ -f "$CARGO_TOML" ] || exit 0 +# Nothing to generate without a registry (no extension) nor for crates.io (cargo's default index and token). +[ -n "$REGISTRY" ] && [ "$REGISTRY" != crates-io ] || exit 0 + +marker="# Generated by .crate-kit/scripts/dev-patch.sh" +config=".cargo/config.toml" + +if [ -f "$config" ] && ! grep -q "^$marker" "$config"; then + warn "⚠ $config was not generated by the kit: left as is. If it is tracked by the repository," + warn " delete it and add /.cargo/config.toml to .gitignore (the CI uses an environment variable)." + exit 0 +fi + +self=$(crate_name) +manifests=("$CARGO_TOML") +# Root of a workspace whose member CARGO_TOML designates (workspace): this is where the shared +# dependencies ([workspace.dependencies]) are declared. +[ "$CARGO_TOML" != Cargo.toml ] && [ -f Cargo.toml ] && manifests+=(Cargo.toml) +for m in */Cargo.toml; do [ -f "$m" ] && manifests+=("$m"); done + +registry_deps() { + sed -nE "s/^([A-Za-z0-9_-]+)[[:space:]]*=[[:space:]]*\{[^}]*registry[[:space:]]*=[[:space:]]*\"$REGISTRY\".*/\1/p" "$@" +} +names=$(registry_deps "${manifests[@]}" | sort -u) +# Transitive closure through the neighbours: a dependency of a patched neighbour (a -> a-macros) +# must be patched too, otherwise the project builds the neighbour against the published version of its own +# dependency and not against the neighbouring code. +while :; do + more=$(for n in $names; do [ -f "../$n/Cargo.toml" ] && registry_deps "../$n/Cargo.toml"; done | sort -u) + merged=$(printf '%s\n%s\n' "$names" "$more" | sed '/^$/d' | sort -u) + [ "$merged" = "$names" ] && break + names=$merged +done + +patches="" +for n in $names; do + [ "$n" = "$self" ] && continue + [ -f "../$n/Cargo.toml" ] && patches+="$n = { path = \"../$n\" }"$'\n' +done + +new="$marker on every \`make\`: do not edit, do not commit (ignored by the repository). +# Private registry and, for joint development, dependencies resolved to the neighbouring folders. +[registries.$REGISTRY] +index = \"$REGISTRY_INDEX\" +" +[ -n "$patches" ] && new+=" +[patch.$REGISTRY] +$patches" + +if [ ! -f "$config" ] || [ "$(cat "$config")" != "${new%$'\n'}" ]; then + mkdir -p .cargo + printf '%s' "$new" >"$config" + list=$(printf '%s' "$patches" | sed 's/ = .*//' | paste -sd' ' -) + info " $config updated (local patches: ${list:-none})" +fi diff --git a/.crate-kit/scripts/forgejo-release.sh b/.crate-kit/scripts/forgejo-release.sh new file mode 100755 index 00000000..5490fa1f --- /dev/null +++ b/.crate-kit/scripts/forgejo-release.sh @@ -0,0 +1,56 @@ +#!/usr/bin/env bash +# Creates the Forgejo release associated with the tag version-x.y.z. Description: the message of the tag if it is +# annotated, otherwise (lightweight tag created by tag.sh) the file $RELEASE_NOTES_DIR/version-x.y.z.md of the +# working directory, which must be the checkout of the tag. Meant for the CI; idempotent: an already existing release is +# reused, and an attached file that is already present is not sent again. +# +# Variables (provided by the workflow): +# FORGETOKEN Forgejo API token (write access to releases) +# TAG tag to publish (e.g. version-0.1.4) +# SERVER Forgejo server URL (e.g. https://forge.example.org) +# REPO owner/repository (e.g. org/crate) +# ASSET optional: file to attach to the release (e.g. dist/crate-kit-0.1.4.tar.gz) +set -euo pipefail +. "$(dirname "$0")/common.sh" + +: "${FORGETOKEN:?FORGETOKEN required}" "${TAG:?TAG required}" "${SERVER:?SERVER required}" "${REPO:?REPO required}" +command -v jq >/dev/null || { err "✗ jq is required"; exit 1; } + +api="$SERVER/api/v1/repos/$REPO" +auth="Authorization: token $FORGETOKEN" + +if release_json=$(curl -sf -H "$auth" "$api/releases/tags/$TAG"); then + warn " The release $TAG already exists: reused" +else + # Message of the annotated tag (object of type "tag"); empty for a lightweight tag. + ref_json=$(forge_call "reading tag $TAG" -H "$auth" "$api/git/refs/tags/$TAG") || exit 1 + obj_sha=$(echo "$ref_json" | jq -r '.[0]?.object.sha // empty') + obj_type=$(echo "$ref_json" | jq -r '.[0]?.object.type // empty') + body="" + if [ "$obj_type" = "tag" ]; then + tag_json=$(forge_call "reading the message of tag $TAG" -H "$auth" "$api/git/tags/$obj_sha") || exit 1 + body=$(echo "$tag_json" | jq -r '.message // empty') + fi + # Lightweight tag (tag.sh, jj only): the notes are the file committed in the tagged revision, read in the + # working directory (the workflow runs in the checkout of the tag). + if [ -z "$body" ] && [ -f "$RELEASE_NOTES_DIR/$TAG.md" ]; then + body=$(cat "$RELEASE_NOTES_DIR/$TAG.md") + fi + release_json=$(forge_call "creating release $TAG" -X POST "$api/releases" -H "$auth" \ + -H "Content-Type: application/json" \ + -d "$(jq -n --arg tag "$TAG" --arg body "$body" '{tag_name: $tag, name: $tag, body: $body}')") || exit 1 + ok "✓ Release $TAG created" +fi + +if [ -n "${ASSET:-}" ]; then + [ -f "$ASSET" ] || { err "✗ file to attach not found: $ASSET"; exit 1; } + release_id=$(echo "$release_json" | jq -r '.id') + name=$(basename "$ASSET") + if echo "$release_json" | jq -e --arg n "$name" '.assets[]? | select(.name == $n)' >/dev/null; then + warn " $name is already attached to the release: nothing to do" + else + forge_call "uploading $name to release $TAG" -X POST "$api/releases/$release_id/assets?name=$name" \ + -H "$auth" -F "attachment=@$ASSET" >/dev/null || exit 1 + ok "✓ $name attached to release $TAG" + fi +fi diff --git a/.crate-kit/scripts/jjfetch.sh b/.crate-kit/scripts/jjfetch.sh new file mode 100755 index 00000000..0aeb5207 --- /dev/null +++ b/.crate-kit/scripts/jjfetch.sh @@ -0,0 +1,74 @@ +#!/usr/bin/env bash +# Fetches the latest commits from origin WITHOUT losing local work: the mutable revisions +# sitting on the old main are rebased on top of the fetched main@origin. +# +# - local work (mutable revisions between main@origin and @, including an empty working +# copy): rebased onto main@origin; +# - work sitting on a pushed revision not yet merged into main@origin (pending +# PR): left in place, with a warning (rebasing it would cut it off from that revision); +# - working copy already contained in main@origin: we start again from a new revision on top of it. +# +# JJ_BASE (default main@origin): the base to join. +set -euo pipefail +. "$(dirname "$0")/common.sh" + +base="${JJ_BASE:-main@origin}" + +info "→ Fetching the latest commits..." +jj git fetch + +jj log -r "$base" --no-graph -T 'change_id' >/dev/null 2>&1 || { + err "✗ $base not found after the fetch" + exit 1 +} + +# Local work = mutable revisions between the base and @ that are NOT already published (reachable +# from a remote bookmark): we do not rewrite what origin knows. We only keep the roots +# whose parent is already in the base's history. +work="(mutable() & ($base..@)) ~ ::remote_bookmarks()" + +# A local revision rewritten AFTER its push (describe, rebase…) then merged on the server side in its +# pushed version has a twin in $base: same change id, other commit, hence a divergent +# change. We never designate a revision by its change id (jj refuses a divergent +# identifier), and we do not rebase what is already merged: +# - same content as the merged twin: the local revision is abandoned (nothing is lost); +# - different content: we stop before rewriting anything, with the course of action to follow. +for c in $(jj log --no-graph -r "($work) & divergent()" -T 'commit_id ++ "\n"'); do + cid=$(jj log --no-graph -r "$c" -T 'change_id') + twin=$(jj log --no-graph -r "change_id($cid) & ::$base" -T 'commit_id ++ "\n"' | head -n 1) + [ -n "$twin" ] || continue + short=$(jj log --no-graph -r "$c" -T 'commit_id.short(12)') + if [ -z "$(jj interdiff --from "$twin" --to "$c" --summary)" ]; then + jj abandon "$c" + ok "✓ Revision $short already merged into $base (same content): abandoned" + else + err "✗ The local revision $short has already been merged into $base in another version" + err " (same change id, different content): nothing was rewritten." + err " See the difference: jj interdiff --from $twin --to $c" + err " Keep the merged version: jj abandon $c" + err " Keep the local version: jj metaedit --update-change-id $c, then rerun" + exit 1 + fi +done + +roots=$(jj log --no-graph -r "roots($work) & children(::$base)" -T 'commit_id ++ "\n"') + +if [ -n "$roots" ]; then + args=() + for r in $roots; do args+=(-s "$r"); done + jj rebase "${args[@]}" -d "$base" + ok "✓ Local work rebased onto $base" +elif [ -n "$(jj log --no-graph -r "@ & ::$base" -T 'change_id')" ]; then + # The working copy is already part of the base: nothing to keep. + jj new "$base" + ok "✓ New revision on $base" +elif [ -n "$(jj log --no-graph -r "($base..@) & (::remote_bookmarks() | immutable())" -T 'change_id')" ]; then + warn "⚠ The work rests on pushed revisions not merged into $base (pending PR):" + warn " left in place. Merge the PR then rerun, if needed." +else + ok "✓ Already up to date on $base" +fi + +if [ -n "$(jj log --no-graph -r 'conflicts() & ::@ & mutable()' -T 'change_id' 2>/dev/null)" ]; then + warn "⚠ Conflicts after the rebase: jj st, then jj resolve." +fi diff --git a/.crate-kit/scripts/kit-check.sh b/.crate-kit/scripts/kit-check.sh new file mode 100755 index 00000000..c1b26cda --- /dev/null +++ b/.crate-kit/scripts/kit-check.sh @@ -0,0 +1,68 @@ +#!/usr/bin/env bash +# Checks that the crate is adopted: the CI release workflow is installed and up to date with the template of +# its kind (comments and step names ignored; opt out with a `# kit-workflow: custom` line), and the kit copy +# (.crate-kit/) is identical to the reference kit (crate-kit + overlay, assembled by $KIT_SRC/tools/kit-assemble.sh; default ../crate-kit). Read-only. +# +# Compares the CONTENT, not VERSION: a fix to the kit does not always change its number. +# `--fix`: instead of failing on an out-of-date workflow, replace it with the template of its kind. +# Without a crate-kit repository alongside (clone of the crate alone, CI), there is nothing to compare: success. +set -euo pipefail +. "$(dirname "$0")/common.sh" + +fix=0 +[ "${1:-}" = "--fix" ] && fix=1 +kit_dir="$(cd "$(dirname "$0")/.." && pwd)" +crate_dir="$(dirname "$kit_dir")" + +# Without this workflow, a version-* tag publishes nothing: the crate was not adopted all the way. +workflow=".gitea/workflows/release.yaml" +if [ ! -f "$crate_dir/$workflow" ]; then + err "✗ $workflow is missing in $crate_dir: the release CI will not trigger" + info " Complete the adoption: crate-kit/adopt.sh [--kind ] $crate_dir" + exit 1 +fi + +kit_src="${KIT_SRC:-../crate-kit}" + +# Workflow up to date with the template of the crate's kind (the same one adopt.sh lays down). Only the +# logic counts: comment lines and `- name:` labels are ignored, so a rewording is not a difference. +if [ -x "$kit_src/tools/kit-assemble.sh" ] && ! grep -q '^# kit-workflow: custom' "$crate_dir/$workflow"; then + kind="${CRATE_KIND:-}" + if [ -z "$kind" ] && [ -f "$crate_dir/Makefile" ]; then + kind=$(sed -n 's/^CRATE_KIND *[:?]*= *\([a-z]*\).*/\1/p' "$crate_dir/Makefile" | head -n 1) + fi + template="$("$kit_src/tools/kit-assemble.sh" --root)/template" + overlay=$("$kit_src/tools/kit-assemble.sh" --overlay 2>/dev/null || true) + [ -n "$kind" ] && [ -n "$overlay" ] && [ -d "$overlay/templates/$kind" ] && template="$overlay/templates/$kind" + norm() { grep -v '^ *#' "$1" | grep -v '^ *- name:' | sed 's/[[:space:]]*$//'; } + if [ -f "$template/$workflow" ] && ! diff <(norm "$crate_dir/$workflow") <(norm "$template/$workflow") >/dev/null; then + if [ "$fix" = 1 ]; then + cp "$template/$workflow" "$crate_dir/$workflow" + ok "→ $workflow replaced with the template of its kind" + else + err "✗ $workflow differs from the template of its kind: the release CI is out of date" + diff <(norm "$crate_dir/$workflow") <(norm "$template/$workflow") >&2 || true + info " Replace it: cp $template/$workflow $crate_dir/$workflow" + info " (keep a deliberate customization by adding the line \"# kit-workflow: custom\" to the workflow)" + exit 1 + fi + fi +fi + +if [ ! -x "$kit_src/tools/kit-assemble.sh" ]; then + info " (reference kit not found: $kit_src, check skipped)" + exit 0 +fi +ref="$(mktemp -d "${TMPDIR:-/tmp}/kit-check.XXXXXX")" +trap 'rm -r "$ref"' EXIT +"$kit_src/tools/kit-assemble.sh" "$ref" + +if diff -rq "$ref" "$kit_dir" >/dev/null 2>&1; then + ok "✓ Kit up to date (crate-kit $(cat "$ref/VERSION"))" + exit 0 +fi + +err "✗ This crate's kit is not the one from $kit_src:" +diff -rq "$ref" "$kit_dir" >&2 || true +info " Update: make kit-update" +exit 1 diff --git a/.crate-kit/scripts/needs-commit.sh b/.crate-kit/scripts/needs-commit.sh new file mode 100755 index 00000000..1ccc7d5c --- /dev/null +++ b/.crate-kit/scripts/needs-commit.sh @@ -0,0 +1,77 @@ +#!/usr/bin/env bash +# Is there, in the crate's jj working copy (current directory), a change that justifies a +# commit, that is, something other than what the kit itself produces or modifies? Read-only. +# +# Do not count: +# - .crate-kit/ (kit copy) and .cargo/ (generated local configuration); +# - a template file (.gitea/workflows/release.yaml, LICENSE, .gitignore, Makefile…) identical to +# that of the kind's template (/templates/, otherwise crate-kit/template): adopt.sh laid it down as is; +# - Cargo.lock when only the `version` line of the crate itself changed (version bump); +# - the Makefile when only its kit bootstrap lines changed (KIT_SRC, copy or sync of +# .crate-kit/, comments that talk about the kit): the rest (description, PLUGIN_ID…) belongs to the crate. +# Without a crate-kit repository alongside ($KIT_SRC), the second filter cannot apply: these files +# then count as changes. +# +# Output: one file per line on standard output. Code 0 if there are any, 1 otherwise (nothing to commit). +set -euo pipefail +. "$(dirname "$0")/common.sh" + +kit_src="${KIT_SRC:-../crate-kit}" +kind="${CRATE_KIND:-}" +if [ -z "$kind" ] && [ -f Makefile ]; then + kind=$(sed -n 's/^CRATE_KIND *[:?]*= *\([a-z]*\).*/\1/p' Makefile | head -n 1) +fi +template="$("$kit_src/tools/kit-assemble.sh" --root)/template" +overlay=$("$kit_src/tools/kit-assemble.sh" --overlay 2>/dev/null || true) +[ -n "$kind" ] && [ -n "$overlay" ] && [ -d "$overlay/templates/$kind" ] && template="$overlay/templates/$kind" + +# Cargo.lock: did only the `version` line of the crate's package change? +lock_is_version_bump() { + local name + name=$(crate_name) + jj diff --git --context 1 Cargo.lock 2>/dev/null | awk -v name="$name" ' + /^(\+\+\+|---)/ { next } + /^@@/ { prev = ""; next } + /^[-+]/ { + changed++ + if ($0 !~ /^[-+]version = / || prev != " name = \"" name "\"") bad = 1 + next + } + /^ / { prev = $0 } + END { exit (changed > 0 && !bad) ? 0 : 1 }' +} + +# Makefile: did only the kit bootstrap lines change? Those that name KIT_SRC or +# `crate-kit` (variable, sync, copy of .crate-kit/) and the comments that talk about the kit; a +# modification of any other line (description, PLUGIN_ID, targets) is a real change of the crate. +makefile_is_kit_bootstrap() { + jj diff --git --context 1 Makefile 2>/dev/null | awk ' + /^(\+\+\+|---)/ { next } + /^[-+]/ { + changed++ + if ($0 !~ /KIT_SRC|crate-kit|kit-copy|^[-+]# .*[Kk]it/) bad = 1 + } + END { exit (changed > 0 && !bad) ? 0 : 1 }' +} + +found=0 +while IFS= read -r line; do + # Format of `jj diff --summary`: "M path"; a rename "R {a => b}" remains a change. + path="${line#? }" + case "$path" in + .crate-kit/* | .cargo/*) continue ;; + Cargo.lock) + if lock_is_version_bump; then continue; fi + ;; + Makefile) + if makefile_is_kit_bootstrap; then continue; fi + ;; + esac + if [ "${line%% *}" = M ] && [ -f "$template/$path" ] && cmp -s "$template/$path" "$path"; then + continue + fi + echo "$path" + found=1 +done < <(jj diff --summary) + +[ "$found" -eq 1 ] || { info " nothing to commit outside the kit" ; exit 1; } diff --git a/.crate-kit/scripts/new-commit.sh b/.crate-kit/scripts/new-commit.sh new file mode 100755 index 00000000..4ba9a6b3 --- /dev/null +++ b/.crate-kit/scripts/new-commit.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash +# Starts a new working commit (`jj new`), unless @ already is a blank one (empty, without a description). +# After a push of main, @ is usually already blank: when the pushed commit was @, it became immutable and jj +# itself created an empty working commit on top of it (operation "push bookmark main"). An unconditional +# `jj new` would then stack a second, useless empty commit. +set -euo pipefail +. "$(dirname "$0")/common.sh" + +blank=$(jj log -r @ --no-graph -T 'if(empty && description == "", "1", "0")') +if [ "$blank" = 1 ]; then + info " (@ is already an empty working commit: no new commit)" + exit 0 +fi +jj new diff --git a/.crate-kit/scripts/publish-guard.sh b/.crate-kit/scripts/publish-guard.sh new file mode 100755 index 00000000..e38cc490 --- /dev/null +++ b/.crate-kit/scripts/publish-guard.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash +# Safeguard: a crate published on a private registry declares `publish = [""]` in its +# Cargo.toml, so that cargo itself refuses any publication elsewhere (crates.io for example). +# Not applicable: kind without publication (PUBLISH=no), registry absent or crates-io. +set -euo pipefail +. "$(dirname "$0")/common.sh" +[ "${PUBLISH:-yes}" = no ] && exit 0 +{ [ -n "$REGISTRY" ] && [ "$REGISTRY" != crates-io ]; } || exit 0 +[ -f "$CARGO_TOML" ] || exit 0 +grep -qE "^publish[[:space:]]*=[[:space:]]*\[[[:space:]]*\"$REGISTRY\"[[:space:]]*\]" "$CARGO_TOML" && exit 0 +err "✗ $CARGO_TOML : publish = [\"$REGISTRY\"] missing in [package] (without it, cargo publish would accept crates.io)" +exit 1 diff --git a/.crate-kit/scripts/publish.sh b/.crate-kit/scripts/publish.sh new file mode 100755 index 00000000..1fa66d01 --- /dev/null +++ b/.crate-kit/scripts/publish.sh @@ -0,0 +1,38 @@ +#!/usr/bin/env bash +# Publishes the current version on the $REGISTRY registry (private, or crates-io with CARGO_REGISTRY_TOKEN). +# DRY_RUN non-empty: assembles and builds the package without sending it. +# +# Idempotent: if the version is already published, it is a success (allows replaying the release +# workflow after a later failure). Authentication: variable CARGO_REGISTRIES__TOKEN +# ("Bearer "), otherwise built from the forge token (forge_token: FORGETOKEN in CI). +# +# --allow-dirty: in a colocated jj repository, git always sees the working copy as +# modified relative to its HEAD, even when the jj commit is already pushed. +set -euo pipefail +. "$(dirname "$0")/common.sh" + +if [ "${PUBLISH:-yes}" = no ]; then + info " (kind ${CRATE_KIND:-crate}: nothing to publish on the registry)" + exit 0 +fi + +[ -n "$REGISTRY" ] || { err "✗ no registry: declare the kit extension (KIT_OVERLAY in the Makefile, org.mk) or set REGISTRY = crates-io"; exit 1; } +version=$(current_version) +name=$(crate_name) +if [ -n "${DRY_RUN:-}" ]; then + warn "→ Checking the publication of $name $version (without sending)..." + "$CARGO" publish --registry "$REGISTRY" --allow-dirty --dry-run + exit 0 +fi + +warn "→ Publishing $name $version on registry $REGISTRY..." +log=$(mktemp) +trap 'rm -f -- "$log"' EXIT +if "$CARGO" publish --registry "$REGISTRY" --allow-dirty 2>&1 | tee "$log" >&2; then + ok "✓ $name $version published" +elif grep -qiE 'already (exists|uploaded)|crate version .* is already' "$log"; then + warn " $name $version is already published on $REGISTRY: nothing to do" +else + err "✗ Publication of $name $version failed" + exit 1 +fi diff --git a/.crate-kit/scripts/push-main.sh b/.crate-kit/scripts/push-main.sh new file mode 100755 index 00000000..77c9df52 --- /dev/null +++ b/.crate-kit/scripts/push-main.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash +# Advances the main bookmark to the current commit (@, or its first non-empty ancestor if @ is an +# empty working commit without a description: release_rev) and pushes it: no PR branch, main receives +# the commit directly. Moving main must be a fast-forward (jj refuses otherwise): if +# main@origin has advanced, `make jjfetch` first rebases the local work onto it. +set -euo pipefail +. "$(dirname "$0")/common.sh" + +abandon_blank_commits +rev=$(release_rev) +if ! jj bookmark set main -r "$rev" 2>/dev/null; then + err "✗ main cannot advance to $rev (main has diverged or $rev does not descend from it)" + info " Run make jjfetch to rebase the work onto main@origin, then start again." + exit 1 +fi +jj git push --bookmark main diff --git a/.crate-kit/scripts/release-notes.sh b/.crate-kit/scripts/release-notes.sh new file mode 100755 index 00000000..1ae29f40 --- /dev/null +++ b/.crate-kit/scripts/release-notes.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash +# Generates $RELEASE_NOTES_DIR/version-.md: notes produced by `jj release-notes` +# (fallback to one line if they fail, e.g. before the first tag), then adds a +# "Public API" section with the snapshot diff since the previous version. +set -euo pipefail +. "$(dirname "$0")/common.sh" + +version=$(current_version) +notes="$RELEASE_NOTES_DIR/version-$version.md" +info "→ Generating the release notes ($notes)..." +mkdir -p "$RELEASE_NOTES_DIR" + +PMOJJ_RELEASE_LANG="${KIT_LANG:-en}" PMOJJ_RELEASE_PROJECT="${RELEASE_PROJECT_DESC:-$(crate_name)}" jj release-notes --release "$version" >"$notes" || + echo "Release version-$version" >"$notes" + +prev=$(ls "$API_DIR"/*.txt 2>/dev/null | sed 's|.*/||; s|\.txt$||' | sort -V | + grep -v -x "$version" | tail -n 1 || true) +if [ -n "$prev" ] && [ -f "$API_DIR/$version.txt" ]; then + api_diff=$(diff <(filter_notes "$API_DIR/$prev.txt") <(filter_notes "$API_DIR/$version.txt") | grep '^[<>]' || true) + if [ -n "$api_diff" ]; then + printf '\n## Public API (changes since %s)\n\n```diff\n%s\n```\n' \ + "$prev" "$api_diff" >>"$notes" + fi +fi diff --git a/.crate-kit/scripts/tag-exists.sh b/.crate-kit/scripts/tag-exists.sh new file mode 100755 index 00000000..d5a88995 --- /dev/null +++ b/.crate-kit/scripts/tag-exists.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash +# Does the release tag `version-` already exist (locally or on origin)? jj only, no git command. +# Usage: tag-exists.sh +# Exit: 0 = the tag exists, 1 = it does not, 2 = not checked (no jj repository, origin unreachable). +# jj has no equivalent of `ls-remote`: the tag alone is fetched (`jj git fetch --tag`), which imports it as a +# tracked remote tag if it exists on origin and changes nothing else, then `jj tag list` tells. +set -uo pipefail + +version="${1:?usage: tag-exists.sh }" +tag="version-$version" + +jj root >/dev/null 2>&1 || exit 2 +jj git fetch --tag "exact:$tag" >/dev/null 2>&1 || exit 2 +if [ -n "$(jj tag list "exact:$tag" -T 'name ++ "\n"' 2>/dev/null)" ]; then + exit 0 +fi +exit 1 diff --git a/.crate-kit/scripts/tag.sh b/.crate-kit/scripts/tag.sh new file mode 100755 index 00000000..e8292642 --- /dev/null +++ b/.crate-kit/scripts/tag.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash +# Creates and pushes the tag version- on the published commit (release_rev: @, or its first +# non-empty ancestor), with jj only. The tag is lightweight (jj creates no annotated tag): the release notes +# are not its message but the file $RELEASE_NOTES_DIR/version-.md committed in the tagged revision, +# which forgejo-release.sh reads in the CI as the body of the release. +set -euo pipefail +. "$(dirname "$0")/common.sh" + +version=$(current_version) +tag="version-$version" +notes="$RELEASE_NOTES_DIR/$tag.md" +[ -f "$notes" ] || { err "✗ release notes missing: $notes (make release-notes)"; exit 1; } +if [ -n "$(jj tag list "exact:$tag" 2>/dev/null)" ]; then + err "✗ tag $tag already exists" + exit 1 +fi +rev=$(release_rev) +jj tag set "$tag" -r "$rev" +jj git push --tag "exact:$tag" +ok "✓ Release $tag published" diff --git a/.crate-kit/scripts/wiki.sh b/.crate-kit/scripts/wiki.sh new file mode 100755 index 00000000..6e710322 --- /dev/null +++ b/.crate-kit/scripts/wiki.sh @@ -0,0 +1,141 @@ +#!/usr/bin/env bash +# Publishes the API documentation (rustdoc -> JSON -> Markdown) to the crate's Forgejo wiki. +# +# The Forgejo wiki is a second repository (.wiki.git). It is never kept: the script +# clones it into a temporary directory (git), replaces the generated pages, commits and pushes, then +# removes the clone. Works identically locally and in the CI (release workflow). +# +# Pages produced: Home.md (module index), _Sidebar.md, one page per module. +# The wiki content is ENTIRELY replaced: any page written by hand on the Forgejo side +# disappears at the next run. +# +# Variables: +# WIKI_URL wiki repository URL (default: `origin` URL with .git replaced by .wiki.git) +# WIKI_TOKEN access token (CI, https URL): sent in the header "Authorization: token …" +# GIT_USER_NAME / GIT_USER_EMAIL commit identity if git has none configured +# DRY_RUN non-empty: generates and commits in the temporary clone, shows the diff, does not push +# +# Prerequisites: cargo-doc-md (cargo install cargo-doc-md --locked); the wiki must exist on the +# Forgejo side (create a first page by hand once per crate, otherwise the repository is not found). +set -euo pipefail +. "$(dirname "$0")/common.sh" + +if [ "${WIKI:-yes}" = no ]; then + info " (kind ${CRATE_KIND:-crate}: no API documentation for the wiki)" + exit 0 +fi + +require_cargo_tool doc-md cargo-doc-md + +name=$(crate_name) +version=$(current_version) + +# Wiki URL: that of origin, with .git replaced by .wiki.git. +if [ -z "${WIKI_URL:-}" ]; then + origin=$(git remote get-url origin 2>/dev/null || true) + [ -n "$origin" ] || { err "✗ remote origin not found: set WIKI_URL=..."; exit 1; } + WIKI_URL="${origin%.git}.wiki.git" +fi + +# Common git options: token in a header (CI) and fallback identity. +git_opts=() +if [ -n "${WIKI_TOKEN:-}" ]; then + git_opts+=(-c "http.extraHeader=Authorization: token $WIKI_TOKEN") +fi +if [ -z "$(git config user.name 2>/dev/null || true)" ]; then + git_opts+=(-c "user.name=${GIT_USER_NAME:-crate-kit}") +fi +if [ -z "$(git config user.email 2>/dev/null || true)" ]; then + git_opts+=(-c "user.email=${GIT_USER_EMAIL:-crate-kit@localhost}") +fi +wgit() { git "${git_opts[@]}" "$@"; } + +work=$(mktemp -d "${TMPDIR:-/tmp}/crate-kit-wiki.XXXXXX") +[ -n "$work" ] && [ -d "$work" ] || { err "✗ temporary directory not created"; exit 1; } +trap 'rm -rf -- "$work"' EXIT + +# 1. Rustdoc -> Markdown (one file per module, in $work/md//). +info "→ Generating the Markdown ($name $version)..." +"$CARGO" doc-md --no-deps -o "$work/md" >&2 +src="$work/md/$name" +[ -f "$src/index.md" ] || { + # The folder name follows the library name (hyphens -> underscores). + src="$work/md/${name//-/_}" + [ -f "$src/index.md" ] || { err "✗ index.md not found in $work/md"; exit 1; } +} + +# 2. Wiki pages: flat, links between pages without the .md extension (Forgejo wiki convention). +pages="$work/pages" +mkdir -p "$pages" +for f in "$src"/*.md; do + base=$(basename "$f") + [ "$base" = index.md ] && continue + cp "$f" "$pages/$base" +done +# Home = crate index as produced by cargo-doc-md (title, crate doc, modules); +# the version appears in the sidebar. +sed -E 's/\]\(([^)#]+)\.md\)/](\1)/g' "$src/index.md" >"$pages/Home.md" +{ + printf '**[%s](Home)** %s\n\n' "$name" "$version" + sed -nE 's/^### \[`([^`]+)`\]\(([^)]+)\.md\).*/- [\1](\2)/p' "$src/index.md" +} >"$pages/_Sidebar.md" + +# Rustdoc intra-doc links (``[`item`]``, ``[`module::item`]``): cargo-doc-md does not resolve them +# and leaves them in literal brackets. We resolve them here to the wiki page that defines +# the item (table built from the "Contents" of each module page); a module +# points to its own page. Names not found (std, other crates) lose their +# brackets and remain as code. +map="$work/map" +: >"$map" +for f in "$pages"/*.md; do + p=$(basename "$f" .md) + case "$p" in Home | _Sidebar) continue ;; esac + echo "$p $p" >>"$map" +done +for f in "$pages"/*.md; do + p=$(basename "$f" .md) + case "$p" in Home | _Sidebar) continue ;; esac + sed -nE 's/^- \[`([A-Za-z0-9_]+)`\]\(#.*/\1 '"$p"'/p' "$f" >>"$map" +done +resolve="$work/resolve.sed" +: >"$resolve" +while read -r item page; do + # First wins: the module pages (lines at the start) take precedence; an item already + # turned into a link is no longer a candidate (it is followed by "("). + printf 's/\\[`((([A-Za-z0-9_]+::)*)%s)`\\]([^(:[]|$)/[`\\1`](%s)\\4/g\n' "$item" "$page" >>"$resolve" +done <"$map" +for f in "$pages"/*.md; do + sed -E -f "$resolve" "$f" | sed -E 's/\[(`[^`]+`)\]([^(:[]|$)/\1\2/g' >"$f.tmp" + mv "$f.tmp" "$f" +done + +# 3. Clone the wiki, replace the pages, commit, push. +info "→ Cloning the wiki ${WIKI_URL}..." +clone="$work/clone" +wgit clone --quiet "$WIKI_URL" "$clone" >&2 || { + err "✗ cannot clone: does the wiki exist? (create a first page on Forgejo)" + exit 1 +} +cd "$clone" + +# Default branch of the wiki (master or main depending on the instance): the one the clone checked out. +branch=$(git symbolic-ref --short HEAD) + +# The generated files replace all the .md; the rest (images…) is kept. +find . -maxdepth 1 -name '*.md' -type f -delete +cp "$pages"/*.md . +git add -A + +if [ -z "$(git status --porcelain)" ]; then + ok "✓ Wiki already up to date" + exit 0 +fi + +git diff --cached --stat >&2 +wgit commit --quiet -m "API documentation: $name $version" +if [ -n "${DRY_RUN:-}" ]; then + warn "→ DRY_RUN: local commit in the temporary clone, nothing is pushed" + exit 0 +fi +wgit push --quiet origin "$branch" >&2 +ok "✓ Wiki of $name updated ($version)" diff --git a/.gitignore b/.gitignore index f0bf8a7c..691592a6 100644 --- a/.gitignore +++ b/.gitignore @@ -45,3 +45,6 @@ biblio *.ckp.gz *.model scripts/__pycache__/mk_wiki.cpython-314.pyc + +# Generated by .crate-kit/dev-patch.mk at every make +/.cargo/config.toml diff --git a/LICENSE b/LICENSE new file mode 100644 index 00000000..be9a324c --- /dev/null +++ b/LICENSE @@ -0,0 +1,550 @@ + + CONTRAT DE LICENCE DE LOGICIEL LIBRE CeCILL + +Version 2.1 du 2013-06-21 + + + Avertissement + +Ce contrat est une licence de logiciel libre issue d'une concertation +entre ses auteurs afin que le respect de deux grands principes préside à +sa rédaction: + + * d'une part, le respect des principes de diffusion des logiciels + libres: accès au code source, droits étendus conférés aux utilisateurs, + * d'autre part, la désignation d'un droit applicable, le droit + français, auquel elle est conforme, tant au regard du droit de la + responsabilité civile que du droit de la propriété intellectuelle et + de la protection qu'il offre aux auteurs et titulaires des droits + patrimoniaux sur un logiciel. + +Les auteurs de la licence CeCILL (Ce[a] C[nrs] I[nria] L[ogiciel] L[ibre]) +sont: + +Commissariat à l'énergie atomique et aux énergies alternatives - CEA, +établissement public de recherche à caractère scientifique, technique et +industriel, dont le siège est situé 25 rue Leblanc, immeuble Le Ponant +D, 75015 Paris. + +Centre National de la Recherche Scientifique - CNRS, établissement +public à caractère scientifique et technologique, dont le siège est +situé 3 rue Michel-Ange, 75794 Paris cedex 16. + +Institut National de Recherche en Informatique et en Automatique - +Inria, établissement public à caractère scientifique et technologique, +dont le siège est situé Domaine de Voluceau, Rocquencourt, BP 105, 78153 +Le Chesnay cedex. + + + Préambule + +Ce contrat est une licence de logiciel libre dont l'objectif est de +conférer aux utilisateurs la liberté de modification et de +redistribution du logiciel régi par cette licence dans le cadre d'un +modèle de diffusion en logiciel libre. + +L'exercice de ces libertés est assorti de certains devoirs à la charge +des utilisateurs afin de préserver ce statut au cours des +redistributions ultérieures. + +L'accessibilité au code source et les droits de copie, de modification +et de redistribution qui en découlent ont pour contrepartie de n'offrir +aux utilisateurs qu'une garantie limitée et de ne faire peser sur +l'auteur du logiciel, le titulaire des droits patrimoniaux et les +concédants successifs qu'une responsabilité restreinte. + +A cet égard l'attention de l'utilisateur est attirée sur les risques +associés au chargement, à l'utilisation, à la modification et/ou au +développement et à la reproduction du logiciel par l'utilisateur étant +donné sa spécificité de logiciel libre, qui peut le rendre complexe à +manipuler et qui le réserve donc à des développeurs ou des +professionnels avertis possédant des connaissances informatiques +approfondies. Les utilisateurs sont donc invités à charger et tester +l'adéquation du logiciel à leurs besoins dans des conditions permettant +d'assurer la sécurité de leurs systèmes et/ou de leurs données et, plus +généralement, à l'utiliser et l'exploiter dans les mêmes conditions de +sécurité. Ce contrat peut être reproduit et diffusé librement, sous +réserve de le conserver en l'état, sans ajout ni suppression de clauses. + +Ce contrat est susceptible de s'appliquer à tout logiciel dont le +titulaire des droits patrimoniaux décide de soumettre l'exploitation aux +dispositions qu'il contient. + +Une liste de questions fréquemment posées se trouve sur le site web +officiel de la famille des licences CeCILL +(http://www.cecill.info/index.fr.html) pour toute clarification qui +serait nécessaire. + + + Article 1 - DEFINITIONS + +Dans ce contrat, les termes suivants, lorsqu'ils seront écrits avec une +lettre capitale, auront la signification suivante: + +Contrat: désigne le présent contrat de licence, ses éventuelles versions +postérieures et annexes. + +Logiciel: désigne le logiciel sous sa forme de Code Objet et/ou de Code +Source et le cas échéant sa documentation, dans leur état au moment de +l'acceptation du Contrat par le Licencié. + +Logiciel Initial: désigne le Logiciel sous sa forme de Code Source et +éventuellement de Code Objet et le cas échéant sa documentation, dans +leur état au moment de leur première diffusion sous les termes du Contrat. + +Logiciel Modifié: désigne le Logiciel modifié par au moins une +Contribution. + +Code Source: désigne l'ensemble des instructions et des lignes de +programme du Logiciel et auquel l'accès est nécessaire en vue de +modifier le Logiciel. + +Code Objet: désigne les fichiers binaires issus de la compilation du +Code Source. + +Titulaire: désigne le ou les détenteurs des droits patrimoniaux d'auteur +sur le Logiciel Initial. + +Licencié: désigne le ou les utilisateurs du Logiciel ayant accepté le +Contrat. + +Contributeur: désigne le Licencié auteur d'au moins une Contribution. + +Concédant: désigne le Titulaire ou toute personne physique ou morale +distribuant le Logiciel sous le Contrat. + +Contribution: désigne l'ensemble des modifications, corrections, +traductions, adaptations et/ou nouvelles fonctionnalités intégrées dans +le Logiciel par tout Contributeur, ainsi que tout Module Interne. + +Module: désigne un ensemble de fichiers sources y compris leur +documentation qui permet de réaliser des fonctionnalités ou services +supplémentaires à ceux fournis par le Logiciel. + +Module Externe: désigne tout Module, non dérivé du Logiciel, tel que ce +Module et le Logiciel s'exécutent dans des espaces d'adressage +différents, l'un appelant l'autre au moment de leur exécution. + +Module Interne: désigne tout Module lié au Logiciel de telle sorte +qu'ils s'exécutent dans le même espace d'adressage. + +GNU GPL: désigne la GNU General Public License dans sa version 2 ou +toute version ultérieure, telle que publiée par Free Software Foundation +Inc. + +GNU Affero GPL: désigne la GNU Affero General Public License dans sa +version 3 ou toute version ultérieure, telle que publiée par Free +Software Foundation Inc. + +EUPL: désigne la Licence Publique de l'Union européenne dans sa version +1.1 ou toute version ultérieure, telle que publiée par la Commission +Européenne. + +Parties: désigne collectivement le Licencié et le Concédant. + +Ces termes s'entendent au singulier comme au pluriel. + + + Article 2 - OBJET + +Le Contrat a pour objet la concession par le Concédant au Licencié d'une +licence non exclusive, cessible et mondiale du Logiciel telle que +définie ci-après à l'article 5 <#etendue> pour toute la durée de +protection des droits portant sur ce Logiciel. + + + Article 3 - ACCEPTATION + +3.1 L'acceptation par le Licencié des termes du Contrat est réputée +acquise du fait du premier des faits suivants: + + * (i) le chargement du Logiciel par tout moyen notamment par + téléchargement à partir d'un serveur distant ou par chargement à + partir d'un support physique; + * (ii) le premier exercice par le Licencié de l'un quelconque des + droits concédés par le Contrat. + +3.2 Un exemplaire du Contrat, contenant notamment un avertissement +relatif aux spécificités du Logiciel, à la restriction de garantie et à +la limitation à un usage par des utilisateurs expérimentés a été mis à +disposition du Licencié préalablement à son acceptation telle que +définie à l'article 3.1 <#acceptation-acquise> ci dessus et le Licencié +reconnaît en avoir pris connaissance. + + + Article 4 - ENTREE EN VIGUEUR ET DUREE + + + 4.1 ENTREE EN VIGUEUR + +Le Contrat entre en vigueur à la date de son acceptation par le Licencié +telle que définie en 3.1 <#acceptation-acquise>. + + + 4.2 DUREE + +Le Contrat produira ses effets pendant toute la durée légale de +protection des droits patrimoniaux portant sur le Logiciel. + + + Article 5 - ETENDUE DES DROITS CONCEDES + +Le Concédant concède au Licencié, qui accepte, les droits suivants sur +le Logiciel pour toutes destinations et pour la durée du Contrat dans +les conditions ci-après détaillées. + +Par ailleurs, si le Concédant détient ou venait à détenir un ou +plusieurs brevets d'invention protégeant tout ou partie des +fonctionnalités du Logiciel ou de ses composants, il s'engage à ne pas +opposer les éventuels droits conférés par ces brevets aux Licenciés +successifs qui utiliseraient, exploiteraient ou modifieraient le +Logiciel. En cas de cession de ces brevets, le Concédant s'engage à +faire reprendre les obligations du présent alinéa aux cessionnaires. + + + 5.1 DROIT D'UTILISATION + +Le Licencié est autorisé à utiliser le Logiciel, sans restriction quant +aux domaines d'application, étant ci-après précisé que cela comporte: + + 1. + + la reproduction permanente ou provisoire du Logiciel en tout ou + partie par tout moyen et sous toute forme. + + 2. + + le chargement, l'affichage, l'exécution, ou le stockage du Logiciel + sur tout support. + + 3. + + la possibilité d'en observer, d'en étudier, ou d'en tester le + fonctionnement afin de déterminer les idées et principes qui sont à + la base de n'importe quel élément de ce Logiciel; et ceci, lorsque + le Licencié effectue toute opération de chargement, d'affichage, + d'exécution, de transmission ou de stockage du Logiciel qu'il est en + droit d'effectuer en vertu du Contrat. + + + 5.2 DROIT D'APPORTER DES CONTRIBUTIONS + +Le droit d'apporter des Contributions comporte le droit de traduire, +d'adapter, d'arranger ou d'apporter toute autre modification au Logiciel +et le droit de reproduire le logiciel en résultant. + +Le Licencié est autorisé à apporter toute Contribution au Logiciel sous +réserve de mentionner, de façon explicite, son nom en tant qu'auteur de +cette Contribution et la date de création de celle-ci. + + + 5.3 DROIT DE DISTRIBUTION + +Le droit de distribution comporte notamment le droit de diffuser, de +transmettre et de communiquer le Logiciel au public sur tout support et +par tout moyen ainsi que le droit de mettre sur le marché à titre +onéreux ou gratuit, un ou des exemplaires du Logiciel par tout procédé. + +Le Licencié est autorisé à distribuer des copies du Logiciel, modifié ou +non, à des tiers dans les conditions ci-après détaillées. + + + 5.3.1 DISTRIBUTION DU LOGICIEL SANS MODIFICATION + +Le Licencié est autorisé à distribuer des copies conformes du Logiciel, +sous forme de Code Source ou de Code Objet, à condition que cette +distribution respecte les dispositions du Contrat dans leur totalité et +soit accompagnée: + + 1. + + d'un exemplaire du Contrat, + + 2. + + d'un avertissement relatif à la restriction de garantie et de + responsabilité du Concédant telle que prévue aux articles 8 + <#responsabilite> et 9 <#garantie>, + +et que, dans le cas où seul le Code Objet du Logiciel est redistribué, +le Licencié permette un accès effectif au Code Source complet du +Logiciel pour une durée d'au moins 3 ans à compter de la distribution du +logiciel, étant entendu que le coût additionnel d'acquisition du Code +Source ne devra pas excéder le simple coût de transfert des données. + + + 5.3.2 DISTRIBUTION DU LOGICIEL MODIFIE + +Lorsque le Licencié apporte une Contribution au Logiciel, les conditions +de distribution du Logiciel Modifié en résultant sont alors soumises à +l'intégralité des dispositions du Contrat. + +Le Licencié est autorisé à distribuer le Logiciel Modifié, sous forme de +code source ou de code objet, à condition que cette distribution +respecte les dispositions du Contrat dans leur totalité et soit +accompagnée: + + 1. + + d'un exemplaire du Contrat, + + 2. + + d'un avertissement relatif à la restriction de garantie et de + responsabilité du Concédant telle que prévue aux articles 8 + <#responsabilite> et 9 <#garantie>, + +et, dans le cas où seul le code objet du Logiciel Modifié est redistribué, + + 3. + + d'une note précisant les conditions d'accès effectif au code source + complet du Logiciel Modifié, pendant une période d'au moins 3 ans à + compter de la distribution du Logiciel Modifié, étant entendu que le + coût additionnel d'acquisition du code source ne devra pas excéder + le simple coût de transfert des données. + + + 5.3.3 DISTRIBUTION DES MODULES EXTERNES + +Lorsque le Licencié a développé un Module Externe les conditions du +Contrat ne s'appliquent pas à ce Module Externe, qui peut être distribué +sous un contrat de licence différent. + + + 5.3.4 COMPATIBILITE AVEC D'AUTRES LICENCES + +Le Licencié peut inclure un code soumis aux dispositions d'une des +versions de la licence GNU GPL, GNU Affero GPL et/ou EUPL dans le +Logiciel modifié ou non et distribuer l'ensemble sous les conditions de +la même version de la licence GNU GPL, GNU Affero GPL et/ou EUPL. + +Le Licencié peut inclure le Logiciel modifié ou non dans un code soumis +aux dispositions d'une des versions de la licence GNU GPL, GNU Affero +GPL et/ou EUPL et distribuer l'ensemble sous les conditions de la même +version de la licence GNU GPL, GNU Affero GPL et/ou EUPL. + + + Article 6 - PROPRIETE INTELLECTUELLE + + + 6.1 SUR LE LOGICIEL INITIAL + +Le Titulaire est détenteur des droits patrimoniaux sur le Logiciel +Initial. Toute utilisation du Logiciel Initial est soumise au respect +des conditions dans lesquelles le Titulaire a choisi de diffuser son +oeuvre et nul autre n'a la faculté de modifier les conditions de +diffusion de ce Logiciel Initial. + +Le Titulaire s'engage à ce que le Logiciel Initial reste au moins régi +par le Contrat et ce, pour la durée visée à l'article 4.2 <#duree>. + + + 6.2 SUR LES CONTRIBUTIONS + +Le Licencié qui a développé une Contribution est titulaire sur celle-ci +des droits de propriété intellectuelle dans les conditions définies par +la législation applicable. + + + 6.3 SUR LES MODULES EXTERNES + +Le Licencié qui a développé un Module Externe est titulaire sur celui-ci +des droits de propriété intellectuelle dans les conditions définies par +la législation applicable et reste libre du choix du contrat régissant +sa diffusion. + + + 6.4 DISPOSITIONS COMMUNES + +Le Licencié s'engage expressément: + + 1. + + à ne pas supprimer ou modifier de quelque manière que ce soit les + mentions de propriété intellectuelle apposées sur le Logiciel; + + 2. + + à reproduire à l'identique lesdites mentions de propriété + intellectuelle sur les copies du Logiciel modifié ou non. + +Le Licencié s'engage à ne pas porter atteinte, directement ou +indirectement, aux droits de propriété intellectuelle du Titulaire et/ou +des Contributeurs sur le Logiciel et à prendre, le cas échéant, à +l'égard de son personnel toutes les mesures nécessaires pour assurer le +respect des dits droits de propriété intellectuelle du Titulaire et/ou +des Contributeurs. + + + Article 7 - SERVICES ASSOCIES + +7.1 Le Contrat n'oblige en aucun cas le Concédant à la réalisation de +prestations d'assistance technique ou de maintenance du Logiciel. + +Cependant le Concédant reste libre de proposer ce type de services. Les +termes et conditions d'une telle assistance technique et/ou d'une telle +maintenance seront alors déterminés dans un acte séparé. Ces actes de +maintenance et/ou assistance technique n'engageront que la seule +responsabilité du Concédant qui les propose. + +7.2 De même, tout Concédant est libre de proposer, sous sa seule +responsabilité, à ses licenciés une garantie, qui n'engagera que lui, +lors de la redistribution du Logiciel et/ou du Logiciel Modifié et ce, +dans les conditions qu'il souhaite. Cette garantie et les modalités +financières de son application feront l'objet d'un acte séparé entre le +Concédant et le Licencié. + + + Article 8 - RESPONSABILITE + +8.1 Sous réserve des dispositions de l'article 8.2 +<#limite-responsabilite>, le Licencié a la faculté, sous réserve de +prouver la faute du Concédant concerné, de solliciter la réparation du +préjudice direct qu'il subirait du fait du Logiciel et dont il apportera +la preuve. + +8.2 La responsabilité du Concédant est limitée aux engagements pris en +application du Contrat et ne saurait être engagée en raison notamment: +(i) des dommages dus à l'inexécution, totale ou partielle, de ses +obligations par le Licencié, (ii) des dommages directs ou indirects +découlant de l'utilisation ou des performances du Logiciel subis par le +Licencié et (iii) plus généralement d'un quelconque dommage indirect. En +particulier, les Parties conviennent expressément que tout préjudice +financier ou commercial (par exemple perte de données, perte de +bénéfices, perte d'exploitation, perte de clientèle ou de commandes, +manque à gagner, trouble commercial quelconque) ou toute action dirigée +contre le Licencié par un tiers, constitue un dommage indirect et +n'ouvre pas droit à réparation par le Concédant. + + + Article 9 - GARANTIE + +9.1 Le Licencié reconnaît que l'état actuel des connaissances +scientifiques et techniques au moment de la mise en circulation du +Logiciel ne permet pas d'en tester et d'en vérifier toutes les +utilisations ni de détecter l'existence d'éventuels défauts. L'attention +du Licencié a été attirée sur ce point sur les risques associés au +chargement, à l'utilisation, la modification et/ou au développement et à +la reproduction du Logiciel qui sont réservés à des utilisateurs avertis. + +Il relève de la responsabilité du Licencié de contrôler, par tous +moyens, l'adéquation du produit à ses besoins, son bon fonctionnement et +de s'assurer qu'il ne causera pas de dommages aux personnes et aux biens. + +9.2 Le Concédant déclare de bonne foi être en droit de concéder +l'ensemble des droits attachés au Logiciel (comprenant notamment les +droits visés à l'article 5 <#etendue>). + +9.3 Le Licencié reconnaît que le Logiciel est fourni "en l'état" par le +Concédant sans autre garantie, expresse ou tacite, que celle prévue à +l'article 9.2 <#bonne-foi> et notamment sans aucune garantie sur sa +valeur commerciale, son caractère sécurisé, innovant ou pertinent. + +En particulier, le Concédant ne garantit pas que le Logiciel est exempt +d'erreur, qu'il fonctionnera sans interruption, qu'il sera compatible +avec l'équipement du Licencié et sa configuration logicielle ni qu'il +remplira les besoins du Licencié. + +9.4 Le Concédant ne garantit pas, de manière expresse ou tacite, que le +Logiciel ne porte pas atteinte à un quelconque droit de propriété +intellectuelle d'un tiers portant sur un brevet, un logiciel ou sur tout +autre droit de propriété. Ainsi, le Concédant exclut toute garantie au +profit du Licencié contre les actions en contrefaçon qui pourraient être +diligentées au titre de l'utilisation, de la modification, et de la +redistribution du Logiciel. Néanmoins, si de telles actions sont +exercées contre le Licencié, le Concédant lui apportera son expertise +technique et juridique pour sa défense. Cette expertise technique et +juridique est déterminée au cas par cas entre le Concédant concerné et +le Licencié dans le cadre d'un protocole d'accord. Le Concédant dégage +toute responsabilité quant à l'utilisation de la dénomination du +Logiciel par le Licencié. Aucune garantie n'est apportée quant à +l'existence de droits antérieurs sur le nom du Logiciel et sur +l'existence d'une marque. + + + Article 10 - RESILIATION + +10.1 En cas de manquement par le Licencié aux obligations mises à sa +charge par le Contrat, le Concédant pourra résilier de plein droit le +Contrat trente (30) jours après notification adressée au Licencié et +restée sans effet. + +10.2 Le Licencié dont le Contrat est résilié n'est plus autorisé à +utiliser, modifier ou distribuer le Logiciel. Cependant, toutes les +licences qu'il aura concédées antérieurement à la résiliation du Contrat +resteront valides sous réserve qu'elles aient été effectuées en +conformité avec le Contrat. + + + Article 11 - DISPOSITIONS DIVERSES + + + 11.1 CAUSE EXTERIEURE + +Aucune des Parties ne sera responsable d'un retard ou d'une défaillance +d'exécution du Contrat qui serait dû à un cas de force majeure, un cas +fortuit ou une cause extérieure, telle que, notamment, le mauvais +fonctionnement ou les interruptions du réseau électrique ou de +télécommunication, la paralysie du réseau liée à une attaque +informatique, l'intervention des autorités gouvernementales, les +catastrophes naturelles, les dégâts des eaux, les tremblements de terre, +le feu, les explosions, les grèves et les conflits sociaux, l'état de +guerre... + +11.2 Le fait, par l'une ou l'autre des Parties, d'omettre en une ou +plusieurs occasions de se prévaloir d'une ou plusieurs dispositions du +Contrat, ne pourra en aucun cas impliquer renonciation par la Partie +intéressée à s'en prévaloir ultérieurement. + +11.3 Le Contrat annule et remplace toute convention antérieure, écrite +ou orale, entre les Parties sur le même objet et constitue l'accord +entier entre les Parties sur cet objet. Aucune addition ou modification +aux termes du Contrat n'aura d'effet à l'égard des Parties à moins +d'être faite par écrit et signée par leurs représentants dûment habilités. + +11.4 Dans l'hypothèse où une ou plusieurs des dispositions du Contrat +s'avèrerait contraire à une loi ou à un texte applicable, existants ou +futurs, cette loi ou ce texte prévaudrait, et les Parties feraient les +amendements nécessaires pour se conformer à cette loi ou à ce texte. +Toutes les autres dispositions resteront en vigueur. De même, la +nullité, pour quelque raison que ce soit, d'une des dispositions du +Contrat ne saurait entraîner la nullité de l'ensemble du Contrat. + + + 11.5 LANGUE + +Le Contrat est rédigé en langue française et en langue anglaise, ces +deux versions faisant également foi. + + + Article 12 - NOUVELLES VERSIONS DU CONTRAT + +12.1 Toute personne est autorisée à copier et distribuer des copies de +ce Contrat. + +12.2 Afin d'en préserver la cohérence, le texte du Contrat est protégé +et ne peut être modifié que par les auteurs de la licence, lesquels se +réservent le droit de publier périodiquement des mises à jour ou de +nouvelles versions du Contrat, qui posséderont chacune un numéro +distinct. Ces versions ultérieures seront susceptibles de prendre en +compte de nouvelles problématiques rencontrées par les logiciels libres. + +12.3 Tout Logiciel diffusé sous une version donnée du Contrat ne pourra +faire l'objet d'une diffusion ultérieure que sous la même version du +Contrat ou une version postérieure, sous réserve des dispositions de +l'article 5.3.4 <#compatibilite>. + + + Article 13 - LOI APPLICABLE ET COMPETENCE TERRITORIALE + +13.1 Le Contrat est régi par la loi française. Les Parties conviennent +de tenter de régler à l'amiable les différends ou litiges qui +viendraient à se produire par suite ou à l'occasion du Contrat. + +13.2 A défaut d'accord amiable dans un délai de deux (2) mois à compter +de leur survenance et sauf situation relevant d'une procédure d'urgence, +les différends ou litiges seront portés par la Partie la plus diligente +devant les Tribunaux compétents de Paris. + + diff --git a/LICENSE.en b/LICENSE.en new file mode 100644 index 00000000..e7c9f899 --- /dev/null +++ b/LICENSE.en @@ -0,0 +1,519 @@ + + CeCILL FREE SOFTWARE LICENSE AGREEMENT + +Version 2.1 dated 2013-06-21 + + + Notice + +This Agreement is a Free Software license agreement that is the result +of discussions between its authors in order to ensure compliance with +the two main principles guiding its drafting: + + * firstly, compliance with the principles governing the distribution + of Free Software: access to source code, broad rights granted to users, + * secondly, the election of a governing law, French law, with which it + is conformant, both as regards the law of torts and intellectual + property law, and the protection that it offers to both authors and + holders of the economic rights over software. + +The authors of the CeCILL (for Ce[a] C[nrs] I[nria] L[ogiciel] L[ibre]) +license are: + +Commissariat à l'énergie atomique et aux énergies alternatives - CEA, a +public scientific, technical and industrial research establishment, +having its principal place of business at 25 rue Leblanc, immeuble Le +Ponant D, 75015 Paris, France. + +Centre National de la Recherche Scientifique - CNRS, a public scientific +and technological establishment, having its principal place of business +at 3 rue Michel-Ange, 75794 Paris cedex 16, France. + +Institut National de Recherche en Informatique et en Automatique - +Inria, a public scientific and technological establishment, having its +principal place of business at Domaine de Voluceau, Rocquencourt, BP +105, 78153 Le Chesnay cedex, France. + + + Preamble + +The purpose of this Free Software license agreement is to grant users +the right to modify and redistribute the software governed by this +license within the framework of an open source distribution model. + +The exercising of this right is conditional upon certain obligations for +users so as to preserve this status for all subsequent redistributions. + +In consideration of access to the source code and the rights to copy, +modify and redistribute granted by the license, users are provided only +with a limited warranty and the software's author, the holder of the +economic rights, and the successive licensors only have limited liability. + +In this respect, the risks associated with loading, using, modifying +and/or developing or reproducing the software by the user are brought to +the user's attention, given its Free Software status, which may make it +complicated to use, with the result that its use is reserved for +developers and experienced professionals having in-depth computer +knowledge. Users are therefore encouraged to load and test the +suitability of the software as regards their requirements in conditions +enabling the security of their systems and/or data to be ensured and, +more generally, to use and operate it in the same conditions of +security. This Agreement may be freely reproduced and published, +provided it is not altered, and that no provisions are either added or +removed herefrom. + +This Agreement may apply to any or all software for which the holder of +the economic rights decides to submit the use thereof to its provisions. + +Frequently asked questions can be found on the official website of the +CeCILL licenses family (http://www.cecill.info/index.en.html) for any +necessary clarification. + + + Article 1 - DEFINITIONS + +For the purpose of this Agreement, when the following expressions +commence with a capital letter, they shall have the following meaning: + +Agreement: means this license agreement, and its possible subsequent +versions and annexes. + +Software: means the software in its Object Code and/or Source Code form +and, where applicable, its documentation, "as is" when the Licensee +accepts the Agreement. + +Initial Software: means the Software in its Source Code and possibly its +Object Code form and, where applicable, its documentation, "as is" when +it is first distributed under the terms and conditions of the Agreement. + +Modified Software: means the Software modified by at least one +Contribution. + +Source Code: means all the Software's instructions and program lines to +which access is required so as to modify the Software. + +Object Code: means the binary files originating from the compilation of +the Source Code. + +Holder: means the holder(s) of the economic rights over the Initial +Software. + +Licensee: means the Software user(s) having accepted the Agreement. + +Contributor: means a Licensee having made at least one Contribution. + +Licensor: means the Holder, or any other individual or legal entity, who +distributes the Software under the Agreement. + +Contribution: means any or all modifications, corrections, translations, +adaptations and/or new functions integrated into the Software by any or +all Contributors, as well as any or all Internal Modules. + +Module: means a set of sources files including their documentation that +enables supplementary functions or services in addition to those offered +by the Software. + +External Module: means any or all Modules, not derived from the +Software, so that this Module and the Software run in separate address +spaces, with one calling the other when they are run. + +Internal Module: means any or all Module, connected to the Software so +that they both execute in the same address space. + +GNU GPL: means the GNU General Public License version 2 or any +subsequent version, as published by the Free Software Foundation Inc. + +GNU Affero GPL: means the GNU Affero General Public License version 3 or +any subsequent version, as published by the Free Software Foundation Inc. + +EUPL: means the European Union Public License version 1.1 or any +subsequent version, as published by the European Commission. + +Parties: mean both the Licensee and the Licensor. + +These expressions may be used both in singular and plural form. + + + Article 2 - PURPOSE + +The purpose of the Agreement is the grant by the Licensor to the +Licensee of a non-exclusive, transferable and worldwide license for the +Software as set forth in Article 5 <#scope> hereinafter for the whole +term of the protection granted by the rights over said Software. + + + Article 3 - ACCEPTANCE + +3.1 The Licensee shall be deemed as having accepted the terms and +conditions of this Agreement upon the occurrence of the first of the +following events: + + * (i) loading the Software by any or all means, notably, by + downloading from a remote server, or by loading from a physical medium; + * (ii) the first time the Licensee exercises any of the rights granted + hereunder. + +3.2 One copy of the Agreement, containing a notice relating to the +characteristics of the Software, to the limited warranty, and to the +fact that its use is restricted to experienced users has been provided +to the Licensee prior to its acceptance as set forth in Article 3.1 +<#accepting> hereinabove, and the Licensee hereby acknowledges that it +has read and understood it. + + + Article 4 - EFFECTIVE DATE AND TERM + + + 4.1 EFFECTIVE DATE + +The Agreement shall become effective on the date when it is accepted by +the Licensee as set forth in Article 3.1 <#accepting>. + + + 4.2 TERM + +The Agreement shall remain in force for the entire legal term of +protection of the economic rights over the Software. + + + Article 5 - SCOPE OF RIGHTS GRANTED + +The Licensor hereby grants to the Licensee, who accepts, the following +rights over the Software for any or all use, and for the term of the +Agreement, on the basis of the terms and conditions set forth hereinafter. + +Besides, if the Licensor owns or comes to own one or more patents +protecting all or part of the functions of the Software or of its +components, the Licensor undertakes not to enforce the rights granted by +these patents against successive Licensees using, exploiting or +modifying the Software. If these patents are transferred, the Licensor +undertakes to have the transferees subscribe to the obligations set +forth in this paragraph. + + + 5.1 RIGHT OF USE + +The Licensee is authorized to use the Software, without any limitation +as to its fields of application, with it being hereinafter specified +that this comprises: + + 1. permanent or temporary reproduction of all or part of the Software + by any or all means and in any or all form. + + 2. loading, displaying, running, or storing the Software on any or all + medium. + + 3. entitlement to observe, study or test its operation so as to + determine the ideas and principles behind any or all constituent + elements of said Software. This shall apply when the Licensee + carries out any or all loading, displaying, running, transmission or + storage operation as regards the Software, that it is entitled to + carry out hereunder. + + + 5.2 ENTITLEMENT TO MAKE CONTRIBUTIONS + +The right to make Contributions includes the right to translate, adapt, +arrange, or make any or all modifications to the Software, and the right +to reproduce the resulting software. + +The Licensee is authorized to make any or all Contributions to the +Software provided that it includes an explicit notice that it is the +author of said Contribution and indicates the date of the creation thereof. + + + 5.3 RIGHT OF DISTRIBUTION + +In particular, the right of distribution includes the right to publish, +transmit and communicate the Software to the general public on any or +all medium, and by any or all means, and the right to market, either in +consideration of a fee, or free of charge, one or more copies of the +Software by any means. + +The Licensee is further authorized to distribute copies of the modified +or unmodified Software to third parties according to the terms and +conditions set forth hereinafter. + + + 5.3.1 DISTRIBUTION OF SOFTWARE WITHOUT MODIFICATION + +The Licensee is authorized to distribute true copies of the Software in +Source Code or Object Code form, provided that said distribution +complies with all the provisions of the Agreement and is accompanied by: + + 1. a copy of the Agreement, + + 2. a notice relating to the limitation of both the Licensor's warranty + and liability as set forth in Articles 8 and 9, + +and that, in the event that only the Object Code of the Software is +redistributed, the Licensee allows effective access to the full Source +Code of the Software for a period of at least three years from the +distribution of the Software, it being understood that the additional +acquisition cost of the Source Code shall not exceed the cost of the +data transfer. + + + 5.3.2 DISTRIBUTION OF MODIFIED SOFTWARE + +When the Licensee makes a Contribution to the Software, the terms and +conditions for the distribution of the resulting Modified Software +become subject to all the provisions of this Agreement. + +The Licensee is authorized to distribute the Modified Software, in +source code or object code form, provided that said distribution +complies with all the provisions of the Agreement and is accompanied by: + + 1. a copy of the Agreement, + + 2. a notice relating to the limitation of both the Licensor's warranty + and liability as set forth in Articles 8 and 9, + +and, in the event that only the object code of the Modified Software is +redistributed, + + 3. a note stating the conditions of effective access to the full source + code of the Modified Software for a period of at least three years + from the distribution of the Modified Software, it being understood + that the additional acquisition cost of the source code shall not + exceed the cost of the data transfer. + + + 5.3.3 DISTRIBUTION OF EXTERNAL MODULES + +When the Licensee has developed an External Module, the terms and +conditions of this Agreement do not apply to said External Module, that +may be distributed under a separate license agreement. + + + 5.3.4 COMPATIBILITY WITH OTHER LICENSES + +The Licensee can include a code that is subject to the provisions of one +of the versions of the GNU GPL, GNU Affero GPL and/or EUPL in the +Modified or unmodified Software, and distribute that entire code under +the terms of the same version of the GNU GPL, GNU Affero GPL and/or EUPL. + +The Licensee can include the Modified or unmodified Software in a code +that is subject to the provisions of one of the versions of the GNU GPL, +GNU Affero GPL and/or EUPL and distribute that entire code under the +terms of the same version of the GNU GPL, GNU Affero GPL and/or EUPL. + + + Article 6 - INTELLECTUAL PROPERTY + + + 6.1 OVER THE INITIAL SOFTWARE + +The Holder owns the economic rights over the Initial Software. Any or +all use of the Initial Software is subject to compliance with the terms +and conditions under which the Holder has elected to distribute its work +and no one shall be entitled to modify the terms and conditions for the +distribution of said Initial Software. + +The Holder undertakes that the Initial Software will remain ruled at +least by this Agreement, for the duration set forth in Article 4.2 <#term>. + + + 6.2 OVER THE CONTRIBUTIONS + +The Licensee who develops a Contribution is the owner of the +intellectual property rights over this Contribution as defined by +applicable law. + + + 6.3 OVER THE EXTERNAL MODULES + +The Licensee who develops an External Module is the owner of the +intellectual property rights over this External Module as defined by +applicable law and is free to choose the type of agreement that shall +govern its distribution. + + + 6.4 JOINT PROVISIONS + +The Licensee expressly undertakes: + + 1. not to remove, or modify, in any manner, the intellectual property + notices attached to the Software; + + 2. to reproduce said notices, in an identical manner, in the copies of + the Software modified or not. + +The Licensee undertakes not to directly or indirectly infringe the +intellectual property rights on the Software of the Holder and/or +Contributors, and to take, where applicable, vis-à-vis its staff, any +and all measures required to ensure respect of said intellectual +property rights of the Holder and/or Contributors. + + + Article 7 - RELATED SERVICES + +7.1 Under no circumstances shall the Agreement oblige the Licensor to +provide technical assistance or maintenance services for the Software. + +However, the Licensor is entitled to offer this type of services. The +terms and conditions of such technical assistance, and/or such +maintenance, shall be set forth in a separate instrument. Only the +Licensor offering said maintenance and/or technical assistance services +shall incur liability therefor. + +7.2 Similarly, any Licensor is entitled to offer to its licensees, under +its sole responsibility, a warranty, that shall only be binding upon +itself, for the redistribution of the Software and/or the Modified +Software, under terms and conditions that it is free to decide. Said +warranty, and the financial terms and conditions of its application, +shall be subject of a separate instrument executed between the Licensor +and the Licensee. + + + Article 8 - LIABILITY + +8.1 Subject to the provisions of Article 8.2, the Licensee shall be +entitled to claim compensation for any direct loss it may have suffered +from the Software as a result of a fault on the part of the relevant +Licensor, subject to providing evidence thereof. + +8.2 The Licensor's liability is limited to the commitments made under +this Agreement and shall not be incurred as a result of in particular: +(i) loss due the Licensee's total or partial failure to fulfill its +obligations, (ii) direct or consequential loss that is suffered by the +Licensee due to the use or performance of the Software, and (iii) more +generally, any consequential loss. In particular the Parties expressly +agree that any or all pecuniary or business loss (i.e. loss of data, +loss of profits, operating loss, loss of customers or orders, +opportunity cost, any disturbance to business activities) or any or all +legal proceedings instituted against the Licensee by a third party, +shall constitute consequential loss and shall not provide entitlement to +any or all compensation from the Licensor. + + + Article 9 - WARRANTY + +9.1 The Licensee acknowledges that the scientific and technical +state-of-the-art when the Software was distributed did not enable all +possible uses to be tested and verified, nor for the presence of +possible defects to be detected. In this respect, the Licensee's +attention has been drawn to the risks associated with loading, using, +modifying and/or developing and reproducing the Software which are +reserved for experienced users. + +The Licensee shall be responsible for verifying, by any or all means, +the suitability of the product for its requirements, its good working +order, and for ensuring that it shall not cause damage to either persons +or properties. + +9.2 The Licensor hereby represents, in good faith, that it is entitled +to grant all the rights over the Software (including in particular the +rights set forth in Article 5 <#scope>). + +9.3 The Licensee acknowledges that the Software is supplied "as is" by +the Licensor without any other express or tacit warranty, other than +that provided for in Article 9.2 <#good-faith> and, in particular, +without any warranty as to its commercial value, its secured, safe, +innovative or relevant nature. + +Specifically, the Licensor does not warrant that the Software is free +from any error, that it will operate without interruption, that it will +be compatible with the Licensee's own equipment and software +configuration, nor that it will meet the Licensee's requirements. + +9.4 The Licensor does not either expressly or tacitly warrant that the +Software does not infringe any third party intellectual property right +relating to a patent, software or any other property right. Therefore, +the Licensor disclaims any and all liability towards the Licensee +arising out of any or all proceedings for infringement that may be +instituted in respect of the use, modification and redistribution of the +Software. Nevertheless, should such proceedings be instituted against +the Licensee, the Licensor shall provide it with technical and legal +expertise for its defense. Such technical and legal expertise shall be +decided on a case-by-case basis between the relevant Licensor and the +Licensee pursuant to a memorandum of understanding. The Licensor +disclaims any and all liability as regards the Licensee's use of the +name of the Software. No warranty is given as regards the existence of +prior rights over the name of the Software or as regards the existence +of a trademark. + + + Article 10 - TERMINATION + +10.1 In the event of a breach by the Licensee of its obligations +hereunder, the Licensor may automatically terminate this Agreement +thirty (30) days after notice has been sent to the Licensee and has +remained ineffective. + +10.2 A Licensee whose Agreement is terminated shall no longer be +authorized to use, modify or distribute the Software. However, any +licenses that it may have granted prior to termination of the Agreement +shall remain valid subject to their having been granted in compliance +with the terms and conditions hereof. + + + Article 11 - MISCELLANEOUS + + + 11.1 EXCUSABLE EVENTS + +Neither Party shall be liable for any or all delay, or failure to +perform the Agreement, that may be attributable to an event of force +majeure, an act of God or an outside cause, such as defective +functioning or interruptions of the electricity or telecommunications +networks, network paralysis following a virus attack, intervention by +government authorities, natural disasters, water damage, earthquakes, +fire, explosions, strikes and labor unrest, war, etc. + +11.2 Any failure by either Party, on one or more occasions, to invoke +one or more of the provisions hereof, shall under no circumstances be +interpreted as being a waiver by the interested Party of its right to +invoke said provision(s) subsequently. + +11.3 The Agreement cancels and replaces any or all previous agreements, +whether written or oral, between the Parties and having the same +purpose, and constitutes the entirety of the agreement between said +Parties concerning said purpose. No supplement or modification to the +terms and conditions hereof shall be effective as between the Parties +unless it is made in writing and signed by their duly authorized +representatives. + +11.4 In the event that one or more of the provisions hereof were to +conflict with a current or future applicable act or legislative text, +said act or legislative text shall prevail, and the Parties shall make +the necessary amendments so as to comply with said act or legislative +text. All other provisions shall remain effective. Similarly, invalidity +of a provision of the Agreement, for any reason whatsoever, shall not +cause the Agreement as a whole to be invalid. + + + 11.5 LANGUAGE + +The Agreement is drafted in both French and English and both versions +are deemed authentic. + + + Article 12 - NEW VERSIONS OF THE AGREEMENT + +12.1 Any person is authorized to duplicate and distribute copies of this +Agreement. + +12.2 So as to ensure coherence, the wording of this Agreement is +protected and may only be modified by the authors of the License, who +reserve the right to periodically publish updates or new versions of the +Agreement, each with a separate number. These subsequent versions may +address new issues encountered by Free Software. + +12.3 Any Software distributed under a given version of the Agreement may +only be subsequently distributed under the same version of the Agreement +or a subsequent version, subject to the provisions of Article 5.3.4 +<#compatibility>. + + + Article 13 - GOVERNING LAW AND JURISDICTION + +13.1 The Agreement is governed by French law. The Parties agree to +endeavor to seek an amicable solution to any disagreements or disputes +that may arise during the performance of the Agreement. + +13.2 Failing an amicable solution within two (2) months as from their +occurrence, and unless emergency proceedings are necessary, the +disagreements or disputes shall be referred to the Paris Courts having +jurisdiction, by the more diligent Party. + diff --git a/Makefile b/Makefile index 3930a600..3fb488ba 100644 --- a/Makefile +++ b/Makefile @@ -29,16 +29,66 @@ $(MKDOCS): $(VENV)/bin/activate mkdocs-bibtex $(PIP) install --quiet --upgrade InSilicoSeq +# ── standard targets (names and behaviour follow crate-kit's crate.mk) ─────────── +# obiskim is an application workspace: cargo runs on $(CARGO_DIR)/Cargo.toml, default features. + +CARGO ?= cargo +CARGO_MANIFEST := $(CARGO_DIR)/Cargo.toml +GREEN ?= \033[0;32m +YELLOW ?= \033[1;33m +BLUE ?= \033[1;34m +NC ?= \033[0m + +.DEFAULT_GOAL := build + +.PHONY: help build release test check fmt fmt-check clippy ci +## help: Lists the documented targets (this Makefile and the kit's) +help: + @echo "$(GREEN)Available commands:$(NC)" + @sed -n "s/^## *\([^:]*\): */\1$$(printf '\t')/p" $(MAKEFILE_LIST) | column -t -s "$$(printf '\t')" | sed -e 's/^/ /' + +## build: Release build of the obikmer binary (alias of release) +build: release + +## release: Release build of the obikmer binary +release: obikmer + +## test: Workspace tests +test: + $(CARGO) test --workspace --manifest-path $(CARGO_MANIFEST) + +## check: Code check (all targets of the workspace) +check: + $(CARGO) check --workspace --all-targets --manifest-path $(CARGO_MANIFEST) + +## fmt: Code formatting +fmt: + $(CARGO) fmt --all --manifest-path $(CARGO_MANIFEST) + +## fmt-check: Formatting check +fmt-check: + $(CARGO) fmt --all --manifest-path $(CARGO_MANIFEST) -- --check + +## clippy: Static analysis (warnings = errors) +clippy: + $(CARGO) clippy --workspace --all-targets --manifest-path $(CARGO_MANIFEST) -- -D warnings + +## ci: Verification pipeline (deps-check fmt-check clippy test) +ci: deps-check fmt-check clippy test + @echo "$(GREEN)✓ All CI checks passed$(NC)" + # ── obikmer binary ─────────────────────────────────────────────────────────── PROFILE_FILE := profile.pb PPROF_PORT := 8081 .PHONY: obikmer +## obikmer: Release build of the obikmer binary obikmer: cargo build --release --manifest-path $(CARGO_DIR)/Cargo.toml --bin obikmer .PHONY: debug +## debug: Debug build of the obikmer binary debug: cargo build --manifest-path $(CARGO_DIR)/Cargo.toml --bin obikmer @@ -53,6 +103,7 @@ profile-view: # ── documentation ───────────────────────────────────────────────────────────── .PHONY: doc +## doc: Builds the developer documentation (DevDoc/) doc: $(MKDOCS) $(MKDOCS) build -f $(DOC_FILE) @@ -66,6 +117,7 @@ clean-doc: rm -rf $(DOC_SITE)/ .PHONY: doc-user +## doc-user: Builds the user documentation (doc/) doc-user: $(MKDOCS) $(MKDOCS) build -f $(DOC_USER_FILE) @@ -82,9 +134,10 @@ clean-doc-user: # Regenerates the Gitea/Forgejo wiki (a separate repository, checked out next # to this one) from the user documentation. Only rewrites its working tree: # committing and pushing it stays a manual step. Not part of `clean`. -DOC_WIKI_DIR := ../obikmer.wiki +DOC_WIKI_DIR := ../obiskim.wiki .PHONY: wiki +## wiki: Regenerates the wiki working tree (../obiskim.wiki); commit and push stay manual wiki: @command -v pmotransdoc >/dev/null || { echo "pmotransdoc not found in PATH" >&2; exit 1; } @test -d $(DOC_WIKI_DIR)/.git || { echo "$(DOC_WIKI_DIR) is not a git checkout of the wiki" >&2; exit 1; } @@ -94,12 +147,27 @@ wiki: clean: clean-doc clean-doc-user rm -rf $(VENV) -# ── release ─────────────────────────────────────────────────────────────────── +# ── release (jj only; the kit's norms for a repository that is not a crate) ─────── +# Version: patch bump of the obikmer crate (RELEASE=x.y.z forces it). Tag: v (what release.yml +# triggers on), created and pushed with jj, lightweight: the CI release body is the tagged commit's +# message. Release notes: ReleaseNotes/version-.md (jj release-notes), committed with the release. +# No git command is run. The user runs `make jjrelease`; it never runs by itself. CARGO_TOML := $(CARGO_DIR)/obikmer/Cargo.toml +RELEASE_NOTES_DIR := ReleaseNotes +API_DIR := api +RELEASE_PROJECT_DESC := obiskim (Rust k-mer genomics tool) +TAG_PREFIX := v +# Backlog of outdated external dependencies: not enforced until TASK-24 of the obi backlog is done. +# The private-registry check (neighbours, lock, duplicates) stays active. +export DEPS_CHECK_EXTERNAL ?= 0 +export RELEASE_NOTES_DIR API_DIR RELEASE_PROJECT_DESC TAG_PREFIX -.PHONY: bump-version +.PHONY: bump-version jjpush jjrelease bookmark-check print-% + +## bump-version: Next patch version of the obikmer crate, or fixed RELEASE=x.y.z (refused if the tag exists) bump-version: + @jj git fetch @current=$$(grep '^version = ' $(CARGO_TOML) | head -n 1 | sed 's/version = "\(.*\)"/\1/'); \ if [ -n "$(RELEASE)" ]; then \ new_version="$(RELEASE)"; \ @@ -107,22 +175,59 @@ bump-version: major=$$(echo $$current | cut -d. -f1); \ minor=$$(echo $$current | cut -d. -f2); \ patch=$$(echo $$current | cut -d. -f3); \ - new_patch=$$((patch + 1)); \ - new_version="$$major.$$minor.$$new_patch"; \ + new_version="$$major.$$minor.$$((patch + 1))"; \ + fi; \ + if [ -n "$$(jj tag list "$(TAG_PREFIX)$$new_version" 2>/dev/null)" ]; then \ + echo "✗ tag $(TAG_PREFIX)$$new_version already exists (use RELEASE=x.y.z)" >&2; exit 1; \ fi; \ echo "Version: $$current -> $$new_version"; \ sed -i.bak "s/^version = \"$$current\"/version = \"$$new_version\"/" $(CARGO_TOML) && \ rm $(CARGO_TOML).bak -.PHONY: release -release: bump-version +## bookmark-check: Does main track main@origin? Otherwise the push of main would fail (read-only) +bookmark-check: + @.crate-kit/scripts/bookmark-check.sh + +## jjpush: Documents the commit, advances main to it and pushes main (no PR branch), then starts a new commit +jjpush: bookmark-check deps-check + @echo "$(YELLOW)→ Pushing the commit to main...$(NC)" @jj auto-doc - @jj git push --change @ - @new_version=$$(grep '^version = ' $(CARGO_TOML) | head -n 1 | sed 's/version = "\(.*\)"/\1/'); \ - git_hash=$$(jj log -r @ --no-graph -T 'commit_id'); \ - commits=$$(jj log -r 'latest(tags())..@' --no-graph -T 'description ++ "\n"' 2>/dev/null || \ - jj log --no-graph -T 'description ++ "\n"' --limit 30); \ - notes=$$(printf 'Write concise markdown release notes for obikmer (a Rust kmer genomics tool). Be technical and direct. Base them strictly on these commit messages:\n\n%s' "$$commits" | aichat 2>/dev/null); \ - tag_msg="$${notes:-Release v$$new_version}"; \ - git tag -a "v$$new_version" -m "$$tag_msg" "$$git_hash" && \ - git push origin "v$$new_version" + @.crate-kit/scripts/push-main.sh + @.crate-kit/scripts/new-commit.sh + @echo "$(GREEN)✓ main pushed; new working commit created on top of it$(NC)" + +## jjrelease: Release (ci, version bump, notes, push of main, tag v pushed; release.yml then builds) +jjrelease: bookmark-check ci bump-version + @echo "$(BLUE)→ Documenting the undocumented commits...$(NC)" + @jj auto-doc + @.crate-kit/scripts/release-notes.sh + @echo "$(BLUE)→ Documenting the current commit...$(NC)" + @jj auto-doc + @echo "$(BLUE)→ Pushing main...$(NC)" + @.crate-kit/scripts/push-main.sh + @scripts/jj-tag.sh + @.crate-kit/scripts/new-commit.sh + @echo "$(GREEN)✓ Tag pushed: the CI (release.yml) builds and publishes the release$(NC)" + +## print-%: Value of a make variable (e.g. make print-REGISTRY) +print-%: + @echo '$($*)' + +# ── crate-kit (registry `obi`, joint development) ───────────────────────────── +# obiskim is an APPLICATION workspace, not a crate. It includes dev-patch.mk (private registry +# definition, local patches to neighbouring crates, deps-check/deps-bump) and jj.mk (jjnew, jjfetch). +# The crate targets of crate.mk (publish, api-*, kit-check: it requires a release.yaml workflow) do NOT +# apply; the release targets above are the application's own, built on the kit's scripts. +# .crate-kit/ is resynchronized from obi-kit (which assembles crate-kit) at every make, before the include. +# Skipped when obi-kit is absent (CI, repository cloned alone): the committed copy is used. +# Included last so that the default goal stays `build`. +KIT_SRC ?= ../obi-kit +$(shell [ -x '$(KIT_SRC)/tools/kit-copy.sh' ] && '$(KIT_SRC)/tools/kit-copy.sh' .crate-kit) + +include .crate-kit/dev-patch.mk +include .crate-kit/jj.mk + +# Exported after the includes: KIT_LANG comes from org.mk (`?=`), and an earlier `export KIT_LANG` would +# define it empty with GNU make 3.81 (macOS). +export KIT_LANG CARGO_TOML +export PMOJJ_LANG = $(KIT_LANG) diff --git a/scripts/jj-tag.sh b/scripts/jj-tag.sh new file mode 100755 index 00000000..331bede1 --- /dev/null +++ b/scripts/jj-tag.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env bash +# Tags the published commit with using jj only, then pushes the tag. +# The tag is lightweight (jj creates no annotated tag): the CI release body is the commit message. +set -euo pipefail +. "$(dirname "$0")/../.crate-kit/scripts/common.sh" +version=$(current_version) +tag="${TAG_PREFIX:-v}$version" +if [ -n "$(jj tag list "$tag" 2>/dev/null)" ]; then + err "✗ tag $tag already exists" + exit 1 +fi +rev=$(release_rev) +jj tag set "$tag" -r "$rev" +jj git push --tag "$tag" +ok "✓ Release $tag published" diff --git a/src/Cargo.lock b/src/Cargo.lock index 595d5e77..41cc3188 100644 --- a/src/Cargo.lock +++ b/src/Cargo.lock @@ -1531,7 +1531,7 @@ dependencies = [ [[package]] name = "obikmer" -version = "1.4.7" +version = "1.4.8" dependencies = [ "clap", "csv", diff --git a/src/obicompactvec/Cargo.toml b/src/obicompactvec/Cargo.toml index 43d8e42b..3e355231 100644 --- a/src/obicompactvec/Cargo.toml +++ b/src/obicompactvec/Cargo.toml @@ -2,6 +2,8 @@ name = "obicompactvec" version = "0.1.0" edition = "2024" +license = "CECILL-2.1" +repository = "https://forge.metabarcoding.org/obi/obiskim" [dependencies] common_traits = "0.13" diff --git a/src/obidebruinj/Cargo.toml b/src/obidebruinj/Cargo.toml index de1fc00c..d9624ca1 100644 --- a/src/obidebruinj/Cargo.toml +++ b/src/obidebruinj/Cargo.toml @@ -2,6 +2,8 @@ name = "obidebruinj" version = "0.1.0" edition = "2021" +license = "CECILL-2.1" +repository = "https://forge.metabarcoding.org/obi/obiskim" [dependencies] obikseq = { path = "../obikseq" } diff --git a/src/obifastwrite/Cargo.toml b/src/obifastwrite/Cargo.toml index 2615305a..fe2c26cf 100644 --- a/src/obifastwrite/Cargo.toml +++ b/src/obifastwrite/Cargo.toml @@ -2,6 +2,8 @@ name = "obifastwrite" version = "0.1.0" edition = "2024" +license = "CECILL-2.1" +repository = "https://forge.metabarcoding.org/obi/obiskim" [dependencies] obikseq = { path = "../obikseq" } diff --git a/src/obikalgorithm/Cargo.toml b/src/obikalgorithm/Cargo.toml index 6b0e7f5b..f34ef612 100644 --- a/src/obikalgorithm/Cargo.toml +++ b/src/obikalgorithm/Cargo.toml @@ -2,3 +2,5 @@ name = "obikalgorithm" version = "0.1.0" edition = "2024" +license = "CECILL-2.1" +repository = "https://forge.metabarcoding.org/obi/obiskim" diff --git a/src/obikdump/Cargo.toml b/src/obikdump/Cargo.toml index 06426592..2c8a49e2 100644 --- a/src/obikdump/Cargo.toml +++ b/src/obikdump/Cargo.toml @@ -2,6 +2,8 @@ name = "obikdump" version = "0.1.0" edition = "2024" +license = "CECILL-2.1" +repository = "https://forge.metabarcoding.org/obi/obiskim" [dependencies] obikindex = { path = "../obikindex" } diff --git a/src/obikentropy/Cargo.toml b/src/obikentropy/Cargo.toml index 3d1cd69b..52fa9fb9 100644 --- a/src/obikentropy/Cargo.toml +++ b/src/obikentropy/Cargo.toml @@ -2,6 +2,8 @@ name = "obikentropy" version = "0.1.0" edition = "2024" +license = "CECILL-2.1" +repository = "https://forge.metabarcoding.org/obi/obiskim" [dependencies] obikseq = { path = "../obikseq" } diff --git a/src/obikfilter/Cargo.toml b/src/obikfilter/Cargo.toml index 9b199742..91196ba1 100644 --- a/src/obikfilter/Cargo.toml +++ b/src/obikfilter/Cargo.toml @@ -2,6 +2,8 @@ name = "obikfilter" version = "0.1.0" edition = "2024" +license = "CECILL-2.1" +repository = "https://forge.metabarcoding.org/obi/obiskim" [dependencies] obikindex = { path = "../obikindex" } diff --git a/src/obikidxcache/Cargo.toml b/src/obikidxcache/Cargo.toml index 661ffc3a..25b1225e 100644 --- a/src/obikidxcache/Cargo.toml +++ b/src/obikidxcache/Cargo.toml @@ -2,6 +2,8 @@ name = "obikidxcache" version = "0.1.0" edition = "2024" +license = "CECILL-2.1" +repository = "https://forge.metabarcoding.org/obi/obiskim" [dependencies] obikindex = { path = "../obikindex"} diff --git a/src/obikindex/Cargo.toml b/src/obikindex/Cargo.toml index 0b52d8e8..fa2fc0c1 100644 --- a/src/obikindex/Cargo.toml +++ b/src/obikindex/Cargo.toml @@ -2,6 +2,8 @@ name = "obikindex" version = "0.1.0" edition = "2024" +license = "CECILL-2.1" +repository = "https://forge.metabarcoding.org/obi/obiskim" [dependencies] obikseq = { path = "../obikseq" } diff --git a/src/obikindexer/Cargo.toml b/src/obikindexer/Cargo.toml index 03d00f19..75f0615e 100644 --- a/src/obikindexer/Cargo.toml +++ b/src/obikindexer/Cargo.toml @@ -2,6 +2,8 @@ name = "obikindexer" version = "0.1.0" edition = "2024" +license = "CECILL-2.1" +repository = "https://forge.metabarcoding.org/obi/obiskim" [dependencies] obikindex = { path = "../obikindex" } diff --git a/src/obikmer/Cargo.toml b/src/obikmer/Cargo.toml index 7e8f76ac..7a9ea8a0 100644 --- a/src/obikmer/Cargo.toml +++ b/src/obikmer/Cargo.toml @@ -2,6 +2,8 @@ name = "obikmer" version = "1.4.8" edition = "2024" +license = "CECILL-2.1" +repository = "https://forge.metabarcoding.org/obi/obiskim" [[bin]] name = "obikmer" diff --git a/src/obikmerge/Cargo.toml b/src/obikmerge/Cargo.toml index eccee4ef..91c9e81f 100644 --- a/src/obikmerge/Cargo.toml +++ b/src/obikmerge/Cargo.toml @@ -2,6 +2,8 @@ name = "obikmerge" version = "0.1.0" edition = "2024" +license = "CECILL-2.1" +repository = "https://forge.metabarcoding.org/obi/obiskim" [dependencies] obikindex = { path = "../obikindex" } diff --git a/src/obikphylo/Cargo.toml b/src/obikphylo/Cargo.toml index 6cf38773..bfeda2fc 100644 --- a/src/obikphylo/Cargo.toml +++ b/src/obikphylo/Cargo.toml @@ -2,6 +2,8 @@ name = "obikphylo" version = "0.1.0" edition = "2024" +license = "CECILL-2.1" +repository = "https://forge.metabarcoding.org/obi/obiskim" [dependencies] obikindex = { path = "../obikindex", default-features = false } diff --git a/src/obikquery/Cargo.toml b/src/obikquery/Cargo.toml index 685c50ca..7224156f 100644 --- a/src/obikquery/Cargo.toml +++ b/src/obikquery/Cargo.toml @@ -2,6 +2,8 @@ name = "obikquery" version = "0.1.0" edition = "2024" +license = "CECILL-2.1" +repository = "https://forge.metabarcoding.org/obi/obiskim" [dependencies] obikindex = { path = "../obikindex" } diff --git a/src/obikrebuild/Cargo.toml b/src/obikrebuild/Cargo.toml index 539b8cea..e92f553c 100644 --- a/src/obikrebuild/Cargo.toml +++ b/src/obikrebuild/Cargo.toml @@ -2,6 +2,8 @@ name = "obikrebuild" version = "0.1.0" edition = "2024" +license = "CECILL-2.1" +repository = "https://forge.metabarcoding.org/obi/obiskim" [dependencies] obikindex = { path = "../obikindex" } diff --git a/src/obikrope/Cargo.toml b/src/obikrope/Cargo.toml index ded3335e..922d9a65 100644 --- a/src/obikrope/Cargo.toml +++ b/src/obikrope/Cargo.toml @@ -2,6 +2,8 @@ name = "obikrope" version = "0.1.0" edition = "2024" +license = "CECILL-2.1" +repository = "https://forge.metabarcoding.org/obi/obiskim" [dev-dependencies] criterion2 = { version = "3", features = ["cargo_bench_support"] } diff --git a/src/obikselect/Cargo.toml b/src/obikselect/Cargo.toml index c31722ed..084fafb3 100644 --- a/src/obikselect/Cargo.toml +++ b/src/obikselect/Cargo.toml @@ -2,6 +2,8 @@ name = "obikselect" version = "0.1.0" edition = "2024" +license = "CECILL-2.1" +repository = "https://forge.metabarcoding.org/obi/obiskim" [dependencies] obikindex = { path = "../obikindex" } diff --git a/src/obikseq/Cargo.toml b/src/obikseq/Cargo.toml index 97be974f..c4ed3cb2 100644 --- a/src/obikseq/Cargo.toml +++ b/src/obikseq/Cargo.toml @@ -2,6 +2,8 @@ name = "obikseq" version = "0.1.0" edition = "2024" +license = "CECILL-2.1" +repository = "https://forge.metabarcoding.org/obi/obiskim" [features] # Replaces the OnceLock-based params with thread-local storage so that diff --git a/src/obiksession/Cargo.toml b/src/obiksession/Cargo.toml index 1845cf5b..4fab5896 100644 --- a/src/obiksession/Cargo.toml +++ b/src/obiksession/Cargo.toml @@ -2,6 +2,8 @@ name = "obiksession" version = "0.1.0" edition = "2024" +license = "CECILL-2.1" +repository = "https://forge.metabarcoding.org/obi/obiskim" [dependencies] obisys = { path = "../obisys", default-features = false } diff --git a/src/obikstats/Cargo.toml b/src/obikstats/Cargo.toml index 825b9a12..1de91563 100644 --- a/src/obikstats/Cargo.toml +++ b/src/obikstats/Cargo.toml @@ -2,6 +2,8 @@ name = "obikstats" version = "0.1.0" edition = "2024" +license = "CECILL-2.1" +repository = "https://forge.metabarcoding.org/obi/obiskim" [dependencies] obikindex = { path = "../obikindex" } diff --git a/src/obipipeline/Cargo.toml b/src/obipipeline/Cargo.toml index 40aa6bfb..7cceb381 100644 --- a/src/obipipeline/Cargo.toml +++ b/src/obipipeline/Cargo.toml @@ -2,6 +2,8 @@ name = "obipipeline" version = "0.1.0" edition = "2024" +license = "CECILL-2.1" +repository = "https://forge.metabarcoding.org/obi/obiskim" [dependencies] crossbeam-channel = "0.5.15" diff --git a/src/obiread/Cargo.toml b/src/obiread/Cargo.toml index ba6177b3..3ab18b06 100644 --- a/src/obiread/Cargo.toml +++ b/src/obiread/Cargo.toml @@ -2,6 +2,8 @@ name = "obiread" version = "0.1.0" edition = "2024" +license = "CECILL-2.1" +repository = "https://forge.metabarcoding.org/obi/obiskim" [dependencies] obikrope = { path = "../obikrope" } diff --git a/src/obiskbuilder/Cargo.toml b/src/obiskbuilder/Cargo.toml index 02c206ae..eafe62d7 100644 --- a/src/obiskbuilder/Cargo.toml +++ b/src/obiskbuilder/Cargo.toml @@ -2,6 +2,8 @@ name = "obiskbuilder" version = "0.1.0" edition = "2024" +license = "CECILL-2.1" +repository = "https://forge.metabarcoding.org/obi/obiskim" [dependencies] obikseq = { path = "../obikseq" } diff --git a/src/obiskio/Cargo.toml b/src/obiskio/Cargo.toml index b0d093dc..4f1e282c 100644 --- a/src/obiskio/Cargo.toml +++ b/src/obiskio/Cargo.toml @@ -2,6 +2,8 @@ name = "obiskio" version = "0.1.0" edition = "2024" +license = "CECILL-2.1" +repository = "https://forge.metabarcoding.org/obi/obiskim" [dependencies] niffler = "3.0.0" diff --git a/src/obisys/Cargo.toml b/src/obisys/Cargo.toml index 8952e948..8206fb6b 100644 --- a/src/obisys/Cargo.toml +++ b/src/obisys/Cargo.toml @@ -2,6 +2,8 @@ name = "obisys" version = "0.1.0" edition = "2024" +license = "CECILL-2.1" +repository = "https://forge.metabarcoding.org/obi/obiskim" [dependencies] libc = "0.2" diff --git a/src/obitaxonomy/Cargo.toml b/src/obitaxonomy/Cargo.toml index b391f4d2..8280f026 100644 --- a/src/obitaxonomy/Cargo.toml +++ b/src/obitaxonomy/Cargo.toml @@ -2,5 +2,7 @@ name = "obitaxonomy" version = "0.1.0" edition = "2024" +license = "CECILL-2.1" +repository = "https://forge.metabarcoding.org/obi/obiskim" [dependencies]