Skip to content

Commit 0ffea8f

Browse files
committed
docs
1 parent e7373e6 commit 0ffea8f

File tree

1 file changed

+62
-16
lines changed

1 file changed

+62
-16
lines changed

packaging/homebrew/HOMEBREW.md

Lines changed: 62 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,11 @@ When users run `brew install mfc`, they get:
1717
- `mfc` - Wrapper script that provides the full MFC interface
1818

1919
### Additional Components
20-
- Python toolchain in `/usr/local/Cellar/mfc/VERSION/toolchain/`
21-
- Example cases in `/usr/local/Cellar/mfc/VERSION/share/mfc/examples/`
20+
- Python toolchain in `/usr/local/Cellar/mfc/VERSION/toolchain/` or `/opt/homebrew/Cellar/mfc/VERSION/toolchain/`
21+
- Python virtual environment in `/usr/local/Cellar/mfc/VERSION/libexec/venv/` or `/opt/homebrew/Cellar/mfc/VERSION/libexec/venv/`
22+
- Pre-installed with Cantera 3.1.0 and MFC toolchain packages
23+
- Example cases in `/usr/local/Cellar/mfc/VERSION/examples/` or `/opt/homebrew/Cellar/mfc/VERSION/examples/`
24+
- Main `mfc.sh` script in `libexec/`
2225
- Documentation references and usage information
2326

2427
## Formula Structure
@@ -28,25 +31,43 @@ When users run `brew install mfc`, they get:
2831
Build-time dependencies (only needed during installation):
2932
- cmake - Build system generator
3033
- gcc - GNU Compiler Collection (provides gfortran)
31-
- [email protected] - Python 3.12 for build scripts
3234

3335
Runtime dependencies (needed to run MFC):
3436
- boost - C++ libraries
3537
- fftw - Fast Fourier Transform library
3638
- hdf5 - Hierarchical Data Format 5 for data storage
3739
- open-mpi - Message Passing Interface for parallel computing
3840
- openblas - Optimized BLAS library
41+
- [email protected] - Python 3.12 (used for build scripts and runtime virtual environment)
42+
43+
Python package dependencies (installed in virtual environment):
44+
- cantera==3.1.0 - Chemical kinetics library (required for MFC build and runtime)
45+
- MFC toolchain package - Python utilities for MFC operations (installed in editable mode)
46+
47+
### Virtual Environment Setup
48+
49+
Before building, the formula creates a Python virtual environment to isolate MFC's Python dependencies:
50+
51+
1. Creates a new virtual environment in `libexec/venv` using Python 3.12
52+
2. Upgrades pip, setuptools, and wheel to latest versions
53+
3. Installs Cantera 3.1.0 from PyPI (required dependency for MFC)
54+
4. Installs the MFC toolchain package in editable mode (`-e`) to avoid RECORD file issues
55+
5. Creates a symlink from `build/venv` to the venv so `mfc.sh` can find it during build
56+
57+
This virtual environment persists after installation and is used by the wrapper script at runtime.
3958

4059
### Build Process
4160

4261
The formula executes the following steps during installation:
4362

44-
1. Runs `./mfc.sh build` to compile all three binaries
45-
2. Installs binaries to Homebrew's bin directory
46-
3. Installs mfc.sh to libexec for script execution
47-
4. Installs Python toolchain (required for mfc.sh functionality)
48-
5. Installs examples to share directory
49-
6. Creates a wrapper script that sets up the environment
63+
1. **Virtual Environment Setup** (see section above)
64+
2. Sets `VIRTUAL_ENV` environment variable so `mfc.sh` uses the pre-configured venv
65+
3. Runs `./mfc.sh build -t pre_process simulation post_process -j <cores>` to compile all three binaries
66+
4. Installs binaries from `build/install/*/bin/*` to Homebrew's bin directory
67+
5. Installs `mfc.sh` to `libexec/` for script execution
68+
6. Installs Python toolchain directory to `prefix/toolchain/` (required for mfc.sh functionality)
69+
7. Installs examples directory to `prefix/examples/`
70+
8. Creates and installs the `mfc` wrapper script that handles runtime environment setup
5071

5172
### Environment Configuration
5273

@@ -57,7 +78,18 @@ The formula relies on Homebrew's automatic environment setup:
5778

5879
### Wrapper Script
5980

60-
The installed `mfc` wrapper provides the complete MFC interface. It automatically configures the environment and delegates to the main `mfc.sh` script. Users can run any MFC command through this wrapper:
81+
The installed `mfc` wrapper provides the complete MFC interface. Due to Homebrew's read-only Cellar structure, the wrapper implements a sophisticated workaround:
82+
83+
**Key Features:**
84+
1. **Temporary Working Directory**: Creates a temporary directory since the Cellar is read-only and `mfc.sh` may need to write build artifacts
85+
2. **Environment Setup**: Copies `mfc.sh`, toolchain, examples, and the virtual environment to the temp directory
86+
3. **Toolchain Patching**: Dynamically patches the toolchain Python code to:
87+
- Use pre-installed binaries from Homebrew's bin directory instead of building new ones
88+
- Skip building main targets (`pre_process`, `simulation`, `post_process`, `syscheck`) since they're already installed
89+
4. **Build Optimization**: Automatically adds `--no-build` flag to `mfc run` commands to skip unnecessary compilation
90+
5. **Cleanup**: Automatically removes the temporary directory when the command completes
91+
92+
Users can run any MFC command through this wrapper:
6193

6294
```bash
6395
mfc build
@@ -66,6 +98,8 @@ mfc test
6698
mfc clean
6799
```
68100

101+
The wrapper ensures all MFC functionality works correctly while respecting Homebrew's installation constraints.
102+
69103
## Installation Methods
70104

71105
### Standard Installation
@@ -89,9 +123,11 @@ This clones from the master branch instead of using a release tarball.
89123
## Testing
90124

91125
The formula includes automated tests that verify:
92-
- All three binary files exist after installation
93-
- The mfc wrapper script is functional
94-
- The help command executes without errors
126+
- All three binary files exist after installation and are executable
127+
- The Python toolchain directory is installed correctly
128+
- The virtual environment exists and contains an executable Python interpreter
129+
- The examples directory is installed
130+
- The mfc wrapper script is functional and responds to `--help`
95131

96132
These tests run automatically during `brew install` and can be run manually with `brew test mfc`.
97133

@@ -108,8 +144,14 @@ After installation completes, Homebrew displays usage information including:
108144
Once installed, users can immediately start using MFC:
109145

110146
```bash
147+
# Copy an example case to your working directory
148+
cp $(brew --prefix mfc)/examples/1D_sodshocktube/case.py .
149+
111150
# Run a test case
112-
mfc run /usr/local/share/mfc/examples/1D_sodshocktube/case.py
151+
mfc run case.py
152+
153+
# Or run directly from the installed examples directory
154+
mfc run $(brew --prefix mfc)/examples/1D_sodshocktube/case.py
113155

114156
# Run just preprocessing
115157
pre_process -i input.dat
@@ -121,6 +163,8 @@ simulation -i input.dat
121163
post_process -i input.dat
122164
```
123165

166+
Note: The `brew --prefix mfc` command returns the installation prefix (e.g., `/usr/local/Cellar/mfc/VERSION` or `/opt/homebrew/Cellar/mfc/VERSION`), making examples work on both Intel and Apple Silicon systems.
167+
124168
## Distribution
125169

126170
The formula can be distributed in two ways:
@@ -183,8 +227,10 @@ The formula uses all available CPU cores for building (`ENV.make_jobs`) to minim
183227
### Installation Prefix
184228
Files install to the standard Homebrew prefix:
185229
- Binaries: `/usr/local/bin/` (Intel) or `/opt/homebrew/bin/` (Apple Silicon)
186-
- Data: `/usr/local/share/mfc/` or `/opt/homebrew/share/mfc/`
187-
- Toolchain: `/usr/local/Cellar/mfc/VERSION/` or `/opt/homebrew/Cellar/mfc/VERSION/`
230+
- Main script: `/usr/local/Cellar/mfc/VERSION/libexec/mfc.sh` or `/opt/homebrew/Cellar/mfc/VERSION/libexec/mfc.sh`
231+
- Toolchain: `/usr/local/Cellar/mfc/VERSION/toolchain/` or `/opt/homebrew/Cellar/mfc/VERSION/toolchain/`
232+
- Virtual environment: `/usr/local/Cellar/mfc/VERSION/libexec/venv/` or `/opt/homebrew/Cellar/mfc/VERSION/libexec/venv/`
233+
- Examples: `/usr/local/Cellar/mfc/VERSION/examples/` or `/opt/homebrew/Cellar/mfc/VERSION/examples/`
188234

189235
## Advantages Over Manual Installation
190236

0 commit comments

Comments
 (0)