cross-rs / cross

“Zero setup” cross compilation and “cross testing” of Rust crates
Apache License 2.0
6.79k stars 379 forks source link

Improper multi-line templating of pre-build configuration #1554

Open arthuro555 opened 2 months ago

arthuro555 commented 2 months ago

Checklist

Describe your issue

Using a multi-line string in Cross.toml's pre-build field causes $CROSS_DEB_ARCH to not be properly replaced with the current architecture.

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

armv7-unknown-linux-gnueabihf

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

What architecture is the host?

What container engine is cross using?

cross version

cross 0.2.5

Example

Here are two failing configurations:

[build]
pre-build = [
    "dpkg --add-architecture $CROSS_DEB_ARCH",
    "apt-get update",
    """apt-get --assume-yes --no-install-recommends install
    libssl-dev:$CROSS_DEB_ARCH
    libcairo2-dev:$CROSS_DEB_ARCH
    """,
]
[build]
pre-build = [
    "dpkg --add-architecture $CROSS_DEB_ARCH",
    "apt-get update",
    """apt-get --assume-yes --no-install-recommends install \
    libssl-dev:$CROSS_DEB_ARCH \
    libcairo2-dev:$CROSS_DEB_ARCH \
    """,
]

Here is an equivalent, working configuration using a simple string:

[build]
pre-build = [
    "dpkg --add-architecture $CROSS_DEB_ARCH",
    "apt-get update",
    "apt-get --assume-yes --no-install-recommends install libssl-dev:$CROSS_DEB_ARCH libcairo2-dev:$CROSS_DEB_ARCH",
]

Expected behavior:

# Functional
apt-get --assume-yes --no-install-recommends install
    libssl-dev:armhf
    libcairo2-dev:armhf

Current behavior:

# Errors: Unknown architecture
apt-get --assume-yes --no-install-recommends install
    libssl-dev:$CROSS_DEB_ARCH
    libcairo2-dev:$CROSS_DEB_ARCH

Additional information / notes

No response

Emilgardis commented 2 months ago

Interesting, this is how it's put into the Dockerfile

https://github.com/cross-rs/cross/blob/d8631fe4f4e8bb4c4b24417a35544857fb42ee22/src/docker/shared.rs#L169-L172

and I think the problem is a combination of how it's expanded in quotemarks and https://github.com/cross-rs/cross/blob/d8631fe4f4e8bb4c4b24417a35544857fb42ee22/src/docker/shared.rs#L180

will have to investigate