cross icon indicating copy to clipboard operation
cross copied to clipboard

Improper multi-line templating of pre-build configuration

Open arthuro555 opened this issue 1 year ago • 1 comments

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?

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

What architecture is the host?

  • [X] x86_64 / AMD64
  • [ ] arm32
  • [ ] arm64 (including Mac M1)

What container engine is cross using?

  • [X] docker
  • [ ] podman
  • [ ] other container engine (specify in description)

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

arthuro555 avatar Sep 04 '24 12:09 arthuro555

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

Emilgardis avatar Sep 04 '24 12:09 Emilgardis