# Building Guide

This guide explains how to build `bstart-trb` wheel packages for distribution.

## Prerequisites

### Windows

1. **Install MSYS2** (provides gfortran):
   - Download from https://www.msys2.org/
   - After installation, open MSYS2 terminal and run:
     ```bash
     pacman -S mingw-w64-ucrt-x86_64-gcc-fortran
     ```
   - Add `C:\msys64\ucrt64\bin` to your system PATH

2. **Install Python 3.10+**:
   - Download from https://www.python.org/downloads/

3. **Install uv** (recommended):
   ```powershell
   powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
   ```

### macOS

```bash
# Install gfortran
brew install gfortran

# Install uv
curl -LsSf https://astral.sh/uv/install.sh | sh
```

### Linux

```bash
# Install gfortran
sudo apt install gfortran  # Debian/Ubuntu
sudo yum install gcc-gfortran  # RHEL/CentOS

# Install uv
curl -LsSf https://astral.sh/uv/install.sh | sh
```

---

## Build Steps

### 1. Clone the repository

```bash
git clone https://github.com/youjunxiaji/bstart-trb.git
cd bstart-trb
```

### 2. Install dependencies with uv

```bash
uv sync
```

This automatically creates a virtual environment and installs all dependencies.

### 3. Build the wheel

```bash
uv run python -m build --wheel
```

The wheel file will be created in the `dist/` directory.

---

## Alternative: Direct f2py Build

If meson build fails, you can compile the Fortran module directly:

```bash
cd slice_wrapper
uv run python -m numpy.f2py -c taper_slice.f90 -m _taper_slice
```

---

## Publishing to PyPI

### 1. Install twine

```bash
uv pip install twine
```

### 2. Create PyPI API token

1. Log in to https://pypi.org
2. Go to Account settings → API tokens → Add API token
3. Save the token securely

### 3. Upload the wheel

```bash
uv run twine upload dist/*.whl
```

When prompted:
- Username: `__token__`
- Password: Your API token (starts with `pypi-`)

---

## Notes

- Each Python version (3.10, 3.11, 3.12) needs a separate wheel
- Windows wheels have `.whl` suffix like `*-win_amd64.whl`
- macOS wheels: `*-macosx_*_arm64.whl` (Apple Silicon) or `*-macosx_*_x86_64.whl` (Intel)
- Linux wheels: `*-manylinux*.whl`
