-
Notifications
You must be signed in to change notification settings - Fork 125
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Describe the bug
I can't cross-compile a project using sqlx and sqlx-macros with the sqlite-unbundled feature.
Error log
Executing configureCargoCommonVars
----------------------------------------------------------------------------------
NOTICE: setting the following environment variables for cross-compilation purposes
- if this is unwanted, you can set them to a non-empty value
- alternatively, you can disable the built-in cross compilation support
by setting `doIncludeCrossToolchainEnv = false` in the derivation
AR_X86_64_PC_WINDOWS_GNU=x86_64-w64-mingw32-ar
AR_X86_64_UNKNOWN_LINUX_GNU=ar
CARGO_BUILD_TARGET=x86_64-pc-windows-gnu
CARGO_TARGET_X86_64_PC_WINDOWS_GNU_LINKER=x86_64-w64-mingw32-cc
CARGO_TARGET_X86_64_PC_WINDOWS_GNU_RUNNER=/nix/store/xasgsbas61xwm2csysdrncxg6367k364-wine64-10.0/bin/wine64
CARGO_TARGET_X86_64_PC_WINDOWS_GNU_RUSTFLAGS=-L native=/nix/store/wpjziab51p75yyxpf10716vn5pxrjrbg-mingw_w64-pthreads-x86_64-w64-mingw32-13.0.0/lib
CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER=cc
CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_RUSTFLAGS=-L native=/nix/store/wpjziab51p75yyxpf10716vn5pxrjrbg-mingw_w64-pthreads-x86_64-w64-mingw32-13.0.0/lib
CC_X86_64_PC_WINDOWS_GNU=x86_64-w64-mingw32-cc
CC_X86_64_UNKNOWN_LINUX_GNU=cc
CXX_X86_64_PC_WINDOWS_GNU=x86_64-w64-mingw32-c++
CXX_X86_64_UNKNOWN_LINUX_GNU=c++
HOST_AR=ar
HOST_CC=cc
HOST_CXX=c++
TARGET_AR=x86_64-w64-mingw32-ar
TARGET_CC=x86_64-w64-mingw32-cc
TARGET_CXX=x86_64-w64-mingw32-c++
----------------------------------------------------------------------------------
Running phase: updateAutotoolsGnuConfigScriptsPhase
@nix { "action": "setPhase", "phase": "updateAutotoolsGnuConfigScriptsPhase" }
Running phase: configurePhase
@nix { "action": "setPhase", "phase": "configurePhase" }
will append /build/source/.cargo-home/config.toml with contents of /nix/store/f8xsnj653czy12za5i4lm0wdj3v8pc4h-vendor-cargo-deps/config.toml
default configurePhase, nothing to do
Running phase: buildPhase
@nix { "action": "setPhase", "phase": "buildPhase" }
+++ command cargo --version
cargo 1.89.0 (c24e10642 2025-06-23)
+++ command cargo check --release --locked --all-targets
[...]
Compiling sqlx-macros v0.8.6
error: linking with `cc` failed: exit status: 1
|
= note: "cc" [...]
= note: some arguments are omitted. use `--verbose` to show all linker arguments
= note: /nix/store/...-binutils-2.44/bin/ld: /nix/store/...-sqlite-x86_64-w64-mingw32-3.50.2/lib/libsqlite3.a(sqlite3.o):(.text+0x246f5): undefined reference to `log2'
note: [...]/libsqlite3.a(sqlite3.o) [...] dangerous relocation: R_AMD64_IMAGEBASE with __ImageBase undefined
note: [...]/ld: [...]/libsqlite3.a(sqlite3.o) [...] undefined reference to `CloseHandle'
I think what's happening there is that Rust is only getting a Windows sqlite library, and it's trying to link that to sqlx-macros, which is executed on Linux.
I have no idea how this works for the bundled sqlite...
Reproduction
# in Cargo.toml
[dependencies]
sqlx = { version = "0.8.6", features = ["sqlite-unbundled"] }Modified Windows cross-compilation example for sqlx:
{
description = "Cross compiling a rust program for windows";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
crane.url = "github:ipetkov/crane";
flake-utils.url = "github:numtide/flake-utils";
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs =
{
self,
nixpkgs,
crane,
flake-utils,
rust-overlay,
...
}:
flake-utils.lib.eachDefaultSystem (
system:
let
pkgs =
(import nixpkgs {
overlays = [ (import rust-overlay) ];
localSystem = system;
crossSystem = {
config = "x86_64-w64-mingw32";
libc = "msvcrt";
};
# HACK: __splicedPackages so we don't have to use pkgs.callPackage, which can't really be used with commonArgs
}).__splicedPackages;
inherit (pkgs) lib;
craneLib = (crane.mkLib pkgs).overrideToolchain (
p:
p.rust-bin.stable.latest.default.override {
targets = [ "x86_64-pc-windows-gnu" ];
}
);
unfilteredRoot = ./.; # The original, unfiltered source
src = lib.fileset.toSource {
root = unfilteredRoot;
fileset = lib.fileset.unions [
# Default files from crane (Rust and cargo files)
(craneLib.fileset.commonCargoSources unfilteredRoot)
# Include all the .sql migrations as well
./migrations
];
};
commonArgs = {
inherit src;
strictDeps = true;
nativeBuildInputs = with pkgs; [
pkg-config
pkgs.pkgsBuildBuild.rustPlatform.bindgenHook
];
buildInputs = with pkgs; [
sqlite
];
};
# Build *just* the cargo dependencies, so we can reuse
# all of that work (e.g. via cachix) when running in CI
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
my-crate = craneLib.buildPackage (
commonArgs
// {
inherit cargoArtifacts;
# FIXME: are these also required for clippy and doc?
nativeBuildInputs = (commonArgs.nativeBuildInputs or [ ]) ++ [
pkgs.sqlx-cli
];
preBuild = ''
export DATABASE_URL=sqlite:./db.sqlite3
sqlx database create
sqlx migrate run
'';
}
);
in
{
packages = {
inherit my-crate;
default = my-crate;
};
devShells.default = craneLib.devShell {
checks = self.checks.${system};
};
checks = {
inherit my-crate;
# Run clippy (and deny all warnings) on the crate source,
# again, reusing the dependency artifacts from above.
#
# Note that this is done as a separate derivation so that
# we can block the CI if there are issues here, but not
# prevent downstream consumers from building our crate by itself.
my-crate-clippy = craneLib.cargoClippy (
commonArgs
// {
inherit cargoArtifacts;
cargoClippyExtraArgs = "--all-targets -- --deny warnings";
}
);
my-crate-doc = craneLib.cargoDoc (
commonArgs
// {
inherit cargoArtifacts;
# This can be commented out or tweaked as necessary, e.g. set to
# `--deny rustdoc::broken-intra-doc-links` to only enforce that lint
env.RUSTDOCFLAGS = "--deny warnings";
}
);
# Check formatting
my-crate-fmt = craneLib.cargoFmt {
inherit src;
};
my-crate-toml-fmt = craneLib.taploFmt {
src = pkgs.lib.sources.sourceFilesBySuffices src [ ".toml" ];
# taplo arguments can be further customized below as needed
# taploExtraArgs = "--config ./taplo.toml";
};
# Audit licenses
my-crate-deny = craneLib.cargoDeny {
inherit src;
};
};
}
);
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working