Skip to content

rfc: c apis - #33

Open
YUCLing wants to merge 1 commit into
electron:mainfrom
YUCLing:rfc/0030-c-api
Open

YUCLing wants to merge 1 commit into
electron:mainfrom
YUCLing:rfc/0030-c-api

Conversation

@YUCLing

@YUCLing YUCLing commented Oct 7, 2026

Copy link
Copy Markdown

Proposes a small, versioned C ABI for native addons: one exported symbol, electron_get_api(), filling a size-negotiated core table. Feature sets are reached through a generic get_feature() lookup, so adding a feature never adds an exported symbol or changes the core layout.

Scope is deliberately narrow — the mechanism, its stability policy, and a CI conformance test. No feature set is proposed here; the Wayland connection feature set that motivates this work will follow separately, and I’m working on it in parallel so it can serve as the first test case for this mechanism.

Note: no additional cross-platform feature set is planned right now; Wayland is the only immediate priority.

Supersedes #3.

Looking forward to feedback from the Electron team! 🚀

@YUCLing
YUCLing requested a review from a team as a code owner October 7, 2026 14:47
@erickzhao erickzhao added the pending-review Waiting for reviewers to give feedback on the PR specifications label Nov 12, 2026

@itsananderson itsananderson left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you for submitting this proposal!

I've left a few comments about specific details of the RFC, and I have a few other high-level comments/suggestions:

  1. It sounds like you have some specific Wayland use-cases that motivate this proposal. Would it be possible for you to add a more expanded code example of the kind of feature that you might build with this API. It will be helpful to have some concrete API proposals (and motivating use-cases) that we can review and approve as part of this RFC.
  2. Something useful that the approach in #3 provided was a way to statically check API availability at compile-time, which would make it easier to verify that a native module is compatible with a specific Electron version, using compile-time checks. If I'm understanding your RFC correctly, it would mostly be limited to runtime checks for checking if an API is available. Would it be possible to incorporate the compile-time feature availability check into your RFC?
  3. We discussed this a bit in our last API WG meeting, and we think that ABI compatibility should be a non-goal for these C APIs. Because Electron is built on top of Chromium, we are subject Chromium's internal changes every time we upgrade our base Chromium version. This will make it very difficult for us to guarantee API backward compatibility, much less ABI compatibility. Because we can't provide these guarantees, native modules which use this C API will need to be recompiled for the specific Electron version they will be shipped with.

Comment thread text/0030-c-api.md
if (electron_get_api(ELECTRON_API_VERSION, &api) != ELECTRON_RESULT_OK) return -1;

/* A feature's header declares its table type; discovery itself is by name. */
electron_wayland_connection_api_t wl = {0};

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If I want to build against a new Electron version, but also support older Electron versions, it would be a compile-time error to reference types like electron_wayland_connection_api_t if they're not yet available in older Electron versions.

Comment thread text/0030-c-api.md

electron_api_t api = {0};
api.struct_size = sizeof(api);
if (electron_get_api(ELECTRON_API_VERSION, &api) != ELECTRON_RESULT_OK) return -1;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Does ELECTRON_API_VERSION come from electron/c_api.h or is it a constant that a native module would define for itself, to specify the ABI version that it wants to request.

Comment thread text/0030-c-api.md
7. **Stability.** The core mechanism is stable from the start and append-only. Feature sets
are experimental until individually promoted, with their status recorded in
`docs/experimental.md` beside the existing experimental tag.
8. **Enforcement.** A CI conformance test compiles a fixture addon against the previously

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

While I think detecting accidental breakage of the ABI is sensible, I don't think we can necessarily guarantee that old API versions will never be broken, because we sometimes need to deprecate/remove APIs due to changing OS or Chromium support. However, maybe we could use a mechanism like this to detect and remove ABI versions that are no longer supportable by new Electron releases.

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.

3 participants