cross
cross copied to clipboard
Port Forwarding / Accessing a host port during build
I am using sqlx which requires a connection to my local postgres db at build time. Is it possible to port forward postgres into the cross container or alternatively is there an environment variable to get the IP address of the host from the container?
Related: conversation about removing this build-time network dependency in sqlx: https://github.com/launchbadge/sqlx/issues/60#issuecomment-586634589
I faced the same issue. In the meantime there's no fix for this, i figured a workaround using a couple docker containers.
This one to emulate an architecture with qemu, allowing to run containers meant for different architectures, like this one with the same arch as the Raspberry PI 2/3
(you may need to setup a docker network to access the sql server, but it depends on your setup)
You can then run the container, install rust and whatever dependencies you may need, and just use cargo build
like normal to compile the application.
Using this method takes way longer to compile the application, but that's expected given it's emulating an architecture.
That is very interesting. I'll look into these. Docker buildx might be another potential avenue to achieve a very similar result. I would love to see a docker-inside-qemu solution like this baked into cross some day.
We now pre-ship containers with cross installed, such as ghcr.io/cross-rs/cross:main
. This might make it a bit simpler. I'll see if I can get port forwarding to work, however.
using CROSS_CONTAINER_OPTS="--network host"
should solve this without needing dind
sqlx also has support for offline building via offline
feature flag