Skip to content

webgl: Add feature guard - #47200

Merged
Narfinger merged 9 commits into
servo:mainfrom
janeoa:webgl-feature-guard
Aug 13, 2026
Merged

Narfinger merged 9 commits into
servo:mainfrom
janeoa:webgl-feature-guard

Conversation

@janeoa

@janeoa janeoa commented Aug 12, 2026 •

Copy link
Copy Markdown
Contributor

Add webgl feature guard, so that we can build without it.

Testing: has no automated tests, but can verify by building without the webgl using ./mach build --no-default-features --features bundled,gamepad,webgpu,max_log_level,js_jit
Fixes: #47184

This PR does a lot of small changes:

  • adds webgl = [] as features to script, servoshell, servo, constellation, paint
  • adds a lot of #[cfg(feature = "webgl")]
  • make webxr depend on webgl webxr = ["webgl", (as previouslty webgl was non optional)
  • adds // skip-unless CARGO_FEATURE_WEBGL to the .webdl's

The .webdl part was tricky as it had:

typedef (OffscreenCanvasRenderingContext2D
  or ImageBitmapRenderingContext
  or WebGLRenderingContext
  or WebGL2RenderingContext
) OffscreenRenderingContext;

and as the WebGLRenderingContext is now optional, I had to introduce

typedef (OffscreenCanvasRenderingContext2D
  or ImageBitmapRenderingContext
  // skip-unless CARGO_FEATURE_WEBGL begin
  or WebGLRenderingContext
  or WebGL2RenderingContext
  // skip-unless CARGO_FEATURE_WEBGL end
) OffscreenRenderingContext;

I though about making it a separate PR, but I guess it should stay here, as the separate PR would need a working example anyway.


I made sure that this would still compile with and without webgl, and currently webxr forces webgl as a dependency

@janeoa
janeoa requested a review from gterzian as a code owner August 12, 2026 14:45
@servo-highfive servo-highfive added the S-awaiting-review There is new code that needs to be reviewed. label Aug 12, 2026
Comment thread components/script_bindings/webidls/HTMLCanvasElement.webidl
Comment thread components/script/dom/document/document.rs Outdated
Comment thread components/script/dom/window/window.rs Outdated
Comment thread components/constellation/constellation.rs Outdated
Comment thread components/script/dom/document/document.rs Outdated
@servo-highfive servo-highfive added S-awaiting-review There is new code that needs to be reviewed. and removed S-awaiting-review There is new code that needs to be reviewed. labels Aug 12, 2026
janeoa added 9 commits August 13, 2026 14:16
Signed-off-by: Asset Malik <5373400+janeoa@users.noreply.github.com>
Signed-off-by: Asset Malik <5373400+janeoa@users.noreply.github.com>
Signed-off-by: Asset Malik <5373400+janeoa@users.noreply.github.com>
Signed-off-by: Asset Malik <5373400+janeoa@users.noreply.github.com>
Signed-off-by: Asset Malik <5373400+janeoa@users.noreply.github.com>
Signed-off-by: Asset Malik <5373400+janeoa@users.noreply.github.com>
Signed-off-by: Asset Malik <5373400+janeoa@users.noreply.github.com>
Signed-off-by: Asset Malik <5373400+janeoa@users.noreply.github.com>
Signed-off-by: Asset Malik <5373400+janeoa@users.noreply.github.com>
@janeoa
janeoa force-pushed the webgl-feature-guard branch from 95eb412 to 7400b08 Compare August 13, 2026 12:28
@Narfinger
Narfinger added this pull request to the merge queue Aug 13, 2026
@servo-highfive servo-highfive added the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Aug 13, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Aug 13, 2026
@servo-highfive servo-highfive added S-tests-failed The changes caused existing tests to fail. and removed S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. labels Aug 13, 2026
@Narfinger
Narfinger added this pull request to the merge queue Aug 13, 2026
@servo-highfive servo-highfive added S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. and removed S-tests-failed The changes caused existing tests to fail. labels Aug 13, 2026
Merged via the queue into servo:main with commit 522fa37 Aug 13, 2026
39 checks passed
@servo-highfive servo-highfive removed the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Aug 13, 2026
@janeoa janeoa mentioned this pull request Aug 14, 2026
@delan delan mentioned this pull request Sep 7, 2026
@janeoa
janeoa deleted the webgl-feature-guard branch September 8, 2026 09:08
RichardTjokroutomo pushed a commit to RichardTjokroutomo/servo that referenced this pull request Oct 6, 2026
Add webgl feature guard, so that we can build without it.

Testing: has no automated tests, but can verify by building without the
webgl using `./mach build --no-default-features --features
bundled,gamepad,webgpu,max_log_level,js_jit`
Fixes: servo#47184

This PR does a lot of small changes:
- adds `webgl = []` as features to script, servoshell, servo,
constellation, paint
- adds a lot of `#[cfg(feature = "webgl")]`
- make webxr depend on webgl `webxr = ["webgl",` (as previouslty webgl
was non optional)
- adds `// skip-unless CARGO_FEATURE_WEBGL` to the `.webdl`'s

The .webdl part was tricky as it had:
```
typedef (OffscreenCanvasRenderingContext2D
  or ImageBitmapRenderingContext
  or WebGLRenderingContext
  or WebGL2RenderingContext
) OffscreenRenderingContext;
```
and as the WebGLRenderingContext is now optional, I had to introduce 

```
typedef (OffscreenCanvasRenderingContext2D
  or ImageBitmapRenderingContext
  // skip-unless CARGO_FEATURE_WEBGL begin
  or WebGLRenderingContext
  or WebGL2RenderingContext
  // skip-unless CARGO_FEATURE_WEBGL end
) OffscreenRenderingContext;
```

I though about making it a separate PR, but I guess it should stay here,
as the separate PR would need a working example anyway.

---

I made sure that this would still compile with and without webgl, and
currently webxr forces webgl as a dependency

---------

Signed-off-by: Asset Malik <5373400+janeoa@users.noreply.github.com>
opensource-fork-sync Bot pushed a commit to cla7aye15I4nd/opensource-servo__servo that referenced this pull request Oct 12, 2026
This PR feature guards the devtools

Just like in the servo#47200 I introduced
a new feature `devtools`. It is now optional and requires `debugging`
(under the same feature guard as a direct dependency). This feature
guard preserves `console`.

PR also introduces a small `default_tooling = ["servo/default_tooling"]`
along to the already present `default_web_features`
```toml
...
default_tooling = ["devtools"]
...
```

(Cargo.toml of servoshell:)
```toml
default = ["default_without_allocator", "servo-allocator/use-jemalloc"]
default_without_allocator = ["bundled", "default_web_features", "default_tooling", "max_log_level", "js_jit"]
default_web_features = ["servo/default_web_features", "gamepad", "webgpu", "webxr"]
default_tooling = ["servo/default_tooling"]
```

Testing: `./mach build --no-default-features --features
bundled,gamepad,webgpu,max_log_level,js_jit`

Builds that pass:
- `./mach build --no-default-features --features
bundled,gamepad,webgpu,max_log_level,js_jit`
- `./mach build`
- `./mach build --features devtools`
- `./mach build --features webgl`

Fixes: [47187](servo#47187)

P.S. I've left a bunch of "dead_code" warnings unaddressed. Could be a
future PR candidate, but I guess the `production` profile would optimize
them away anyway and them extra feature guards might cause more clutter
in the default build?

---------

Signed-off-by: Asset Malik <5373400+janeoa@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-awaiting-review There is new code that needs to be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature guard WebGL

5 participants