Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate full-coverage safe bindings from the bindgen C API output #9

Open
wants to merge 38 commits into
base: main
Choose a base branch
from

Conversation

wravery
Copy link

@wravery wravery commented Jan 3, 2025

I got this idea from noticing that CEF already relies on code generators to translate the internal C++ API to a C API in the DLL/cdylib exports, then generates C to C++ bindings for consumption there. The bindgen tool already does a pretty good job with the C API, but it's all unsafe and much harder to use without the wrapper types you were already working on. The problem with the wrapper types though is that they need to be hand-coded and kept in sync with new versions of CEF.

To fix that, I implemented a code generator in the unpublished update-bindings crate that parses the current bindgen output in /sys/src/bindings.rs with the syn crate and then outputs safe wrappers for the whole C API with the quote crate, much like a proc-macro would.

The main source for update-bindings is in /update-bindings/src/parse_tree.rs, and the output is in /cef/src/bindings.rs. I was able to delete most of the wrapper type modules aside from some custom implementations in the rc and strings modules.

I restructured the cargo workspace to put each crate in a sub-directory, so the main cef crate is no longer in the root directory, it's in /cef/.... The easiest way to compare the before and after API is to look at the original /examples/demo.rs vs. the demo in its new location, /cef/examples/demo.rs.

wravery and others added 30 commits December 17, 2024 23:19
@wravery
Copy link
Author

wravery commented Jan 3, 2025

See also chromiumembedded/cef#3836 for progress on making CEF itself redistributable.

@wravery
Copy link
Author

wravery commented Jan 3, 2025

@wusyong BTW, what do you think of moving this to the https://github.com/tauri-apps org for ongoing development? Ideally, that would include publishing/ownership on crates.io as well.

@wusyong
Copy link
Owner

wusyong commented Jan 4, 2025

@wravery Thanks for the PR! Bindgen was on my list for this project back in the day. Unfortunately, I've been laid off from the company that sponsored my work in Tauri. I haven't followed its development for a while.

That said, I'll still try to review it next week if I have time. Have you tried running it on Linux? I mean Wayland more specifically. One of the reasons I tried to explore this port is that webkitgtk is underperforming a lot. However, last time I checked cef's wayland port isn't great either.

@wravery
Copy link
Author

wravery commented Jan 4, 2025

Oh, I'm sorry to hear about the layoff! I saw that you were still active in other projects like Servo and figured you'd just shifted focus. You are missed in the Tauri project.

To your question about Wayland, I have been testing with the demo example and it seems fine, but so did webkitgtk in my own Tauri app. I'm using the latest COSMIC alpha on Pop_OS! with Wayland for Linux development.

The thing that prompted me to get involved was I started hearing about cases where browser compatibility on Linux was blocking adoption. In other words, performance wasn't the primary concern, browser compatibility/consistency was. From the Tauri perspective, it would be great to have an option of switching to CEF as necessary (e.g., when migrating from Electron's Chromium front end), even if we stick with another rendering engine by default.

@Norbiros
Copy link

Norbiros commented Jan 4, 2025

Webkit has a lot of problems. For example in Modrinth App (which uses tauri) there are a lot of performance issues modrinth/code#3057, random freezes modrinth/code#1127, modrinth/code#1216 etc.

I'm using Gentoo Linux with Gnome and CEF seems way more stable than webkit. I tested random websites, browser benchmarks and this solution works perfectly fine.

@csmoe
Copy link

csmoe commented Jan 6, 2025

@wravery sorry for bothering you here, this repo seems not actively maintained #5 (comment), so I forked here https://github.com/csmoe/cef-rs, made it compilable on linux/mac/windows and fixed some issues, but my current wrapper is just a simple modification based on wrapper, I have been looking for a better automatically approach, could we combine our effort? If possible, I can add you as a collaborator, or transfer the repo to you, as you have been maintaining the webview-rs for years

@wravery
Copy link
Author

wravery commented Jan 6, 2025

@wravery sorry for bothering you here, this repo seems not actively maintained #5 (comment), so I forked here https://github.com/csmoe/cef-rs, made it compilable on linux/mac/windows and fixed some issues, but my current wrapper is just a simple modification based on wrapper, I have been looking for a better automatically approach, could we combine our effort? If possible, I can add you as a collaborator, or transfer the repo to you, as you have been maintaining the webview-rs for years

Hi @csmoe 👋🏼, I'd be happy to work with you on that. Trying out the update-bindings tool on some bindgen bindings for other platforms is definitely on my TODO list. It looks like you've already automated much of that aspect.

I'd still like to try to upstream those changes and mine to this project, if only so that we can keep the crate name cef on crates.io. I understand if that's asking too much of @wusyong, though. If it works better for us to take over the maintenance, I recommend we fold it into the Tauri project, either with a new name or with crates.io ownership transferred, e.g., to @tauri-bot.

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.

4 participants