Skip to content

Conversation

william-stacken
Copy link
Contributor

Description of the change

Adds a codegen option that allows for opting out of the javy_source custom section. If -C source=n is specified to the CLI, source-compression has no effect.

Fixes #982

Why am I making this change?

Allows for smaller Wasm modules output by Javy in case the source code is not necesary. Through local testing I was able to shrink my Wasm modules by about one third.

Checklist

  • I've updated the relevant CHANGELOG files if necessary. Changes to javy-cli, javy-plugin, and javy-plugin-processing do not require updating CHANGELOG files.
  • I've updated the relevant crate versions if necessary. Versioning policy for library crates
  • I've updated documentation including crate documentation if necessary.

Comment on lines 214 to 216
/// Enable source code compression, which generates smaller WebAssembly
/// files at the cost of increased compile time.
SourceCompression(bool),
Copy link
Member

Choose a reason for hiding this comment

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

Could you update the documentation to reflect that this flag will be a no-op in case -source=n?

Comment on lines 212 to 213
/// Embed the JavaScript source in the generated WebAssembly module.
Source(bool),
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/// Embed the JavaScript source in the generated WebAssembly module.
Source(bool),
/// Embed the JavaScript source in custom section the generated WebAssembly module.
Source(bool),

@@ -159,7 +159,9 @@ pub struct Generator {
pub(crate) plugin: Plugin,
/// What kind of linking to use when generating a module.
pub(crate) linking: LinkingKind,
/// Whether to embed the compressed JS source in the generated module.
/// Whether to embed the JS source in the generated module.
pub(crate) source: bool,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Specifically in the codegen crate, can we make source an enum with three options: omitted, compressed, and uncompressed and remove the source_compression field?

I think that would make more sense that two booleans given there's only three states and we're going to be releasing a new major version for the crate soon anyway so a breaking change is fine.

@jeffcharles
Copy link
Collaborator

You'll need to run cargo fmt on the code. Running make fmt tests should give you a decent idea if CI will pass.

@jeffcharles jeffcharles merged commit 3ac9165 into bytecodealliance:main Aug 28, 2025
4 checks passed
@jeffcharles
Copy link
Collaborator

Thank you for contributing!

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.

Trim javy_source from compiled wasm modules?
3 participants