|
| 1 | +# AppEnv.jl |
| 2 | + |
| 3 | +A Julia package for instantiating the environment in bundled/distributed Julia applications. AppEnv.jl configures Julia's load paths, depot paths, and package origins to ensure your application runs correctly when packaged as MSIX (Windows), DMG (macOS), or Snap (Linux). |
| 4 | + |
| 5 | +## Purpose |
| 6 | + |
| 7 | +When distributing Julia applications as standalone bundles, the standard Julia environment needs reconfiguration. AppEnv.jl handles this automatically, managing platform-specific sandboxing requirements and ensuring proper module loading. |
| 8 | + |
| 9 | +## Usage |
| 10 | + |
| 11 | +Call `AppEnv.init()` at the start of your application: |
| 12 | +```julia |
| 13 | +using AppEnv |
| 14 | + |
| 15 | +AppEnv.init() |
| 16 | +``` |
| 17 | + |
| 18 | +When no arguments are passed, AppEnv uses its default parameters that are baked in during compilation from environment variables or reads them from the environment at runtime. The following environment variables are available: |
| 19 | + |
| 20 | +- **`RUNTIME_MODE`** - Sets the runtime mode: `INTERACTIVE` (default), `MIN`, `COMPILATION`, or `SANDBOX` |
| 21 | +- **`MODULE_NAME`** - Name of your main application module (default: `MainEnv`) |
| 22 | +- **`APP_NAME`** - Application name, required for `SANDBOX` mode |
| 23 | +- **`BUNDLE_IDENTIFIER`** - Bundle identifier (e.g., `com.example.myapp`), required for `SANDBOX` mode |
| 24 | +- **`USER_DATA`** - Custom path for user data directory (overrides platform defaults) |
| 25 | +- **`STDLIB`** - Relative path to the standard library location (default: relative path from Julia binary to stdlib) |
| 26 | + |
| 27 | +These variables can be set either at compilation time (baked into either sysimage or pkgimage) or at runtime before calling `init()`. |
| 28 | + |
| 29 | +## User Data Directory |
| 30 | + |
| 31 | +After initialization, access the user data directory via: |
| 32 | +```julia |
| 33 | +AppEnv.USER_DATA |
| 34 | +``` |
| 35 | + |
| 36 | +This provides a persistent location for storing application data, respecting platform conventions and sandboxing requirements. The location can be customized by setting the `USER_DATA` environment variable before calling `init()`. |
| 37 | + |
| 38 | +## Example |
| 39 | +```julia |
| 40 | +module MyApp |
| 41 | + |
| 42 | +using AppEnv |
| 43 | + |
| 44 | +function (@main)(ARGS) |
| 45 | + AppEnv.init() |
| 46 | + |
| 47 | + # Use the user data directory |
| 48 | + config_file = joinpath(AppEnv.USER_DATA, "config.toml") |
| 49 | + println("Config location: ", config_file) |
| 50 | +end |
| 51 | + |
| 52 | +export main |
| 53 | + |
| 54 | +end # module |
| 55 | +``` |
0 commit comments