build: make GPUI an optional feature to allow TUI-only builds#136
Closed
yamaceay wants to merge 2 commits into
Closed
build: make GPUI an optional feature to allow TUI-only builds#136yamaceay wants to merge 2 commits into
yamaceay wants to merge 2 commits into
Conversation
The GPUI desktop UI depends on Metal shader compilation, which requires Xcode developer tools to be installed (xcrun must find the `metal` binary). On machines without Xcode this hard-blocked every `cargo build`, even when only the terminal TUI was needed. Introduce a `gpui-ui` Cargo feature that gates all GPUI-related code: - `Cargo.toml`: `gpui`, `gpui_platform`, and `gpui-component` are now optional dependencies, activated only by `--features gpui-ui`. The gpui entry in `[dev-dependencies]` is removed (it was unused in the unit-test suite). - `src/app/mod.rs`, `src/ui/mod.rs`: `pub mod gpui` gated behind `#[cfg(feature = "gpui-ui")]`. - `src/ui/backend.rs`: The `GpuiTerminalCommandExecutor` import and its single usage site are gated; the TUI-only path falls back to `DefaultCommandExecutor` (which `GpuiTerminalCommandExecutor` itself delegates to internally). - `src/main.rs`: The `--ui` code paths (logging setup, model resolution, `app::gpui::run()`) are gated. Passing `--ui` without the feature produces a clear error message rather than a linker crash. - `src/cli.rs`: The `UiSettings::load()` call that reads the GPUI- persisted default model is gated; TUI-only builds fall through to the alphabetical-first-model fallback. Build commands: # TUI only (no Xcode required): cargo build --no-default-features # With GPUI desktop UI (requires Xcode / Metal): cargo build --features gpui-ui
34c3a0c to
437551e
Compare
Remove terminal, terminal_test_app, and terminal_view from workspace members so cargo build --no-default-features no longer triggers Metal shader compilation. They are still pulled in transitively when building with the gpui-ui feature flag.
Author
|
Potentially in conflict with #130, need to align first |
Owner
|
Solved differently/again on main after the big crate restructuring. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The GPUI desktop UI compiles Metal shaders at build time via a Cargo
build-script. This requires Xcode developer tools (
xcrunmust locate themetalbinary). On machines without Xcode, everycargo buildfailed —including builds of the terminal TUI, which needs no Metal at all:
The root cause was twofold:
gpui_macosunconditionally:terminal,terminal_test_app, andterminal_viewwere listed as unconditional workspace members, so Cargo always compiled them regardless of feature flags — even with--no-default-features.Solution
Two complementary fixes:
gpui-uiCargo feature that makes all GPUI-related code opt-in.terminal,terminal_test_app, andterminal_viewfrom the workspacememberslist so they are only compiled when pulled in transitively via thegpui-uifeature.cargo build --no-default-featurescargo build --features gpui-uicargo build--no-default-features(default unchanged)This PR is the foundation for the autocomplete PR series (#131–#135), which
all depend on TUI-only builds working.
Changes
Cargo.toml(workspace)terminal,terminal_test_app,terminal_viewfrom workspacemembers.They are still available as path dependencies when
gpui-uiis active.crates/code_assistant/Cargo.tomlgpui,gpui_platform,gpui-component,terminal,terminal_viewall made
optional = true.gpui-ui = ["dep:gpui", "dep:gpui_platform", "dep:gpui-component", "dep:terminal", "dep:terminal_view"].gpuifrom[dev-dependencies].src/app/mod.rs,src/ui/mod.rspub mod gpuigated with#[cfg(feature = "gpui-ui")].src/ui/backend.rsGpuiTerminalCommandExecutorimport gated.DefaultCommandExecutorwhen feature is off.src/ui/ui_events.rsterminal::StyledLinere-exported under#[cfg(feature = "gpui-ui")].struct StyledLine;defined under#[cfg(not(feature = "gpui-ui"))].src/main.rs--uilogging, model resolution, andapp::gpui::run()all gated.--uiwithout the feature prints a clear error.src/cli.rsUiSettings::load()gated; TUI-only builds fall through to alphabetical-first-model fallback.Test plan
cargo build --no-default-featurescompletes without Xcode/Metal tools../target/debug/code-assistantlaunches the terminal TUI normally../target/debug/code-assistant --versionprints the version string../target/debug/code-assistant --uiprints the feature-missing error message.cargo build --features gpui-uisucceeds and--uilaunches the GPUI desktop interface.