Metadata-Version: 2.5
Name: gcc-env
Version: 0.3.3
Summary: Cross-platform GCC/C++ toolchain manager built on conda-forge and uv
Project-URL: Homepage, https://github.com/yulianjie/gcc-env
Project-URL: Repository, https://github.com/yulianjie/gcc-env
Project-URL: Issues, https://github.com/yulianjie/gcc-env/issues
Project-URL: Changelog, https://github.com/yulianjie/gcc-env/releases
Author: Yu Lianjie
License: MIT
License-File: LICENSE
Keywords: c++,conda-forge,g++,gcc,libstdc++,toolchain,uv
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: MacOS
Classifier: Operating System :: Microsoft :: Windows
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: C
Classifier: Programming Language :: C++
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Software Development :: Build Tools
Classifier: Topic :: System :: Software Distribution
Requires-Python: >=3.11
Description-Content-Type: text/markdown

# gcc-env (`ge`)

[![CI](https://github.com/yulianjie/gcc-env/actions/workflows/ci.yml/badge.svg)](https://github.com/yulianjie/gcc-env/actions/workflows/ci.yml)
[![Release](https://github.com/yulianjie/gcc-env/actions/workflows/release.yml/badge.svg)](https://github.com/yulianjie/gcc-env/actions/workflows/release.yml)
[![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)

**A cross-platform GCC/C++ toolchain manager built on conda-forge and uv.**

`ge` installs complete GCC toolchains into isolated prefixes under `~/.ge`,
gives each one a uv-managed Python build environment (CMake, Ninja, ...), and
makes switching compilers a one-liner. It also takes care of the infamous
`libstdc++.so.6` / `GLIBCXX_3.4.xx not found` deployment problem.

```console
$ ge setup
$ ge create gcc13 --gcc 13.3.0 --use
$ ge c++ -- -std=c++20 main.cpp -o app
$ ge doctor
```

Works natively on **Linux**, **macOS**, and **Windows** (MinGW-w64), and inside
**WSL** like any other Linux distribution.

---

## Why another toolchain manager?

Installing several GCC versions on one machine usually means fighting with the
system compiler, ABI-incompatible `libstdc++`, and build scripts that cache
`CC`. `ge` keeps everything self-contained:

- **Real GCC, not a shim.** Compilers come from conda-forge's `gcc_*`/`gxx_*`
  packages. Linux uses the `sysroot_linux-64` package (default glibc **2.17**),
  so new compilers can still produce binaries for old distributions.
- **One prefix per version.** `~/.ge/envs/<name>` contains the conda toolchain
  and a separate uv virtual environment. Nothing is installed system-wide.
- **uv for build tooling.** Each environment gets its own Python venv with
  `cmake` and `ninja` (configurable), installed by uv and isolated per GCC.
- **Portable output.** `ge c++` links the C++ runtime statically by default and
  `ge bundle` can produce a relocatable directory with `libstdc++` next to your
  application instead of depending on the target machine.
- **Bare compiler names.** After activation, `c`, `cc`, `gcc`, `c++`, and `g++`
  are available directly (no `ge` prefix) through per-environment shims.
- **Explainable diagnosis.** `ge doctor` compiles a probe, reads `GLIBC_*`,
  `GLIBCXX_*`, and `CXXABI_*` symbol requirements, compares them with the target
  glibc and the system libstdc++, and tells you exactly what will break.

## Requirements

- **No Python of your own** is needed with the standalone installer: it brings
  a pinned CPython 3.12 from python-build-standalone and only needs `sh` plus
  `curl` or `wget` on Linux/macOS, or PowerShell 5.1+ with `tar.exe`
  (Windows 10 1803+) on Windows. Installing through pip, uv, or pipx instead
  needs Python **3.11+** to run `ge` itself.
- Network access for the first bootstrap: **conda-forge** (the GCC toolchain),
  **micro.mamba.pm** (the micromamba release), **GitHub** (uv releases, the
  standalone installer's CPython and wheel, and — when uv has to download one —
  CPython builds), and **pypi.org** (the `pip` seed and build tools such as
  cmake/ninja)
- ~1 GB disk space per toolchain (shared package caches reduce this)

`ge` uses the first **micromamba** and **uv** it finds: the `GE_MICROMAMBA`/
`GE_UV` variables, then a private copy in `~/.ge/bin`, then `PATH`. Only when
none of these provides the tool does it download the pinned release into
`~/.ge/bin`. You do not need conda, Mamba, or a system GCC installed.

## Installation

`ge` is a Python package, so it installs like any other — but Python is only
needed to *run* it, never to install it. Pick whichever fits the machine:

### Standalone installer (no Python required)

Like uv's own installer, this one is self-contained: it downloads a **pinned**
CPython from [python-build-standalone](https://github.com/astral-sh/python-build-standalone)
(the same builds uv uses) and the gcc-env wheel from the latest GitHub
Release, verifies both against SHA-256 digests before anything is extracted,
and installs everything under `~/.ge/standalone` with a launcher in
`~/.local/bin`:

```console
# Linux / macOS / WSL
curl -fsSL https://raw.githubusercontent.com/yulianjie/gcc-env/main/install.sh | sh

# Windows, PowerShell 5.1 or later
powershell -ExecutionPolicy Bypass -c "irm https://raw.githubusercontent.com/yulianjie/gcc-env/main/install.ps1 | iex"
```

Then open a new shell and run:

```console
ge --version
ge setup
```

Both scripts are also attached to every release and covered by its
`SHA256SUMS`, so a mirror can serve them from
`https://github.com/yulianjie/gcc-env/releases/download/v<version>/` instead
of `main`.

Running the installer again upgrades in place (a runtime of the same pin is
reused, older ones are removed). Uninstall with
`rm -rf ~/.ge/standalone ~/.local/bin/ge`, or on Windows
`Remove-Item -Recurse -Force "$env:USERPROFILE\.ge\standalone", "$env:USERPROFILE\.local\bin\ge.exe"`.
The installer takes no arguments (it is piped into `sh`/`iex`), so it is
configured through environment variables:

- `GE_VERSION` — the release to install: `latest` (default), `0.3.3`, or `v0.3.3`.
- `GE_INSTALL_DIR` — where the launcher goes (`~/.local/bin`, or `$XDG_BIN_HOME`).
- `GE_STANDALONE_DIR` — where the runtime lives (`$GE_ROOT/standalone`).
- `GE_WHEEL` — install this local wheel instead of downloading one.
- `GE_WHEEL_URL` + `GE_WHEEL_SHA256` — fetch the wheel from a mirror. An
  override without its checksum is refused before any network access, exactly
  like the bootstrap downloads below.
- `GE_PYTHON_ARCHIVE` — use a local python-build-standalone `install_only` archive.
- `GE_PYTHON_URL` + `GE_PYTHON_SHA256` — fetch CPython from a mirror.
- `GE_ALLOW_INSECURE_BOOTSTRAP_URL` — `1` allows non-`https://` override URLs
  (isolated networks only).
- `GE_FORCE` — `1` replaces a `ge` launcher that this installer did not create
  (for example one from `uv tool install`).

Local files are trusted as they are; the matching `*_SHA256` variable checks
them when set. Archives are cached in `~/.ge/cache/downloads`, which
`ge clean --downloads` empties. The launcher runs the runtime in Python's
isolated mode (`-I` on Unix, a `python._pth` file on Windows), so a stray
`PYTHONHOME`/`PYTHONPATH` — from `uv run`, an activated conda environment, an
embedded-Python application — cannot break `ge`.

### With uv, pipx, or pip (Python 3.11+)

Install as a standalone uv tool (recommended when uv is already on the machine):

```console
uv tool install gcc-env
```

Until the package is on PyPI, install directly from GitHub:

```console
uv tool install "git+https://github.com/yulianjie/gcc-env"
```

Or from a release wheel:

```console
uv tool install ./gcc_env-<version>-py3-none-any.whl
```

Verify:

```console
ge --version
ge bootstrap
```

### Bootstrap downloads are pinned and verified

When `ge` does have to download an engine, it fetches a **pinned** release —
uv 0.13.10 and micromamba 2.10.0 by default — and verifies the archive against
a SHA-256 digest before anything is extracted into `~/.ge/bin`; a truncated or
tampered download is deleted. To use a mirror or another release, set
`GE_UV_URL` and/or `GE_UV_VERSION` (likewise `GE_MICROMAMBA_*`) **together
with** the matching `GE_UV_SHA256`/`GE_MICROMAMBA_SHA256`: an override without
a checksum is refused before any network access. Non-`https://` URLs are
refused as well unless `GE_ALLOW_INSECURE_BOOTSTRAP_URL=1` (isolated networks
only). `ge config` shows the effective pins, checksums, and overrides.

## Quick start

```console
# Locate uv/micromamba, create "default" (GCC 14 on Linux/Windows,
# GCC 15 on macOS) with Python 3.12 + cmake + ninja, and select it.
ge setup

# One-time shell integration: makes `ge activate` modify the current shell
# directly instead of merely printing shell code.
ge shell-init --install
# Restart the shell (or source your profile), then:
ge create gcc13 --gcc 13.3.0
ge activate gcc13

# Compiler names are now available without the `ge` prefix.
c++ --version
c++ -std=c++20 main.cpp -o app

ge status
ge deactivate
```

`ge activate` also enables **global activation** by default: new shells that
load the profile hook start with `gcc13` active and show `(gcc13)` in the
prompt. Use `--session` for a venv-style, current-shell-only activation. The
prompt prefix is removed and the previous environment restored by
`ge deactivate`; use `deactivate --session` to keep global activation enabled.
`ge status` shows the shell, global, and default states.

`ge activate` must be able to modify the **current** shell. A normal executable
cannot do that, so `ge shell-init --install` adds a small wrapper function to
your profile (`bash`/`zsh`/`fish`/PowerShell). Without the hook, use the
explicit fallback:

```console
eval "$(ge activate gcc13)"
```

The hook is idempotent and can be removed with `ge shell-init --uninstall`.
`ge deactivate` restores the environment from before the first activation in
that shell (it also removes the per-environment compiler shims from `PATH`).

PowerShell users can install/print the hook directly:

```powershell
ge shell-init --install
Invoke-Expression ((ge shell-init --shell powershell) -join [Environment]::NewLine)
```

On Windows, `ge shell-init --install` writes both the PowerShell 7 profile
(`Documents\PowerShell\...`) and the Windows PowerShell 5.1 profile
(`Documents\WindowsPowerShell\...`). If `ge activate` still says “This shell
has no gcc-env hook”, the current terminal predates the installation, or
was started with `-NoProfile`. Close/reopen it, or initialize the current
session with:

```powershell
Invoke-Expression ((ge shell-init --shell powershell) -join [Environment]::NewLine)
ge activate gcc13
```

More commands:

```console
ge list
ge use gcc13
ge shell
ge run gcc13 -- cmake --version
ge create gcc15 --gcc 15.2.0
# Linux only: choose a newer glibc/sysroot target.
ge create gcc15-glibc228 --gcc 15.2.0 --sysroot 2.28
```

`ge` also ships `ge cc`, `ge gcc` and `ge g++` aliases. Advanced compiler flags
for `ge` itself must come before the first compiler argument:

```console
ge c++ --env gcc13 --runtime shared -- -O2 main.cpp -o app
ge c++ --print-command -- -std=c++20 main.cpp -o app
```

## Commands

| Command | Description |
| --- | --- |
| `ge setup` | Bootstrap micromamba/uv, create and select the default environment (`--name`, `--gcc`, `--sysroot`, `--python`, `--no-python`, `--tools`, `--runtime`, `--recreate`). |
| `ge bootstrap` | Locate, download and verify micromamba and uv only (`--json`). |
| `ge create [NAME]` | Create an environment (`--gcc`, `--sysroot`, `--python`, `--no-python`, `--tools`, `--runtime`, `--use`, `--force`). |
| `ge list` / `ge ls` | List environments and show the current one (`--json`). |
| `ge info [NAME]` | Show compiler paths, versions, sysroot, Python, and conda packages (`--json`). |
| `ge use NAME` / `ge switch` | Select the default environment for new commands. |
| `ge current` | Print the current environment name (`--json`). |
| `ge status` | Show shell activation, global activation, current default, and prompt state (`--json`). |
| `ge remove NAME` / `ge rm` | Delete an environment. Asks for confirmation; `--yes`/`-y` for scripts. Non-interactive without `--yes` is an error (exit 2), never a silent cancel. |
| `ge clean` | Reclaim disk space from caches and orphaned Python interpreters; installed environments are never touched (`--downloads`, `--uv`, `--pkgs`, `--python`, `--all`, `--dry-run`). |
| `ge shell [NAME]` | Spawn a clean interactive shell with the toolchain activated (`--shell`, `--rc`, `--quiet`). |
| `ge run [NAME] -- CMD` | Run one command with `CC`, `CXX`, `PATH`, and runtime paths set. |
| `ge activate [NAME]` | Activate in the current shell and enable global auto-activation (`--session` for this shell only; `--shell`, `--print-code`). |
| `ge deactivate` | Restore the shell and disable global auto-activation (`--session` keeps it enabled; `--shell`, `--print-code`). |
| `ge shell-init` | Print the shell hook; `--install`/`--uninstall` manage the profile block (`--shell`, `--profile`). |
| `ge cc` / `ge c++` | Invoke the environment C/C++ compiler with the runtime policy applied (`ge gcc`/`ge g++` are aliases). |
| `ge doctor [NAME]` | Check compiler, glibc target, libstdc++, RPATH, and uv tools (`--binary`, `--target-glibc`, `--runtime`, `--json`). |
| `ge bundle BINARY` | Copy a binary plus the required GCC runtime into a relocatable folder (`--dest`, `--env`, `--force`). |
| `ge toolchain [NAME]` | Write a CMake toolchain file (`--output`, `--print` for stdout, `--runtime`). |
| `ge config` | Show effective defaults, timeouts, bootstrap pins/overrides, channels, and paths (`--json`). |
| `ge version` | Print the gcc-env version (`--json`). |

Use `ge COMMAND --help` for details. A few options deserve a note:

- `ge shell` starts bash/zsh/fish without their startup files by default;
  `--rc` loads them, `--shell` picks the executable (`bash`, `zsh`, `fish`,
  `sh`, `pwsh`, `powershell`, `cmd`, or a path), and `--quiet` skips the banner.
- `ge activate`/`ge deactivate` refuse to print code to an interactive terminal
  without the hook; `--print-code` prints it anyway (`--shell` selects the
  dialect). `ge shell-init --profile PATH` overrides the profile file that
  `--install`/`--uninstall` edit.
- `ge doctor --runtime` and `ge toolchain --runtime` override the environment's
  policy for the probe/toolchain file; `ge toolchain --output PATH` selects
  the destination instead of `~/.ge/envs/NAME/ge-toolchain.cmake`.
- `ge bundle --force` replaces only `bin/` and `lib/` inside an existing
  destination and leaves every other file there untouched. The destination is
  refused when it is — or contains — your home directory, the current
  directory, a filesystem root, the gcc-env root, an environment directory, or
  the directory holding the binary.
- `ge clean` removes what `ge` keeps on purpose; at least one selector is
  required: `--downloads` deletes `~/.ge/cache/downloads/*`, `--uv` runs
  `uv cache clean`, `--pkgs` runs `micromamba clean --all --yes` (which is why
  `ge remove` suggests it), `--python` deletes interpreters under
  `~/.ge/python/` that no `envs/*/venv/pyvenv.cfg` references any more,
  `--all` does all of them, and `--dry-run` only lists what would go.

## How it works

```text
~/.ge/
├── bin/                 # private micromamba and uv (downloaded only if not found)
├── cache/
│   ├── downloads/       # bootstrap archives for uv and micromamba
│   └── uv/              # uv cache
├── python/              # uv-managed Python interpreters
├── standalone/          # private CPython + gcc-env written by install.sh / install.ps1
├── mamba/               # micromamba root prefix and package cache
├── envs/
│   └── gcc13/
│       ├── conda/       # conda-forge GCC, binutils, sysroot, patchelf
│       ├── venv/        # uv venv with cmake/ninja (per toolchain)
│       ├── bin/         # c/cc/gcc/c++/g++ shims for bare compiler names
│       ├── ge-toolchain.cmake  # written by `ge toolchain`
│       └── env.json     # exact resolved versions, paths, and the explicit conda lock
├── state/               # per-shell activation snapshots for ge deactivate
├── active               # name of the globally auto-activated environment
├── current              # name of the selected environment
├── .lock                # mutex held by commands that mutate ~/.ge
└── config.toml          # optional defaults
```

`ge create` does three things:

1. Locates micromamba (`GE_MICROMAMBA`, `~/.ge/bin`, `PATH`, or one pinned
   download) and runs a conda solve against **conda-forge** with an explicit
   toolchain package, for example on Linux:

    ```text
    gcc_linux-64=13.3.0  gxx_linux-64=13.3.0
    sysroot_linux-64=2.17  patchelf
    ```

   The solved prefix is recorded in `env.json` (`conda.packages` and the
   reproducible `micromamba list --explicit` lock in `conda.explicit`).

2. Discovers the actual compiler executables from the prefix (including the
   target-prefixed names used by conda-forge).

3. Runs `uv venv --seed --python 3.12` in `venv/` and
   `uv pip install cmake ninja` for build tooling. Use `--no-python` if you only
   need the compiler.

Activation reconstructs a minimal, clean environment: it prepends the
environment's shim directory, venv, and toolchain `bin` directories, exports
`CC`/`CXX`/`AR`/`LD`/..., sets `CMAKE_PREFIX_PATH` and
`CONDA_BUILD_SYSROOT`, and prepends the toolchain `lib` directory to the runtime
loader path. It deliberately does **not** import conda-build's default
`-march=nocona`/`-O2` flags, so your project's flags remain yours.

The shim directory contains `c`, `cc`, `gcc`, `c++`, and `g++` wrappers that
delegate to `ge cc` / `ge c++`, so the bare compiler names respect the same
runtime policy. `ge shell-init --install` is what lets `ge activate`/`ge deactivate`
change the parent shell; without it, use `eval "$(ge activate ...)"`.

Note that `cc -v` (and `c++ -v`) is GCC's verbose diagnostic flag and prints a
large configuration dump by design. Use `cc --version` for a one-line version.

### Global activation and prompts

`ge activate NAME` writes `~/.ge/active` and updates the current shell. The
installed shell hook auto-activates that environment in new shells, and
`(NAME)` is prepended to the prompt. `ge deactivate` clears both the current
shell state and `~/.ge/active`. For a purely local activation:

```console
ge activate gcc13 --session
ge deactivate --session
```

Set `GE_NO_AUTO_ACTIVATE=1` in a shell to skip global auto-activation for that
shell.

The `(NAME)` prefix is a plain `PS1` prepend, so prompt frameworks that rebuild
their prompt themselves (starship, powerlevel10k, ...) do not see it. For those,
`ge activate` exports `GE_PROMPT_MODIFIER` — `"(gcc13) "` with a trailing space,
unset again by `ge deactivate`:

```toml
# starship.toml
[env_var.GE_PROMPT_MODIFIER]
format = "[$env_value]($style)"
style = "bold green"
```

```console
# bash: a custom PS1 that reads it at prompt time
PS1='${GE_PROMPT_MODIFIER}\u@\h:\w\$ '
```

Without the shell hook (the `eval` fallback) nothing re-injects the session
id, so `ge activate` exports `GE_SESSION` (a uuid) instead; its snapshot under
`~/.ge/state/` is reclaimed by the 7-day expiry.

### Why micromamba *and* uv?

They solve different problems. conda-forge supplies the native GCC toolchain,
binutils, sysroot, and runtime libraries; uv supplies isolated Python tooling
and Python interpreters. Using uv alone cannot install native conda packages,
and using conda alone would duplicate a Python environment per compiler without
uv's speed and lockfile ecosystem. `ge` composes them.

## The `libstdc++.so.6` problem

A binary linked with GCC 13/14/15 may require `GLIBCXX_3.4.32` (or newer), while
the target machine's `/usr/lib/.../libstdc++.so.6` only provides an older
version. The usual results are:

```text
./app: /lib/x86_64-linux-gnu/libstdc++.so.6: version `GLIBCXX_3.4.32' not found
./app: /lib/x86_64-linux-gnu/libstdc++.so.6: version `CXXABI_1.3.15' not found
```

Setting `LD_LIBRARY_PATH` globally or shipping a newer libstdc++ "somewhere"
often breaks other applications. `ge` gives you three explicit policies:

| Policy | What happens | Best for |
| --- | --- | --- |
| `static` (default) | Adds `-static-libstdc++ -static-libgcc` when linking (`-static` too on Windows; only `-static-libgcc` on macOS, where conda-forge's GCC uses the system libc++). Shared-library targets (`-shared`) get no static runtime, because GCC links those with `-shared-libgcc` by default so exceptions unwind across library boundaries; an explicit `--runtime static` combined with `-shared` prints a warning. | Shipping standalone tools; maximum compatibility. |
| `shared` | Normal dynamic linking. conda's GCC adds an RPATH to the environment's `lib`, so it runs locally. | Debugging, plugins, shared-library-heavy projects. |
| `bundle` | Dynamic linking plus a relative RPATH (`$ORIGIN/../lib` on Linux, `@loader_path/../lib` on macOS). Then `ge bundle` copies the exact runtime libraries. | Applications that must ship their C++ runtime but stay dynamically linked. |

Choose per command or when creating the environment:

```console
ge create gcc14 --gcc 14
ge create gcc14-shared --gcc 14 --runtime shared

ge c++ --env gcc14 --runtime static -- main.cpp -o app
ge c++ --env gcc14 --runtime shared -- main.cpp -o app-shared
ge c++ --env gcc14 --runtime bundle -- main.cpp -o app-bundle
```

`ge doctor` is the source of truth:

```console
$ ge doctor gcc13
   ✓  environment gcc13 (Linux x86_64)
   ✓  compiler: ~/.ge/envs/gcc13/conda/bin/x86_64-conda-linux-gnu-cc
   ✓  compiled a C++20 filesystem/format probe
   ✓  maximum GLIBC symbol: GLIBC_2.17
   ✓  GLIBC requirements fit the target (2.17)
   ✓  no libstdc++.so.6 dependency (static runtime); portable across ...
   ✓  Python venv: .../venv/bin/python (3.12.3)
   ✓  uv-installed tool: cmake
   ✓  uv-installed tool: ninja
ok doctor passed
```

Inspect an existing binary instead of compiling a probe:

```console
ge doctor gcc13 --binary ./app
ge doctor gcc13 --binary ./app --target-glibc 2.17 --json
```

`ge doctor` exits non-zero only on errors, making it usable in CI. It reports:

- the maximum `GLIBC_*` requirement versus the sysroot target;
- the maximum `GLIBCXX_*` / `CXXABI_*` requirement versus the system
  libstdc++ (on Linux);
- development RPATHs;
- MinGW runtime DLL dependencies on Windows;
- missing Python/uv tooling.

The `GLIBC_*`/`GLIBCXX_*`/`CXXABI_*` requirements are read from the binary's
version-needs section with `readelf`. When `readelf` is unavailable (or the
section is missing), they are extracted heuristically from the raw bytes and
may be *higher* than the real requirement, so `ge doctor` reports those lines
as `warn` rather than `ok`, and `--json` carries `version_source`
(`readelf`, `raw-scan`, or `none`).

### Creating a portable bundle

```console
ge c++ --env gcc13 --runtime bundle -- app.cpp -o app
ge bundle ./app --env gcc13 --dest ./dist

find ./dist
# dist/bin/app
# dist/lib/libstdc++.so.6
# dist/lib/libgcc_s.so.1
```

`ge bundle` copies the binary into `bin/` and then the **transitive closure**
of its dependencies — `DT_NEEDED` on ELF, `LC_LOAD_DYLIB` on Mach-O, the import
table on PE — into `lib/` (next to the `.exe` on Windows), re-inspecting every
copied library so nothing is missed. System libraries (glibc, `libc++`, the
Windows system/UCRT DLLs) are the boundary. Each copied library gets its
RPATH/install name rewritten to point at its siblings: `$ORIGIN` on Linux,
`@rpath/<name>` plus `@loader_path` on macOS. A non-system dependency that is
not in the environment is reported with a `warn` and must be provided by the
target system.

On Linux, `ge bundle` uses `patchelf` (installed in the environment) to replace
the absolute development RPATH with `$ORIGIN/../lib`. On macOS it uses
`install_name_tool` and ad-hoc codesigning when available. On Windows it copies
the required MinGW DLLs next to the `.exe`. `--force` replaces only `bin/` and
`lib/` inside an existing destination (see [Commands](#commands)).

## CMake

`ge toolchain` writes a CMake toolchain file with the compiler paths, static
runtime flags, prefix paths, and a relative install RPATH for bundle builds:

```console
ge toolchain gcc13
# ~/.ge/envs/gcc13/ge-toolchain.cmake

ge run gcc13 -- cmake -S . -B build \
  -DCMAKE_TOOLCHAIN_FILE=$HOME/.ge/envs/gcc13/ge-toolchain.cmake
ge run gcc13 -- cmake --build build
```

The environment's venv provides `cmake` and `ninja`, so no system CMake is
required. The static flags go into `CMAKE_EXE_LINKER_FLAGS_INIT` and
`CMAKE_MODULE_LINKER_FLAGS_INIT`; `CMAKE_SHARED_LINKER_FLAGS_INIT` stays empty
for the same reason `-shared` targets get no static runtime (see above).

## Configuration

Optional `~/.ge/config.toml` (all timeouts are in seconds):

```toml
[defaults]
gcc = "14"
sysroot = "2.17"     # Linux only; "none" to use the default sysroot
python = "3.12"
runtime = "static"   # static | shared | bundle
tools = ["cmake", "ninja"]
channels = ["conda-forge"]
mamba_root = "~/.ge/mamba"  # default: <GE_ROOT>/mamba
download_timeout = 60   # bootstrap downloads (GE_DOWNLOAD_TIMEOUT)
solve_timeout = 3600    # conda solve; `ge create` holds the lock meanwhile (GE_SOLVE_TIMEOUT)
venv_timeout = 900      # each uv venv / uv pip install step (GE_VENV_TIMEOUT)
```

Common environment variables (they override `config.toml`):

| Variable | Meaning |
| --- | --- |
| `GE_ROOT` | Data directory (default `~/.ge`). |
| `GE_GCC`, `GE_SYSROOT`, `GE_PYTHON`, `GE_RUNTIME` | Override defaults. |
| `GE_CONDA_CHANNELS` | Comma-separated channel URLs; useful for mirrors. |
| `GE_MAMBA_ROOT` | micromamba root/cache directory. |
| `GE_DOWNLOAD_TIMEOUT` | Timeout in seconds for bootstrap downloads (default 60). |
| `GE_SOLVE_TIMEOUT` | Timeout in seconds for the conda solve (default 3600). |
| `GE_VENV_TIMEOUT` | Timeout in seconds for each uv venv / `uv pip install` step (default 900). |
| `GE_UV`, `GE_MICROMAMBA` | Use specific external binaries; skips the `~/.ge/bin`/`PATH` lookup. |
| `GE_UV_URL`, `GE_MICROMAMBA_URL` | Override bootstrap download URLs; require the matching `*_SHA256`. |
| `GE_UV_VERSION`, `GE_MICROMAMBA_VERSION` | Override the pinned bootstrap version; requires the matching `*_SHA256`. |
| `GE_UV_SHA256`, `GE_MICROMAMBA_SHA256` | Expected SHA-256 of the bootstrap archive (64 hex digits; a `sha256:` prefix is accepted). |
| `GE_ALLOW_INSECURE_BOOTSTRAP_URL` | `1` allows non-`https://` bootstrap URLs (isolated networks only). |
| `GE_NO_AUTO_ACTIVATE` | Set to `1` in a shell to skip global auto-activation there. |
| `GE_PROMPT_MODIFIER` | Exported by `ge activate` as `"(name) "` for prompt frameworks (see [Global activation and prompts](#global-activation-and-prompts)); unset by `ge deactivate`. |
| `NO_COLOR` / `GE_NO_COLOR` | Disable ANSI colors. |

`GE_ENV`, `GE_GCC_VERSION`, `GE_ACTIVE`, `GE_SHELL` and `GE_SESSION` are set
by `ge` and the shell hook rather than by you, and need no configuration:
`GE_ENV`/`GE_GCC_VERSION` name the active environment and compiler,
`GE_ACTIVE=1` marks an activated shell (a non-exported shell variable in POSIX
shells), `GE_SHELL` names the shell dialect — injected per call by the hook, or
set manually to override detection for `ge activate`/`ge deactivate`/`ge
shell-init` — and `GE_SESSION` identifies the shell's snapshot under
`~/.ge/state/`: the shell's pid, injected for the call only and never exported,
in hook mode; an exported uuid in the `eval` fallback.

### Using a conda mirror

`ge` passes channels explicitly and uses `--no-rc`, and it strips every
`CONDA_*`/`MAMBA_*` variable (`CONDA_SUBDIR`, `CONDA_SOLVER`, `CONDA_OVERRIDE_*`,
...) from the solver's environment, so neither a user `.condarc` nor an
activated conda shell can silently change the solve. Point it at a mirror
explicitly:

```console
GE_CONDA_CHANNELS="https://mirrors.example.edu/conda-forge,conda-forge" ge create gcc13
```

## Platform notes

### Linux

- Default sysroot: **glibc 2.17**, the conda-forge default, for broad
  compatibility. Use `--sysroot 2.28` or `2.39` when you need newer glibc APIs.
- Native `x86_64` and `aarch64` are supported.
- glibc distributions only: the pinned micromamba and the standalone
  installer's CPython are glibc builds, so Alpine and other musl systems are
  not supported (use a glibc container).
- WSL is a normal Linux platform; the same commands work unchanged.

### macOS

- conda-forge's native GCC packages start at **15.2**, so the default is GCC 15.
  Use `--gcc 15.2.0` or newer explicitly; older GCC versions are not available
  for macOS from conda-forge.
- `arm64` and `x86_64` are supported.
- The `static` runtime policy is the default. conda-forge's GCC links against
  the system **libc++** (there is no conda `libstdc++` on macOS), so `static`
  only adds `-static-libgcc` here. `ge doctor` does not flag `libc++.1.dylib`;
  it only warns when `libstdc++.6.dylib` (a non-default runtime) or `libgcc_s`
  dylibs remain.
- `ge bundle` works for dynamically linked applications; `install_name_tool`
  and `codesign` require Xcode command line tools.

### Windows

- Native **MinGW-w64 (UCRT)** GCC is installed from `gcc_win-64`/`gxx_win-64`.
  This is not MSVC: it produces native Windows executables with the MinGW ABI.
- `x86_64` only. Use WSL for Linux toolchains on Windows on ARM.
- The default static runtime produces an `.exe` whose only imports are Windows
  UCRT functions, making it easy to distribute.
- `ge shell` starts PowerShell (or `cmd` if PowerShell is unavailable) with the
  environment applied. `ge activate --shell powershell` prints code for
  `Invoke-Expression`.
- The standalone installer needs PowerShell 5.1+ and `tar.exe` (Windows 10
  1803+). Its `ge.exe` is the launcher pip generates, so no `.cmd` wrapper is
  involved; `x86_64` only, as above.

## CI/CD

The repository contains:

- `ci.yml`: unit tests on Linux/macOS/Windows and Python 3.11–3.13, lint, build,
  real toolchain integration tests on Linux and platform smoke tests on
  macOS/Windows, plus the standalone installer: on all three operating systems
  against the freshly built wheel, and inside a `debian:bookworm-slim`
  container that has no Python at all against the real latest release.
- `release.yml`: on a `v*` tag, builds an sdist and wheel, verifies the wheel,
  creates a **GitHub Release** with the artifacts, `install.sh`/`install.ps1`
  and SHA-256 checksums, smoke-tests both installers against that fresh
  release, and can optionally publish to PyPI when the `PYPI_PUBLISH`
  repository variable and `PYPI_API_TOKEN` secret are configured.

Create a release (the version lives in `src/gcc_env/__init__.py` and is read
from there by hatchling):

```console
git tag v<version>
git push origin v<version>
```

## Development

```console
git clone https://github.com/yulianjie/gcc-env
cd gcc-env
uv sync --dev
uv run pytest -m "not integration"
uv run ruff check src tests
uv run pytest -m integration   # network + several hundred MB
```

The integration tests create real environments (`ge-it-*`) under `~/.ge` and
remove them afterward; they also run `install.sh`/`install.ps1` end to end
against a scratch `GE_ROOT`. `GE_INTEGRATION_ROOT` exists only for them: it
points the integration tests at another root (falling back to `GE_ROOT`) and is
not read by `ge` itself.

Project layout:

```text
src/gcc_env/
├── __init__.py      # package metadata; the single source of the version
├── __main__.py      # `python -m gcc_env`
├── cli.py           # argparse CLI and manual parsers for cc/c++/run
├── config.py        # ~/.ge layout, config.toml, defaults and timeouts
├── platforms.py     # platform/arch detection; conda and uv target names
├── errors.py        # exception types with user-facing exit codes
├── util.py          # terminal output, safe extraction, downloads, file lock
├── bootstrap.py     # pinned micromamba/uv lookup, download, SHA-256 check
├── conda.py         # micromamba wrapper: isolated, --no-rc conda solve
├── uvtools.py       # uv venv + pip integration with isolated caches
├── compiler.py      # conda specs, compiler discovery, runtime link flags
├── envs.py          # env.json metadata; transactional create/remove/use
├── activation.py    # toolchain environment variables and shell snippets
├── shellinit.py     # shell hook rendering and profile install/uninstall
├── state.py         # per-shell activation snapshots and their pruning
├── runtime.py       # ELF/PE/Mach-O inspection, ge doctor
├── bundle.py        # relocatable bundling: dependency closure, RPATH rewrite
├── cmake.py         # CMake toolchain generation
└── clean.py         # ge clean: reclaim caches and orphaned interpreters
```

## Limitations

- Each environment owns a full toolchain prefix; this is intentional isolation,
  not a lightweight multiplexer. Package caches are shared.
- The standalone runtime under `~/.ge/standalone` is private to `ge`:
  `ge create` still downloads the venv's CPython into `~/.ge/python`, so a
  standalone install costs one extra ~30 MB interpreter.
- The Python venv is optional (`--no-python`), but `ge doctor` tool checks and
  `ge toolchain` CMake/Ninja convenience depend on it.
- A statically linked libstdc++ is excellent for executables, but shared
  libraries and plugin boundaries may require `shared`/`bundle` instead.
- glibc itself is still a system dependency on Linux. The 2.17 sysroot gives
  broad compatibility, but it cannot make a binary work on a machine older than
  that glibc.
- macOS GCC from conda-forge is newer than the usual Homebrew GCC versions;
  Apple's Clang remains the platform default for Apple-specific frameworks.

## License

MIT. See [LICENSE](LICENSE).
