Skip to content

Fix derive_dialect! proc macro for use from external crates#2219

Merged
iffyio merged 1 commit intoapache:mainfrom
alexander-beedie:fix-derive-dialect-mod-file
Feb 18, 2026
Merged

Fix derive_dialect! proc macro for use from external crates#2219
iffyio merged 1 commit intoapache:mainfrom
alexander-beedie:fix-derive-dialect-mod-file

Conversation

@alexander-beedie
Copy link
Contributor

@alexander-beedie alexander-beedie commented Feb 15, 2026

Unfortunately I made a classic proc-macro blunder in #2174, forgetting that $CARGO_MANIFEST_DIR points to the crate being compiled, which is not the sqlparser crate. So all the tests worked (as the crate being compiled and the sqlparser crate are the same), but actual use from an external crate fails (without exotic workarounds) 😅

This PR fixes and industrialises the source lookup; now it does the following (documented/explained in the code too):

  1. $CARGO_MANIFEST_DIR/src/dialect/mod.rs: works when macro invoked from within the sqlparser crate (e.g. tests).
  2. <sqlparser_derive dir>/../src/dialect/mod.rs: works when sqlparser_derive lives in a workspace alongside the main crate (standard derive/ layout).
  3. Sibling directories of compiled sqlparser_derive crate in the Cargo registry: works when an external crate uses derive_dialect! via registry dependency.

Confirmed this addresses the issue, and dialects can now be properly derived in/from external crates 👍
Also: minor tweak to use slightly more idiomatic map_err! inside derive_dialect.

@alexander-beedie alexander-beedie force-pushed the fix-derive-dialect-mod-file branch from 77e405f to f8cb6b0 Compare February 15, 2026 07:32
Copy link
Contributor

@iffyio iffyio left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks @alexander-beedie!

@iffyio iffyio added this pull request to the merge queue Feb 18, 2026
Merged via the queue into apache:main with commit 40350e3 Feb 18, 2026
10 checks passed
@alexander-beedie alexander-beedie deleted the fix-derive-dialect-mod-file branch February 18, 2026 09:41
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.

2 participants

Comments