Skip to content
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

cross build --target x86_64-pc-windows-gnu fails #1445

Open
4 of 11 tasks
oscar6echo opened this issue Feb 12, 2024 · 19 comments
Open
4 of 11 tasks

cross build --target x86_64-pc-windows-gnu fails #1445

oscar6echo opened this issue Feb 12, 2024 · 19 comments

Comments

@oscar6echo
Copy link

Checklist

Describe your issue

I have a pyo3 lib that compiles fine in linux.

I wanted to cross compile to windows, so I did:

cross build --target x86_64-pc-windows-gnu

with the following context:

  • Cargo.toml
[package]
name = "pyo3-poker-eval"
version = "0.1.0"
edition = "2021"


[dependencies]
pyo3 = { version = "0.20.2", features = ["extension-module"] }
serde = { version = "1.0.196", features = ["derive"] }
serde-pyobject = { version = "0.2.0" }
poker_eval = { version = "0.1.0", features = ["serde"] }

[lib]
name = "_rust"
# needs to match the name of the function with the `[#pymodule]` attribute
path = "rust/lib.rs"
crate-type = ["cdylib"]

[profile.release]
strip = true
lto = true
codegen-units = 1
  • Cross.toml
[target.x86_64-pc-windows-gnu]
image = "cross-pyo3:x86_64-pc-windows-gnu"


[target.x86_64-pc-windows-gnu.env]
passthrough = [
    "RUST_DEBUG",
    "RUST_BACKTRACE",
    "RUST_LOG",
    "PYO3_CROSS_LIB_DIR=/opt/python/cp310-cp310/lib",
    "PYO3_CROSS_PYTHON_VERSION=3.10",
    # "DIST_EXTRA_CONFIG",
]
  • Dockerfile
FROM quay.io/pypa/manylinux_2_28_x86_64 AS manylinux

FROM ghcr.io/cross-rs/x86_64-pc-windows-gnu:edge

# download python version - https://github.com/indygreg/python-build-standalone/releases
ENV DATE=20240107
ENV VERSION=cpython-3.10.13
ENV URL_ASSET=https://github.com/indygreg/python-build-standalone/releases/download/$DATE/$VERSION+$DATE-x86_64-unknown-linux-gnu-install_only.tar.gz

RUN curl -L $URL_ASSET | tar -xz -C /usr/local

ENV PATH=/usr/local/python/bin:$PATH

COPY --from=manylinux /opt/_internal /opt/_internal
COPY --from=manylinux /opt/python /opt/python

RUN cp /usr/local/python/bin/python3 /usr/local/python/bin/python

RUN python3 -V
RUN python -V
  • Note that for a full context, there is also a pyproject.toml file - not necessary to reproduce:
[build-system]
requires = ["setuptools >= 69.0", "setuptools-rust >= 1.8", "wheel"]
build-backend = "setuptools.build_meta"


[project]
name = "pyo3-poker-eval"
version = "0.1.0"
authors = [{ name = "firstname lastname", email = "author@gmail.com" }]
description = "Poker eval library"
keywords = ["poker", "rust"]
license = { text = "MIT" }
readme = "README.md"
classifiers = [
    "Development Status :: 4 - Beta",
    "License :: OSI Approved :: MIT License",
    "Intended Audience :: Developers",
    "Programming Language :: Python :: 3",
    "Programming Language :: Python :: 3.10",
    "Programming Language :: Python :: 3.11",
    "Operating System :: POSIX",
    "Operating System :: MacOS :: MacOS X",
    "Operating System :: Microsoft :: Windows",
]
requires-python = ">=3.10"
dependencies = [
    # none
]

[project.optional-dependencies]
dev = ["pytest"]

[project.urls]
repository = "https://github.com/oscar6echo/pyo3-poker-eval.git"
# homepage = ""
# documentation = ""
# issues = ""
# changelog = ""


# [tool.setuptools.packages.find]
# where = ["."]
# include = ["*"]
# exclude = ["tests"]

[tool.setuptools]
packages = ["pyo3_poker_eval"]

# Cf. https://setuptools-rust.readthedocs.io/en/v1.1.2/reference.html
[[tool.setuptools-rust.ext-modules]]
# Private Rust extension module to be nested into the Python package
target = "pyo3_poker_eval._rust"
# IMPORTANT: build with --release -> large impact on speed
debug = false
# reduce wheel size
strip = "All"
# used for cross compile
# args = ...

And it fails with a very specific miss:

cross build --target x86_64-pc-windows-gnu         
   Compiling pyo3-poker-eval v0.1.0 (/project)
error: linking with `x86_64-w64-mingw32-gcc-posix` failed: exit status: 1
  |
  = note: LC_ALL="C" PATH="/rust/lib/rustlib/x86_64-unknown-linux-gnu/bin:/usr/local/python/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/rust/bin" VSLANG="1033" "x86_64-w64-mingw32-gcc-posix" "-Wl,/tmp/rustcqa15dX/list.def" "-fno-use-linker-plugin" "-Wl,--dynamicbase" "-Wl,--disable-auto-image-base" "-m64" "-Wl,--high-entropy-va" "/rust/lib/rustlib/x86_64-pc-windows-gnu/lib/rsbegin.o" "/tmp/rustcqa15dX/symbols.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.10wxfm37qgyfifw9.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.11fcft1udhftg0kg.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.13t6ffuyzl4nwjtv.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.143nteefwtw7jcgw.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.14geesjb5nt8t6hw.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.158pcnv4h5q8xsgs.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.1aki2rpugq70t05z.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.1cw377ptrlczian3.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.1d3ycic638i1ukla.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.1gpcn6iyea9ksqim.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.1h0txerctlkdgylx.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.1irbm8dxodxzoafg.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.1jpt60kg73ysaaje.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.1ls4f4utmpygh9b.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.1mwzht1wgtkevpuj.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.1pf54e6dnrdzm57x.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.1pzqvmlrv5j8srbb.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.1r0euvkdl8cofww2.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.1r8lsumgeq3tdl2l.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.1rcktkwuwhyrj49a.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.1rmymc4wpwkcyifn.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.1rtj4ofwjoetsb9s.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.1vcwedrsz603eq8h.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.1x7e2tgcz8px1p08.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.1xag9xcy1i8lby10.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.1xdr2mg30lyj37r6.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.214igsdn9zqjdkcb.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.22f20qfe966n3a0t.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.26q3ne4ook35e3da.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.29lqs5vr2su6029b.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.2agm1l1cdxf85o87.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.2ay0g1g66tjwl7n7.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.2b76reeyk7y9yzkp.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.2b9rrqtwet46771n.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.2dfmuhtah1416f8z.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.2f4f10d6xgmbdkwu.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.2fai9z5iamfgys5k.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.2j9rwrzpi7duc8o0.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.2jso62m4hcif5guq.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.2k2zyfqwncn5dmct.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.2mxgfhj0fpm6scaq.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.2prscyvnh7vq1arr.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.2tn66xum70yf43kd.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.2tph60tnx8mof6xf.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.2ufhe629zm0wbgok.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.2vpf0gn9083ehxwf.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.2za2gc8pyggpnr6c.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.2zw31m3iamxzwjjv.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.31iykyenbi54uc18.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.325q4ujao93fnwwb.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.32pqpfiey18upg8f.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.36jmd12ydd75hzad.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.37n0zgpk7cgznnle.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.39ab5vgqb1zl1qwl.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.3bz29k80v5ewhxth.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.3e5bbpy6fh8yygnm.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.3f1g6zcs92zn1v9t.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.3h7mie9e1pkrnjao.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.3jt3qytawqkwef41.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.3lh74mqt14k96cgx.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.3rhhjlbfcioud3cr.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.3ti9hgyca467prpq.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.3uih6q9bqa2t1p54.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.3vperrg3c7v0w7zs.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.3xak1astqsoh19k5.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.3xg9vp5s20xb2vod.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.3zmwmuk1n2bswgma.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.3zn547qxzo04v39u.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.408lpt6127usba77.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.41httixdtfrjyn25.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.42t0aegspra5q0qo.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.430rbs0n81gez5fq.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.454ofhzstaqvadp5.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.460xqcjtnp1tfd05.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.49ti17581m1rcj7w.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.4cfc8iyhgfonuras.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.4i63kuckvo2iv7y0.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.4isxjmazn3q9pkpx.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.4ji4cd97q4504pig.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.4jor1kshfi2kp77r.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.4nwjibg0pgcfenkq.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.4rzqg3ix7as1khmr.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.4sfkjd7b75q3td7t.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.4uu0t41ghxmfkcnq.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.4vyg1y0w5i2zsxis.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.4y7k2hi6zrzacn2.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.5213gr2k2mlcuigk.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.525uyssglrya7kb2.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.53ebd6ahwmqvn7dg.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.53leds8duhqyovor.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.5496d5zuvcppdkjw.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.56esy9hb1zu5jcqx.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.587zl75vz7we0os3.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.5975ejibswf6n48q.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.5kuftex6lkov90b.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.7g8gkfd1emle6qw.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.9guk9p04l61k7uf.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.amqt3axej2d9aqf.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.cc6faqrfqhpocv5.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.cysocvuwrgnawyv.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.e8ti4eqpwotmo35.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.gwymu49qnv2bd2x.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.hy1zr87ikivk0fr.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.jg38ajt919xmieh.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.joyyhsmk638o5a3.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.k0z55tw2hfks390.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.l71kekt97xzh17v.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.m9zlvtpgl500hdg.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.n8vpeyutbciarr5.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.obvvjkqiq2vj5k1.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.pzdy815o4r17aib.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.tpz7d83h3bhrs2.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.uew6iw5srk1wtt6.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.wn4hf19rt3lu5mi.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.wovmpbmkcmk58fr.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.wztx24tscvem81u.rcgu.o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.3l6wacw99y7t1i0v.rcgu.o" "-L" "/target/x86_64-pc-windows-gnu/debug/deps" "-L" "/target/debug/deps" "-L" "/cargo/registry/src/index.crates.io-6f17d22bba15001f/windows_x86_64_gnu-0.48.5/lib" "-L" "/opt/python/cp310-cp310/lib" "-L" "/rust/lib/rustlib/x86_64-pc-windows-gnu/lib" "-Wl,-Bstatic" "/target/x86_64-pc-windows-gnu/debug/deps/libserde_pyobject-4c42e4314c161f97.rlib" "/target/x86_64-pc-windows-gnu/debug/deps/libpoker_eval-c36b538208a4baba.rlib" "/target/x86_64-pc-windows-gnu/debug/deps/libnum_format-bec9f450a57c573a.rlib" "/target/x86_64-pc-windows-gnu/debug/deps/libitoa-2a360f6b8295e32e.rlib" "/target/x86_64-pc-windows-gnu/debug/deps/libarrayvec-5d9763c331538160.rlib" "/target/x86_64-pc-windows-gnu/debug/deps/libserde_big_array-2bc9456f902ae29b.rlib" "/target/x86_64-pc-windows-gnu/debug/deps/librand-6b9a43be3ab00fbb.rlib" "/target/x86_64-pc-windows-gnu/debug/deps/librand_chacha-142f3a8da597db40.rlib" "/target/x86_64-pc-windows-gnu/debug/deps/libppv_lite86-3c52499b92d74fa2.rlib" "/target/x86_64-pc-windows-gnu/debug/deps/librand_core-addcd20b9766fba3.rlib" "/target/x86_64-pc-windows-gnu/debug/deps/libgetrandom-d8b3cabee0a15a75.rlib" "/target/x86_64-pc-windows-gnu/debug/deps/libthiserror-78743b176776a071.rlib" "/target/x86_64-pc-windows-gnu/debug/deps/libserde-fdf1d2b71c87c06c.rlib" "/target/x86_64-pc-windows-gnu/debug/deps/libpyo3-6227715ee04b2b33.rlib" "/target/x86_64-pc-windows-gnu/debug/deps/libmemoffset-d5856625c1559773.rlib" "/target/x86_64-pc-windows-gnu/debug/deps/libparking_lot-e8fed4c6c64fa0f4.rlib" "/target/x86_64-pc-windows-gnu/debug/deps/libparking_lot_core-67d8989a90eb15c1.rlib" "/target/x86_64-pc-windows-gnu/debug/deps/libwindows_targets-d6cfc54fa21ccf49.rlib" "/target/x86_64-pc-windows-gnu/debug/deps/libcfg_if-8077ed9bff4860d7.rlib" "/target/x86_64-pc-windows-gnu/debug/deps/libsmallvec-2b18a3901389d67f.rlib" "/target/x86_64-pc-windows-gnu/debug/deps/liblock_api-8ed4e464d93b5b54.rlib" "/target/x86_64-pc-windows-gnu/debug/deps/libscopeguard-d6a6f8c981aa494e.rlib" "/target/x86_64-pc-windows-gnu/debug/deps/libpyo3_ffi-6d61411ef66516f3.rlib" "/target/x86_64-pc-windows-gnu/debug/deps/liblibc-89eda55cfee33f7c.rlib" "/target/x86_64-pc-windows-gnu/debug/deps/libunindent-39a0ac93858d00ff.rlib" "/rust/lib/rustlib/x86_64-pc-windows-gnu/lib/libstd-c39a33301a990d4c.rlib" "/rust/lib/rustlib/x86_64-pc-windows-gnu/lib/libpanic_unwind-cca52022a9e303e0.rlib" "/rust/lib/rustlib/x86_64-pc-windows-gnu/lib/libobject-87ab4ba6115beae7.rlib" "/rust/lib/rustlib/x86_64-pc-windows-gnu/lib/libmemchr-5cb7fa9a12663885.rlib" "/rust/lib/rustlib/x86_64-pc-windows-gnu/lib/libaddr2line-63721decd0530f88.rlib" "/rust/lib/rustlib/x86_64-pc-windows-gnu/lib/libgimli-f46ca0e8336ae9ce.rlib" "/rust/lib/rustlib/x86_64-pc-windows-gnu/lib/librustc_demangle-eb7f3864ed6b2a68.rlib" "/rust/lib/rustlib/x86_64-pc-windows-gnu/lib/libstd_detect-7a1913f37e63e841.rlib" "/rust/lib/rustlib/x86_64-pc-windows-gnu/lib/libhashbrown-bc9416be95f71206.rlib" "/rust/lib/rustlib/x86_64-pc-windows-gnu/lib/librustc_std_workspace_alloc-583427bdf1f371c2.rlib" "/rust/lib/rustlib/x86_64-pc-windows-gnu/lib/libminiz_oxide-cda0273dfc900176.rlib" "/rust/lib/rustlib/x86_64-pc-windows-gnu/lib/libadler-9e3a606a7eac348e.rlib" "/rust/lib/rustlib/x86_64-pc-windows-gnu/lib/libunwind-17b9231d7a9331b7.rlib" "/rust/lib/rustlib/x86_64-pc-windows-gnu/lib/libcfg_if-dcab4b455bc920a1.rlib" "/rust/lib/rustlib/x86_64-pc-windows-gnu/lib/liblibc-9852f6e85c86dae7.rlib" "/rust/lib/rustlib/x86_64-pc-windows-gnu/lib/liballoc-2b83ab5495098fa8.rlib" "/rust/lib/rustlib/x86_64-pc-windows-gnu/lib/librustc_std_workspace_core-baa2c1aeb27e5083.rlib" "/rust/lib/rustlib/x86_64-pc-windows-gnu/lib/libcore-b5f8c582e1776c2a.rlib" "/rust/lib/rustlib/x86_64-pc-windows-gnu/lib/libcompiler_builtins-d13d1e3b0b541614.rlib" "-Wl,-Bdynamic" "-lbcrypt" "-ladvapi32" "-lwindows.0.48.5" "-lpython310" "-lkernel32" "-ladvapi32" "-lbcrypt" "-lkernel32" "-lntdll" "-luserenv" "-lws2_32" "-lkernel32" "-lws2_32" "-lkernel32" "-lntdll" "-lkernel32" "-lgcc_eh" "-l:libpthread.a" "-lmsvcrt" "-lmingwex" "-lmingw32" "-lgcc" "-lmsvcrt" "-luser32" "-lkernel32" "-Wl,--nxcompat" "-L" "/rust/lib/rustlib/x86_64-pc-windows-gnu/lib" "-o" "/target/x86_64-pc-windows-gnu/debug/deps/_rust.dll" "-Wl,--gc-sections" "-shared" "-Wl,--out-implib=/target/x86_64-pc-windows-gnu/debug/deps/lib_rust.dll.a" "-nodefaultlibs" "/rust/lib/rustlib/x86_64-pc-windows-gnu/lib/rsend.o"
  = note: /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpython310
          collect2: error: ld returned 1 exit status
          
error: could not compile `pyo3-poker-eval` (lib) due to previous error

Note: I used the same cargo build --target x86_64-pc-windows-gnu on a a hello world project and it works fine.

Is this a bug ? Else what is missing to cross compile ?

What target(s) are you cross-compiling for?

No response

Which operating system is the host (e.g computer cross is on) running?

  • macOS
  • Windows
  • Linux / BSD
  • other OS (specify in description)

What architecture is the host?

  • x86_64 / AMD64
  • arm32
  • arm64 (including Mac M1)

What container engine is cross using?

  • docker
  • podman
  • other container engine (specify in description)

cross version

cross 0.2.5

Example

See above

Additional information / notes

Hopefully this is enough info.

@oscar6echo oscar6echo changed the title cross build --target x86_64-pc-windows-gnu fails with " /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpython310" cross build --target x86_64-pc-windows-gnu fails Feb 12, 2024
@oscar6echo oscar6echo changed the title cross build --target x86_64-pc-windows-gnu fails cross build --target x86_64-pc-windows-gnu fails Feb 12, 2024
@Emilgardis
Copy link
Member

There's a lot happening here.

Is libpython310 actually in scope for mingw to find it?

@oscar6echo
Copy link
Author

When you say 'in scope', you mean in the docker container meant to do the build or the host ?

I would expect you mean in the container, right ? But then I don't really know the image. is mostly derived from a cross-rs image.
How would you check precisely ?

The host is a Ubuntu without any knowledge about anything windows...

@Emilgardis
Copy link
Member

I mean that the library needs to be accessible in /usr/x86_64-w64-mingw32 or another included library

I see that -L/opt/python/cp310-cp310/lib is passed. Does python310 exist there? is that library suitable for w64-mingw32? You can't use a library compiled for another target

@oscar6echo
Copy link
Author

From inside the container.:

root@45d1a52cf28c:/# ls -al  /opt/python/cp310-cp310
lrwxrwxrwx 1 root root 30 Feb  8 18:54 /opt/python/cp310-cp310 -> /opt/_internal/cpython-3.10.13
root@45d1a52cf28c:/# ls -al /opt/_internal/cpython-3.10.13
total 24
drwxr-xr-x  6 root root 4096 Feb  8 18:54 .
drwxr-xr-x 16 root root 4096 Feb  8 18:55 ..
drwxr-xr-x  2 root root 4096 Feb  8 18:55 bin
drwxr-xr-x  3 root root 4096 Feb  8 18:54 include
drwxr-xr-x  4 root root 4096 Feb  8 18:54 lib
drwxr-xr-x  3 root root 4096 Feb  8 18:54 share
root@45d1a52cf28c:/# ls -al /opt/_internal/cpython-3.10.13/lib
total 16
drwxr-xr-x  4 root root 4096 Feb  8 18:54 .
drwxr-xr-x  6 root root 4096 Feb  8 18:54 ..
drwxr-xr-x  2 root root 4096 Feb  8 18:54 pkgconfig
drwxr-xr-x 36 root root 4096 Feb  8 18:55 python3.10
root@45d1a52cf28c:/# 

So yes py310 is installed.

It was downloaded from https://github.com/indygreg/python-build-standalone/releases
This .tar.gz exactly: cpython-3.10.13+20240107-x86_64-unknown-linux-gnu-install_only.

Is it correct ? I guess not because it breaks.
Then which one should it be ?
Maybe this one: cpython-3.10.13+20240107-x86_64-pc-windows-msvc-shared-install_only.tar.gz ?

@Emilgardis
Copy link
Member

You need a mingw python, so no

See indygreg/python-build-standalone#14 for that source

https://packages.msys2.org/package/mingw-w64-x86_64-python?repo=mingw64 has what you want I think.

python-3.10.10

@oscar6echo
Copy link
Author

Ok I found the image and put it inside the container but it's getting increasingly confusing, actually.

I can download and put a mingw64 distrib, say the latest 3.10 in the container.

Then I see:

root@5b5dd9bea925:/usr/local/mingw64# ls -al bin
total 3792
drwxr-xr-x 2 root root    4096 Jun 14  2023 .
drwxr-xr-x 6 root root    4096 Jun 14  2023 ..
-rwxr-xr-x 1 root root     104 Jun 14  2023 2to3
-rwxr-xr-x 1 root root     104 Jun 14  2023 2to3-3.10
-rwxr-xr-x 1 root root     102 Jun 14  2023 idle
-rwxr-xr-x 1 root root     102 Jun 14  2023 idle3
-rwxr-xr-x 1 root root     102 Jun 14  2023 idle3.10
-rwxr-xr-x 1 root root 3323336 Jun 14  2023 libpython3.10.dll
-rwxr-xr-x 1 root root      87 Jun 14  2023 pydoc
-rwxr-xr-x 1 root root      87 Jun 14  2023 pydoc3
-rwxr-xr-x 1 root root      87 Jun 14  2023 pydoc3.10
-rwxr-xr-x 1 root root    3776 Jun 14  2023 python-config
-rwxr-xr-x 1 root root   99407 Jun 14  2023 python.exe
-rwxr-xr-x 1 root root    3776 Jun 14  2023 python3-config
-rwxr-xr-x 1 root root    3776 Jun 14  2023 python3.10-config
-rwxr-xr-x 1 root root   99407 Jun 14  2023 python3.10.exe
-rwxr-xr-x 1 root root   99407 Jun 14  2023 python3.exe
-rwxr-xr-x 1 root root   97871 Jun 14  2023 python3w.exe
-rwxr-xr-x 1 root root   97871 Jun 14  2023 pythonw.exe
root@5b5dd9bea925:/usr/local/mingw64# 

But it's python.exe in a linux container. Then of course python is not found:

# inside container:
root@5b5dd9bea925:/usr/local/mingw64# echo $PATH 
/usr/local/mingw64/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
root@5b5dd9bea925:/usr/local/mingw64# which python
root@5b5dd9bea925:/usr/local/mingw64# 

And the cross build using this container will work even less..

I'm a bit lost in fact.

I started from this image used in this ci.yml, recommended by setuptools-rust in their doc.

Working from there i was trying to adapt the docker file for a cross compile to windows.
But I do not understand how this may work using windows .exe in a container ! 🤔

Note: Generally I think having a working example connecting pyo3/setuptools enabling to cross compile to windows (which seems to be trickier than linux to linux) would be useful. The info is maybe there, though I have not found it yet, but quite disseminated.

@Emilgardis
Copy link
Member

Emilgardis commented Feb 12, 2024

why do you need a python.exe? if python is needed, just install it, shouldn't have to be a .exe.

now, lib/libpython3.10.dll.a should exist in a place where the cross-compiler/linker (x86_64-w64-mingw32-gcc-posix) can find it. Does it find it? What error do you get?

@oscar6echo
Copy link
Author

why do you need a python.exe? if python is needed, just install it, shouldn't have to be a .exe.

I just unpacked the mingw64 python distrib dowloaded.

But now I only keep the dll and put it in the path.
And keep the initial python: cpython-3.10.13+20240107-x86_64-unknown-linux-gnu-install_only.

Which gives the following, with /usr/local/python/bin in PATH:

#12 [stage-1  7/10] RUN ls -al /usr/local/python/bin
#12 0.264 total 1152
#12 0.264 drwxr-xr-x 1 root root    4096 Feb 13 00:10 .
#12 0.264 drwxr-xr-x 1 root root    4096 Feb 12 23:59 ..
#12 0.264 lrwxrwxrwx 1 root root       9 Jan  1  2021 2to3 -> 2to3-3.10
#12 0.264 -rwxrwxr-x 1 root root     128 Jan  1  2021 2to3-3.10
#12 0.264 lrwxrwxrwx 1 root root       8 Jan  1  2021 idle3 -> idle3.10
#12 0.264 -rwxrwxr-x 1 root root     126 Jan  1  2021 idle3.10
#12 0.264 -rw-r--r-- 1 root root 1110920 Feb 13 00:10 libpython3.10.dll.a
#12 0.264 -rwxrwxr-x 1 root root     256 Jan  1  2021 pip
#12 0.264 -rwxrwxr-x 1 root root     256 Jan  1  2021 pip3
#12 0.264 -rwxrwxr-x 1 root root     256 Jan  1  2021 pip3.10
#12 0.264 lrwxrwxrwx 1 root root       9 Jan  1  2021 pydoc3 -> pydoc3.10
#12 0.264 -rwxrwxr-x 1 root root     111 Jan  1  2021 pydoc3.10
#12 0.264 lrwxrwxrwx 1 root root      10 Jan  1  2021 python3 -> python3.10
#12 0.264 lrwxrwxrwx 1 root root      17 Jan  1  2021 python3-config -> python3.10-config
#12 0.264 -rwxrwxr-x 1 root root   20944 Jan  1  2021 python3.10
#12 0.264 -rwxrwxr-x 1 root root    3093 Jan  1  2021 python3.10-config
#12 DONE 0.3s

Then i get the same error:

cross build --target x86_64-pc-windows-gnu
   Compiling pyo3-poker-eval v0.1.0 (/project)
error: linking with `x86_64-w64-mingw32-gcc-posix` failed: exit status: 1
  |
(...)
= note: /usr/bin/x86_64-w64-mingw32-ld: cannot find -lpython310
          collect2: error: ld returned 1 exit status

Is there a Dockerfile that is tested to perform such cross compile from linux to win ?
Or is it expected that users create one per project ?

Here is the current Dockerfile:

FROM ghcr.io/cross-rs/x86_64-pc-windows-gnu:edge

RUN apt install zstd -y 

# download python version - https://github.com/indygreg/python-build-standalone/releases
ENV DATE=20240107
ENV VERSION=cpython-3.10.13
ENV URL_ASSET=https://github.com/indygreg/python-build-standalone/releases/download/$DATE/$VERSION+$DATE-x86_64-unknown-linux-gnu-install_only.tar.gz


RUN curl -L $URL_ASSET | tar -xz -C /usr/local
RUN ls -al /usr/local


ENV URL_ASSET=https://repo.msys2.org/mingw/mingw64/mingw-w64-x86_64-python-3.10.12-1-any.pkg.tar.zst
RUN curl $URL_ASSET > /tmp/pkg.tar.zst && \
    tar -axvf /tmp/pkg.tar.zst -C /tmp && \
    rm /tmp/pkg.tar.zst 

RUN cp /tmp/mingw64/lib/libpython3.10.dll.a /usr/local/python/bin/


RUN ls -al /usr/local/python/bin

ENV PATH=/usr/local/python/bin:$PATH

RUN python3 -V

How would you go about debugging this ?

@Emilgardis
Copy link
Member

Put it in /usr/x86_64-w64-mingw32

@Emilgardis
Copy link
Member

Excuse me if my answers are short also, if you're not able to solve this soon I'll try to reproduce it myself and see what's wrong!

@oscar6echo
Copy link
Author

oscar6echo commented Feb 13, 2024

Put it in /usr/x86_64-w64-mingw32

It turns out I had to put it in /lib below and change its name:

ENV URL_ASSET=https://repo.msys2.org/mingw/mingw64/mingw-w64-x86_64-python-3.10.12-1-any.pkg.tar.zst

RUN curl $URL_ASSET > /tmp/pkg.tar.zst && \
    tar -axvf /tmp/pkg.tar.zst -C /tmp && \
    cp /tmp/mingw64/lib/libpython3.10.dll.a /usr/x86_64-w64-mingw32/lib/libpython310.dll.a && \
    rm /tmp/pkg.tar.zst && \
    rm -rf /tmp/mingw64

Then in container - to be sure:

docker run --rm --name cross -it cross-pyo3:x86_64-pc-windows-gnu   /bin/bash
root@9e2b18f2f5c2:/# cd /tmp
root@9e2b18f2f5c2:/tmp# ls
home  wine
root@9e2b18f2f5c2:/tmp# cd /usr/x86_64-w64-mingw32/lib
root@9e2b18f2f5c2:/usr/x86_64-w64-mingw32/lib# ls -al | grep python
-rw-r--r-- 1 root root 1110920 Feb 13 08:11 libpython310.dll.a
root@9e2b18f2f5c2:/usr/x86_64-w64-mingw32/lib# 

Then it works - or at least does not break - could not test wheel produced yet - as cross is part of the build managed by python -m build configured by the pyproject.toml file above in the conversation.

Excuse me if my answers are short also, if you're not able to solve this soon I'll try to reproduce it myself and see what's wrong!

You're all excused ! On the contrary, your help is both swift and critical 👍
With a bit of dichotomy the issue could be solved.

BUT:

I still think the doc lags in this respect: Unless I missed the relevant section, it does not cover this tricky "linux2win" cross compile config. I am willing to help document it (while it's hot in my mind). Do you think it's a good idea ? If so where would you see this addition ? Assuming it was written, it could then be linked from this pyo3 doc cross compile section. At the bottom there is a link to cross-rs/cross which is how I landed here in the first place.

EDIT:
Then after some search I found this ci.yml which is meant to be the doc for how to use cross in setuptools-rust. But it was also a bit misleading as the multistage Dockerfile eventually proved superfluous in my case (unless again I miss something).

@Emilgardis
Copy link
Member

Yes, I think documenting it is a good idea. We are currently however reworking the docs a bit, see #1438. The place to put it would be in the wiki or when that pr is merged in the docs folder.

I have #1357 planned to improve the situation a bit. For now though, feel free to add to https://github.com/cross-rs/wiki_assets/tree/main/Recipes where we can then incorporate it

@oscar6echo
Copy link
Author

Ok I will try to add a minimalistic example in a folder in the wiki recipes.

In the meantime, the repo from which the above is taken is oscar6echo/pyo3-poker-eval.

@oscar6echo
Copy link
Author

NOTE:
In addition to the cross compile to windows discussed above, I added a build to manylinux in repo oscar6echo/pyo3-poker-eval. Otherwise I cannot push to pypi.

For that I used a manylinux container.
Could cross do it also ? or is it out of scope ?

@Emilgardis
Copy link
Member

I'm not sure I follow, what would cross possibly be able to help with here?

@oscar6echo
Copy link
Author

Well nothing I reckon now 🤔
Indeed this manylinux is about the python wheel, which happens to contain a rust module, so this is orthogonal to what cross does.

Sorry for the noise - and thx again for the alway fast replies 🙏
Hopefully, if somebody else has the same confused thoughts, this issue will help clear them !

@oscar6echo
Copy link
Author

I revisit this conversation because I have a similar case and reach an unexpected runtime error...

I can create a wheel using this reproduceable procedure.

I run it from ubuntu and expect to produce a wheel for windows, which I do.

Everything ends up without error:

image

And the wheel is in dist folder:

image

But on Windows10, it crashes at runtime:

polars.exception.ComputeError: error loading dynamic library: LoadLibrryExW failed

Somehow the building was not good.
I have very limited understanding of what cross does in particular with a docker image like this one:

FROM ghcr.io/cross-rs/x86_64-pc-windows-gnu:edge
# FROM ghcr.io/cross-rs/x86_64-pc-windows-gnu:0.2.5

# download linux python - https://github.com/indygreg/python-build-standalone/releases
# make it system python
# latest as of 6nov24
ENV DATE=20241016
# latest 3.10 as of 6nov24
ENV VERSION=cpython-3.10.15
# ENV VERSION=cpython-3.10.13
ENV URL_ASSET=https://github.com/indygreg/python-build-standalone/releases/download/$DATE/$VERSION+$DATE-x86_64-unknown-linux-gnu-install_only.tar.gz

RUN apt install zstd -y && \
    curl -L $URL_ASSET | tar -xz -C /usr/local

# download mingw64 python - https://repo.msys2.org/mingw/mingw64/
# keep only dll
# latest 3.10 as of 6nov24
ENV URL_ASSET=https://repo.msys2.org/mingw/mingw64/mingw-w64-x86_64-python-3.10.12-1-any.pkg.tar.zst

# debug cf issue https://github.com/cross-rs/cross/issues/1445
RUN curl $URL_ASSET > /tmp/pkg.tar.zst && \
    tar -axvf /tmp/pkg.tar.zst -C /tmp && \
    cp /tmp/mingw64/lib/libpython3.10.dll.a /usr/x86_64-w64-mingw32/lib/libpython310.dll.a && \
    cp /usr/x86_64-w64-mingw32/lib/libpython310.dll.a /usr/x86_64-w64-mingw32/lib/libpython3.dll.a && \
    rm /tmp/pkg.tar.zst && \
    rm -rf /tmp/mingw64

ENV PATH=/usr/local/python/bin:$PATH

How would you go about debugging ??
Is there any working example to use cross to build a win wheel on a linux machine ?

@oscar6echo
Copy link
Author

I am investingating a higher level route to cross compile to win, using maturin.
In short:

# ------- build windows wheel
# debian & co
sudo apt-get install mingw-w64
# redhat & co
sudo dnf install mingw64-gcc

maturin build --release --target x86_64-pc-windows-gnu --out dist

Should be able to test soon and hopefully close the issue.

@oscar6echo
Copy link
Author

It works with maturin.

There was a specific issue with lib polars. Cf. discussion.

The method described previously was working just the same in fact.

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

No branches or pull requests

2 participants