Skip to content

Add support for custom cef framework and subprocess paths - #71

Merged
not-elm merged 5 commits into
not-elm:mainfrom
rohitsangwan01:add-support-for-custom-CEF-framework-and-subprocess-paths
Oct 25, 2026
Merged

not-elm merged 5 commits into
not-elm:mainfrom
rohitsangwan01:add-support-for-custom-CEF-framework-and-subprocess-paths

Conversation

@rohitsangwan01

@rohitsangwan01 rohitsangwan01 commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Problem

  1. Rigid Path Expectations: Previously, bevy_cef expected CEF framework files and helper binaries to either exist in fixed developer paths (~/.local/share/cef/... with the debug feature enabled) or directly adjacent to the main executable in a prebundled app layout. Applications that download or manage CEF dynamically at runtime (e.g. into OS application support directories or custom portable folders) had no way to point bevy_cef to an arbitrary directory.
  2. Helper Process Sandbox Panics on macOS: In bevy_cef_render_process, cef::sandbox::Sandbox::new() was called unconditionally on macOS. When running standalone or in setups where libcef_sandbox.dylib was not linked or present at ../../../Chromium Embedded Framework.framework/Libraries/libcef_sandbox.dylib, the helper process panicked immediately on startup with Os { code: 2, kind: NotFound }.
  3. Helper Process Dynamic Linking on macOS: When helper subprocesses were spawned outside standard bundle structures, library_loader::LibraryLoader failed to resolve the framework dynamically from custom locations or sibling directory structures.

Solution

  1. Configurable CefPlugin Paths:
    • Added pub cef_path: Option<PathBuf> and pub subprocess_path: Option<PathBuf> to CefPlugin and MessageLoopPlugin.
    • Applications can now configure explicit runtime paths directly in code.
  2. Environment Variable Fallback:
    • Implemented resolve_custom_cef_paths() in bevy_cef_core to check explicit parameters, falling back to CEF_PATH / CEF_FRAMEWORK_DIR and CEF_SUBPROCESS_PATH.
    • Supports directory paths, .framework bundles, and direct binary paths across macOS, Windows, and Linux.
  3. Custom Dynamic Framework Loader:
    • Added CustomLibraryLoader in bevy_cef_core::debug to load Chromium Embedded Framework on macOS from arbitrary file paths at runtime via load_library.
  4. Resilient Subprocess Sandbox & Framework Discovery:
    • In bevy_cef_render_process/src/main.rs, sandbox initialization is now guarded by checking whether libcef_sandbox.dylib exists and protected with std::panic::catch_unwind.
    • Subprocess now checks for custom framework paths or sibling framework bundles before falling back to default library loader.

Test Pattern

  • Compilation Check:
    cargo check
    cargo check --manifest-path crates/bevy_cef_render_process/Cargo.toml
  • Custom Path via CefPlugin:
    App::new()
        .add_plugins(CefPlugin {
            cef_path: Some(PathBuf::from("/path/to/custom/cef")),
            ..Default::default()
        })
  • Custom Path via Environment Variable:
    CEF_PATH="/path/to/custom/cef" cargo run --example simple
  • Verified Subprocess Spawning: Confirmed that macOS helper processes (--type=gpu-process, --type=utility) resolve the framework and initialize cleanly without sandbox missing-library aborts.

@not-elm

not-elm commented Oct 24, 2026

Copy link
Copy Markdown
Owner

In crates/bevy_cef_render_process/src/main.rs:49, the CEF path is resolved as follows:

// In crates/bevy_cef_render_process/src/main.rs:49
let (_, framework_binary, _) = resolve_custom_cef_paths(None, None);

This works when the environment variables are set, but the child process does not appear to pick up the path specified in the parent’s CefPlugin.cef_path.

I temporary created examples/custom_cef_paths.rs to test this. It works with the default debug configuration, but crashes when I unset the environment variables and explicitly set CefPlugin.cef_path and subprocess_path:

cargo build -p bevy_cef_render_process

env -u CEF_PATH -u CEF_FRAMEWORK_DIR -u CEF_SUBPROCESS_PATH \
  cargo run --example custom_cef_paths --features debug -- \
  "$HOME/.local/share/cef" \
  "$PWD/target/debug/bevy_cef_render_process"

The child process panics inside LibraryLoader::new with a No such file or directory error.

One possible fix would be to pass the parent’s resolved path to the child through a command-line argument and read it before loading CEF. If CEF already passes --framework-dir-path, the child may be able to use that argument directly. It would also be worth checking that bevy_cef_debug_render_process supports custom paths in the same way.

@rohitsangwan01

Copy link
Copy Markdown
Contributor Author

@not-elm i have added cli argument support for custom cef path

@not-elm not-elm left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!
I'll merge this PR

@not-elm
not-elm merged commit 32cb50f into not-elm:main Oct 25, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants