Skip to content

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

Open
alexander-beedie wants to merge 1 commit intoapache:mainfrom
alexander-beedie:fix-derive-dialect-mod-file
Open

Fix derive_dialect! proc macro for use from external crates#2219
alexander-beedie wants to merge 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
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.

1 participant