Skip to content

fix: Enable WASM compilation by making sqlparser's recursive-protection optional #16418

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

Merged
merged 3 commits into from
Jun 17, 2025

Conversation

jonmmease
Copy link
Contributor

Summary

This PR fixes the WASM compilation issue (#13513) by making sqlparser's recursive-protection feature optional. This allows DataFusion to be compiled for WebAssembly targets without encountering the "LLVM error: section too large" error caused by the PSM (Portable Stack Manipulation) dependency.

Background

When compiling DataFusion for WASM (target wasm32-unknown-unknown), the build fails with:

error: failed to build archive at `.../libpsm-xxx.rlib`: LLVM error: section too large

The dependency chain causing this issue is:

datafusion → datafusion-sql → sqlparser (with default features) → recursive → stacker → psm

The PSM crate is incompatible with WebAssembly because.

As noted in the PSM documentation itself:

"This library is not applicable to the target. WASM hasn't a specified C ABI, the callstack is not even in an address space and does not appear to be manipulatable."

The Fix

This PR implements a solution that maintains backward compatibility while enabling WASM builds:

  1. Workspace Level: Set default-features = false for sqlparser to prevent automatic inclusion of recursive-protection
  2. DataFusion Core: Add explicit feature flags for sqlparser's default features:
    • sqlparser_std → enables sqlparser/std
    • sqlparser_recursive_protection → enables sqlparser/recursive-protection
  3. Default Features: Include these flags in DataFusion's default features to maintain backward compatibility

Usage

After this change:

For WASM builds (no PSM dependency):

datafusion = { version = "48.0.0", default-features = false, features = ["parquet", "sqlparser_std"] }

For regular builds (unchanged behavior):

datafusion = "48.0.0"  # Includes all default features including recursive protection

Related Issues and Context

Notes

While PR #13887 made recursive_protection optional in datafusion-sql, it didn't fully solve the WASM compilation issue because sqlparser itself was still being pulled in with its default features across multiple DataFusion crates. This PR completes the fix by ensuring sqlparser's default features can be controlled at the workspace level.

…ility

This change addresses the PSM "section too large" error when building DataFusion
for WebAssembly by making sqlparser's recursive-protection feature optional.

Changes:
- Set default-features = false for sqlparser in workspace Cargo.toml
- Add sqlparser_std and sqlparser_recursive_protection features to datafusion crate
- Include these features in datafusion's default features for backward compatibility

This allows WASM builds to exclude the problematic dependency chain:
sqlparser → recursive → stacker → psm

While maintaining full compatibility for non-WASM builds.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@github-actions github-actions bot added the core Core DataFusion crate label Jun 15, 2025
The std feature is required for sqlparser to compile properly.
Without it, basic types and imports are missing.
@@ -79,6 +81,9 @@ recursive_protection = [
"datafusion-physical-optimizer/recursive_protection",
"datafusion-sql/recursive_protection",
]
# Enable sqlparser's default features for backward compatibility
sqlparser_std = ["sqlparser/std"]
sqlparser_recursive_protection = ["sqlparser/recursive-protection"]
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there any need to add this new sqlparser_recursive_protection = ["sqlparser/recursive-protection"] feature? could we instead just add it to the recursive_protection existing feature?

recursive_protection = [
    "datafusion-common/recursive_protection",
    "datafusion-expr/recursive_protection",
    "datafusion-optimizer/recursive_protection",
    "datafusion-physical-optimizer/recursive_protection",
    "datafusion-sql/recursive_protection",
    "sqlparser/recursive-protection", # Add this???
]

I also don't fully understand why we need a new feature for sqlparser_std as that would seem to already be enabled

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, yeah, good call. Made these updates in 485a505

Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

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

Thank you for this contribution @jonmmease -- I think wasm is a very important target.

Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

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

Makes sense to me -- thank you @jonmmease

@alamb alamb merged commit 87218a1 into apache:main Jun 17, 2025
30 checks passed
@alamb
Copy link
Contributor

alamb commented Jun 17, 2025

Thanks again @jonmmease

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Core DataFusion crate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"recursive" Dependency Causes "section too large" Error When Compiling for wasm
2 participants