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

rfc: Electron C APIs #3

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

rfc: Electron C APIs #3

wants to merge 1 commit into from

Conversation

zcbenz
Copy link

@zcbenz zcbenz commented Jan 11, 2024

This RFC is modified from the Electron C APIs spec doc with implementation details added, which can be used to bootstrap some basic facilities.

@zcbenz zcbenz requested a review from a team as a code owner January 11, 2024 09:41
@zcbenz zcbenz changed the title RFC: Electron C APIs roc: Electron C APIs Jan 11, 2024
@zcbenz zcbenz changed the title roc: Electron C APIs rfc: Electron C APIs Jan 11, 2024

There is no restriction on API names, and it is not recommeneded to prefix the APIs with `electron_` unless they directly manipulates things of Electron.

This is because the actual implementations of C APIs may not necessarily reside in Electron's codebase, and we may not have control of its API names.
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure I understand why this might occur in practice. In the skia example, would Electron be exposing headers for Chromium's included version of skia?

Copy link
Author

Choose a reason for hiding this comment

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

Skia is a C++ library that does not have stable APIs, exposing its headers won't be very useful in practice. To provide C APIs for it we have to write a translation layer.

Another better example is the ui/views library of Chromium, to provide C APIs for it we will need a non-trivial project. I have actually made a demo which I plan to introduce as the first set of C APIs to include in Electron some time later: https://github.com/photoionization/chrohime.

Copy link
Member

Choose a reason for hiding this comment

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

The idea of allowing folks to extend Electron without needing to go through the review process or forking is certainly appealing.

If you're open to it, I think scheduling a meeting within the API WG to go over chrohime and how this RFC enables its efforts would go a long way in getting more attention here.

Copy link
Author

Choose a reason for hiding this comment

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

Yeah I'm good with it, thanks for bringing it up!


Most components of Chromium are written in C++, and to expose C APIs for them a separate C wrapper must be written, and they may require extra maintaince work during Chromium upgrades.

A possible stratege to solve this is to ask the implementation of C wrapper to live outside Electron's codebase, and only be included in Electron as an optional componenet which can be easily turned off, so it won't add up to the maintaince work of Chromium upgrades.
Copy link
Member

Choose a reason for hiding this comment

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

If a component were disabled during an upgrade, how might app developers discover whether it's supported in newer versions? Would maintaining a supported status for each C API be needed?

Copy link
Author

Choose a reason for hiding this comment

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

Yeah I think we will need to maintain an updated documentation for the status of C APIs.


### External JavaScript bindings

For Electron apps to make use of the C APIs, they usually want to use JavaScript APIs instead of writing all the code in C. In which case a JavaScript bindings also needs to be implemented for the C APIs, and the separated layer can be difficult to use when the JavaScript bindings get out of sync with changes in the C APIs.
Copy link
Member

Choose a reason for hiding this comment

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

Thinking beyond JS, I wonder if wasm's component model could be used to enable support to other languages. This may be a larger discussion than the scope of this RFC though.

Copy link
Author

Choose a reason for hiding this comment

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

We can probably wait to see how Node.js and Chromium will support it first.


## Unresolved questions

The API and ABI stability of C APIs are not covered in this RFC. I think if a set of C APIs has been depended on so much that we actually need to promise API and ABI stability for them, we should probably make them built-in JavaScript APIs, or the independent C library version of the APIs should have already gained enough popularity that it no longer needs Electron team's resources to go on developing.
Copy link
Member

Choose a reason for hiding this comment

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

I think a stages process could be useful in defining a path towards stability—somewhat similar to ECMAScript's stages. Probably not necessary until significant community contributions are made.

@erickzhao erickzhao added the pending-review Waiting for reviewers to give feedback on the PR specifications label Jul 12, 2024
@itsananderson
Copy link
Member

Hey @zcbenz!

I know you're not as actively involved with the Electron project these days, but are you still interested in moving this RFC forward?

This is something that I'm very interested in getting across the finish line, and I expect to have the bandwidth to take it on at the beginning of the new year if you no longer have time for it. Since GitHub doesn't have a way to change the owner of a PR, I think once I'm ready to pick this up, I'd need to close this PR and then open a new RFC PR with his proposal as the starting point.

@zcbenz
Copy link
Author

zcbenz commented Oct 16, 2024

@itsananderson Feel feel to close this PR when needed. I don't think I'll do more efforts to push this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pending-review Waiting for reviewers to give feedback on the PR specifications
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants