Skip to content

sqlx-macros-core: allow not calling cargo from a proc-macro - #4556

Open
lf- wants to merge 2 commits into
transact-rs:mainfrom
MercuryTechnologies:jade/push-vwoyvrqvxpvz
Open

lf- wants to merge 2 commits into
transact-rs:mainfrom
MercuryTechnologies:jade/push-vwoyvrqvxpvz

Conversation

@lf-

@lf- lf- commented Nov 26, 2026

Copy link
Copy Markdown

Rebase of #4315. We've been using this in production for a few months without issue; I just dropped the ball on that PR for some personal reasons.

Problem:
We're trying to build
https://github.com/MercuryTechnologies/locally-euclidean with buck2, and we're finding that sqlx is trying to call Cargo to find the workspace root and snoop outside of its build directory.

This is trouble for us because we want to be able to cache build actions. Thus, we want to be able to run sqlx in an extra offline mode which never calls cargo.

Solution: check if all the env-vars are set (which requires that you put nonsense in the database url, but that's ok for us as it ensures we cannot possibly regress any existing users).

Problem: If a query is missed in .sqlx/, sqlx calls cargo unconditionally to find the workspace root.

Solution: accept SQLX_WORKSPACE_DIR to give the fallback directory. You could make it /var/empty if you want to suppress it altogether.

Does your PR solve an issue?

Not one I've written. Related Bazel usage: #3555, related env-var shenanigans in the CLI #3963.

Is this a breaking change?

No. This will not be observable to external consumers except by calling cargo pointlessly fewer times.

@lf-
lf- marked this pull request as draft November 26, 2026 20:14
lf- added 2 commits November 26, 2026 13:14
Problem:
We're trying to build
https://github.com/MercuryTechnologies/locally-euclidean with buck2, and
we're finding that sqlx is trying to call Cargo to find the workspace
root and snoop outside of its build directory.

This is trouble for us because we want to be able to cache build
actions. Thus, we want to be able to run sqlx in an *extra* offline mode
which never calls cargo.

Solution: check if all the env-vars are set (which requires that you put
nonsense in the database url, but that's ok for us as it ensures we
cannot possibly regress any existing users).

Problem: If a query is missed in .sqlx/, sqlx calls cargo
unconditionally to find the workspace root.

Solution: accept SQLX_WORKSPACE_DIR to give the fallback directory. You
could make it /var/empty if you want to suppress it altogether.

### Does your PR solve an issue?

Not one that either I nor an agent can find.
Related Bazel usage: transact-rs#3555, related env-var shenanigans in the CLI transact-rs#3963, but neither are solved by this.
@lf-
lf- force-pushed the jade/push-vwoyvrqvxpvz branch from fd2d691 to ff5e545 Compare November 26, 2026 20:15
@lf-
lf- marked this pull request as ready for review November 26, 2026 20:21
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