Repository: cross-rs/cross
Pull request #1201 (2023-02-03 22:19:44)

Release v0.2.5
See https://github.com/cross-rs/cross/pull/962#issuecomment-1367088316

includes

ee3c9724582ee0201c61b3c3a5c83b0643ad26d4 #962
fc3df661a701f8b502883555cab570c31479ac03 #1166
33ee9403c891417fdcd08110e094e2eb3581b61d in #997
81c1e59addeb17c7705187541547e3d392481e98 #950
6a57d01bea09dae71e30e1be9e31e37918417411 #1183

Emilgardis: related #1053 
Emilgardis: 7d593d77a1fb13d3b82ccc8fde335dc633cc69a8
6983a921debadf027d4edcd1ee8dc5707bc6d466

the changeset file has to be removed also for #962 

needs to be applied to main after this has been merged
Emilgardis: wonder if this works

bors try
Emilgardis: bors cancel

bors try
bors[bot]: ## try

Already running a review
Emilgardis: bors try-

bors try
Emilgardis: Hmm, cache is not working as expected, might have to hack this a bit and just make it rename 0.2.4 as 0.2.5
Emilgardis: bors try-

bors try
bors[bot]: ## try

Build failed:
  * [conclusion](https://github.com/cross-rs/cross/actions/runs/4088851526/jobs/7051164155)
Emilgardis: bors try
bors[bot]: ## try

Build failed:
  * [conclusion](https://github.com/cross-rs/cross/actions/runs/4089070331/jobs/7052239786)
Emilgardis: bors try
bors[bot]: ## try

Build failed:
  * [conclusion](https://github.com/cross-rs/cross/actions/runs/4090935480/jobs/7055122844)
Emilgardis: bors try

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 55b47a6..aa0c4b0 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,14 @@ This project adheres to [Semantic Versioning](http://semver.org/).
 
 ## [Unreleased] - ReleaseDate
 
+## [v0.2.5] - 2023-02-04
+
+## Fixed
+
+- #962 - fix SELinux labels to allow use in multiple containers and/or the host filesystem.
+- #1166 - freebsd: include memstat in build image to fix build with libc 0.2.138 and up.
+- #1183 - resolve issue when using `pre-build` in `Cargo.toml`
+
 ## [v0.2.4] - 2022-07-10
 
 ## Fixed
@@ -364,7 +372,9 @@ This project adheres to [Semantic Versioning](http://semver.org/).
 <!-- prettier-ignore-start -->
 <!-- next-url -->
 
-[Unreleased]: https://github.com/cross-rs/cross/compare/v0.2.4...HEAD
+[Unreleased]: https://github.com/cross-rs/cross/compare/v0.2.5...HEAD
+
+[v0.2.5]: https://github.com/cross-rs/cross/compare/v0.2.4...v0.2.5
 
 [v0.2.4]: https://github.com/cross-rs/cross/compare/v0.2.3...v0.2.4
 
diff --git a/Cargo.lock b/Cargo.lock
index 0ca6781..a95faa1 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -150,7 +150,7 @@ checksum = "fb58b6451e8c2a812ad979ed1d83378caa5e927eef2622017a45f251457c2c9d"
 
 [[package]]
 name = "cross"
-version = "0.2.4"
+version = "0.2.5"
 dependencies = [
  "atty",
  "clap",
diff --git a/Cargo.toml b/Cargo.toml
index 10eeeb0..d2c8f7b 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -6,7 +6,7 @@ keywords = ["cross", "compilation", "testing", "tool"]
 license = "MIT OR Apache-2.0"
 name = "cross"
 repository = "https://github.com/cross-rs/cross"
-version = "0.2.4"
+version = "0.2.5"
 edition = "2021"
 include = [
   "src/**/*",
@@ -66,7 +66,6 @@ once_cell = "1"
 walkdir = "2"
 
 [package.metadata.release]
-dev-version = false
 push = false
 publish = false
 tag = false
diff --git a/Dockerfile.hack b/Dockerfile.hack
new file mode 100644
index 0000000..664ab56
--- /dev/null
+++ b/Dockerfile.hack
@@ -0,0 +1,2 @@
+ARG CROSS_IMAGE
+FROM $CROSS_IMAGE
\ No newline at end of file
diff --git a/deny.toml b/deny.toml
index 3f77553..b51d773 100644
--- a/deny.toml
+++ b/deny.toml
@@ -12,7 +12,7 @@ vulnerability = "deny"
 unmaintained = "deny"
 notice = "deny"
 unsound = "deny"
-ignore = []
+ignore = ["RUSTSEC-2021-0145"]
 
 [bans]
 multiple-versions = "deny"
diff --git a/docker/Dockerfile.i686-unknown-freebsd b/docker/Dockerfile.i686-unknown-freebsd
index af4600a..37ea6e7 100644
--- a/docker/Dockerfile.i686-unknown-freebsd
+++ b/docker/Dockerfile.i686-unknown-freebsd
@@ -10,12 +10,14 @@ RUN /cmake.sh
 COPY xargo.sh /
 RUN /xargo.sh
 
+RUN echo "export ARCH=i686" > /freebsd-arch.sh
 COPY freebsd-common.sh /
 COPY freebsd.sh /
-RUN /freebsd.sh i686
+RUN /freebsd.sh
 
+COPY freebsd-install.sh /
 COPY freebsd-extras.sh /
-RUN /freebsd-extras.sh i686
+RUN /freebsd-extras.sh
 
 ENV CARGO_TARGET_I686_UNKNOWN_FREEBSD_LINKER=i686-unknown-freebsd12-gcc \
     CC_i686_unknown_freebsd=i686-unknown-freebsd12-gcc \
diff --git a/docker/Dockerfile.x86_64-unknown-freebsd b/docker/Dockerfile.x86_64-unknown-freebsd
index 4f53fb2..239628f 100644
--- a/docker/Dockerfile.x86_64-unknown-freebsd
+++ b/docker/Dockerfile.x86_64-unknown-freebsd
@@ -10,12 +10,14 @@ RUN /cmake.sh
 COPY xargo.sh /
 RUN /xargo.sh
 
+RUN echo "export ARCH=x86_64" > /freebsd-arch.sh
 COPY freebsd-common.sh /
 COPY freebsd.sh /
-RUN /freebsd.sh x86_64
+RUN /freebsd.sh
 
+COPY freebsd-install.sh /
 COPY freebsd-extras.sh /
-RUN /freebsd-extras.sh x86_64
+RUN /freebsd-extras.sh
 
 ENV CARGO_TARGET_X86_64_UNKNOWN_FREEBSD_LINKER=x86_64-unknown-freebsd12-gcc \
     CC_x86_64_unknown_freebsd=x86_64-unknown-freebsd12-gcc \
diff --git a/docker/dragonfly.sh b/docker/dragonfly.sh
index 167aff4..d53ac1a 100755
--- a/docker/dragonfly.sh
+++ b/docker/dragonfly.sh
@@ -105,7 +105,7 @@ EOF
     cp "${td}/dragonfly/usr/lib/libexecinfo.so.1" "${destdir}/lib"
     cp "${td}/dragonfly/usr/lib/libpthread.so" "${destdir}/lib/libpthread.so"
     cp "${td}/dragonfly/usr/lib/librt.so.0" "${destdir}/lib"
-    cp "${td}"/dragonfly/usr/lib/lib{c,m,util}.a "${destdir}/lib"
+    cp "${td}"/dragonfly/usr/lib/lib{c,m,util,kvm}.a "${destdir}/lib"
     cp "${td}/dragonfly/usr/lib/thread/libthread_xu.so.2" "${destdir}/lib/libpthread.so.0"
     cp "${td}"/dragonfly/usr/lib/{crt1,Scrt1,crti,crtn}.o "${destdir}/lib/"
 
diff --git a/docker/freebsd-common.sh b/docker/freebsd-common.sh
index 514ff52..a5af3fa 100755
--- a/docker/freebsd-common.sh
+++ b/docker/freebsd-common.sh
@@ -3,6 +3,9 @@
 set -x
 set -euo pipefail
 
+# shellcheck disable=SC1091
+. freebsd-arch.sh
+
 export BSD_ARCH=
 case "${ARCH}" in
     x86_64)
diff --git a/docker/freebsd-extras.sh b/docker/freebsd-extras.sh
index c3f4f23..e1d4146 100755
--- a/docker/freebsd-extras.sh
+++ b/docker/freebsd-extras.sh
@@ -3,55 +3,17 @@
 set -x
 set -euo pipefail
 
-export ARCH="${1}"
 # shellcheck disable=SC1091
 . lib.sh
 # shellcheck disable=SC1091
 . freebsd-common.sh
+# shellcheck disable=SC1091
+. freebsd-install.sh
 
 main() {
-    local pkg_source="https://pkg.freebsd.org/FreeBSD:${BSD_MAJOR}:${BSD_ARCH}/quarterly"
-    install_packages curl jq xz-utils
-
-    local td
-    td="$(mktemp -d)"
-
-    mkdir "${td}"/{openssl,sqlite,packagesite}
-
-    pushd "${td}"
-
-    curl --retry 3 -sSfL "${pkg_source}/packagesite.txz" -O
-    tar -C "${td}/packagesite" -xJf packagesite.txz
-    local openssl_ver
-    local sqlite_ver
-    openssl_ver=$(jq -c '. | select ( .name == "openssl" ) | .version' "${td}/packagesite/packagesite.yaml")
-    sqlite_ver=$(jq -c '. | select ( .name == "sqlite3" ) | .version' "${td}/packagesite/packagesite.yaml")
-    openssl_ver=${openssl_ver//'"'/}
-    sqlite_ver=${sqlite_ver//'"'/}
-
-    local target="${ARCH}-unknown-freebsd${BSD_MAJOR}"
-
-    # Adding openssl lib
-    curl --retry 3 -sSfL "${pkg_source}/All/openssl-${openssl_ver}.txz" -O
-    tar -C "${td}/openssl" -xJf "openssl-${openssl_ver}.txz" /usr/local/lib /usr/local/include/
-
-    # Adding sqlite3
-    curl --retry 3 -sSfL "${pkg_source}/All/sqlite3-${sqlite_ver}.txz" -O
-    tar -C "${td}/sqlite" -xJf "sqlite3-${sqlite_ver}.txz" /usr/local/lib
-
-    # Copy the linked library
-    local destdir="/usr/local/${target}"
-    cp -r "${td}/openssl/usr/local/include" "${destdir}"
-    cp "${td}/openssl/usr/local/lib"/lib{crypto,ssl}.a "${destdir}/lib"
-    cp "${td}/openssl/usr/local/lib"/lib{crypto,ssl}.so* "${destdir}/lib"
-    cp "${td}/sqlite/usr/local/lib"/libsqlite3.so* "${destdir}/lib"
-
-    purge_packages
-
-    # clean up
-    popd
+    setup_packagesite
+    install_freebsd_package openssl sqlite3
 
-    rm -rf "${td}"
     rm "${0}"
 }
 
diff --git a/docker/freebsd-install.sh b/docker/freebsd-install.sh
new file mode 100755
index 0000000..dba0d1d
--- /dev/null
+++ b/docker/freebsd-install.sh
@@ -0,0 +1,57 @@
+#!/usr/bin/env bash
+
+set -x
+set -euo pipefail
+
+# shellcheck disable=SC1091
+. freebsd-common.sh
+
+export PACKAGESITE=/opt/freebsd-packagesite/packagesite.yaml
+export PKG_SOURCE="https://pkg.freebsd.org/FreeBSD:${BSD_MAJOR}:${BSD_ARCH}/quarterly"
+export TARGET="${ARCH}-unknown-freebsd${BSD_MAJOR}"
+
+setup_packagesite() {
+    apt-get update && apt-get install --assume-yes --no-install-recommends \
+        curl \
+        jq \
+        xz-utils
+
+    mkdir /opt/freebsd-packagesite
+    curl --retry 3 -sSfL "${PKG_SOURCE}/packagesite.txz" -O
+    tar -C /opt/freebsd-packagesite -xJf packagesite.txz
+
+    rm packagesite.txz
+}
+
+install_freebsd_package() {
+    local name
+    local path
+    local pkg
+    local td
+    local destdir="/usr/local/${TARGET}"
+
+    td="$(mktemp -d)"
+    pushd "${td}"
+
+    for name in "${@}"; do
+        path=$(jq -c '. | select ( .name == "'"${name}"'" ) | .repopath' "${PACKAGESITE}")
+        if [[ -z "${path}" ]]; then
+            echo "Unable to find package ${name}" >&2
+            exit 1
+        fi
+        path=${path//'"'/}
+        pkg=$(basename "${path}")
+
+        mkdir "${td}"/package
+        curl --retry 3 -sSfL "${PKG_SOURCE}/${path}" -O
+        tar -C "${td}/package" -xJf "${pkg}"
+        cp -r "${td}/package/usr/local"/* "${destdir}"/
+
+        rm "${td:?}/${pkg}"
+        rm -rf "${td:?}/package"
+    done
+
+    # clean up
+    popd
+    rm -rf "${td:?}"
+}
diff --git a/docker/freebsd.sh b/docker/freebsd.sh
index e351bd3..94f023b 100755
--- a/docker/freebsd.sh
+++ b/docker/freebsd.sh
@@ -3,7 +3,6 @@
 set -x
 set -euo pipefail
 
-export ARCH="${1}"
 # shellcheck disable=SC1091
 . freebsd-common.sh
 # shellcheck disable=SC1091
@@ -96,8 +95,9 @@ main() {
     cp "${td}/freebsd/lib/libdevstat.so.7" "${destdir}/lib"
     cp "${td}/freebsd/usr/lib/libc++.so.1" "${destdir}/lib"
     cp "${td}/freebsd/usr/lib/libc++.a" "${destdir}/lib"
-    cp "${td}/freebsd/usr/lib"/lib{c,util,m,ssp_nonshared}.a "${destdir}/lib"
+    cp "${td}/freebsd/usr/lib"/lib{c,util,m,ssp_nonshared,memstat}.a "${destdir}/lib"
     cp "${td}/freebsd/usr/lib"/lib{rt,execinfo,procstat}.so.1 "${destdir}/lib"
+    cp "${td}/freebsd/usr/lib"/libmemstat.so.3 "${destdir}/lib"
     cp "${td}/freebsd/usr/lib"/{crt1,Scrt1,crti,crtn}.o "${destdir}/lib"
     cp "${td}/freebsd/usr/lib"/libkvm.a "${destdir}/lib"
 
diff --git a/src/cross_toml.rs b/src/cross_toml.rs
index 819143f..3804622 100644
--- a/src/cross_toml.rs
+++ b/src/cross_toml.rs
@@ -680,6 +680,28 @@ mod tests {
         Ok(())
     }
 
+    #[test]
+    pub fn fully_populated_roundtrip() -> Result<()> {
+        let cfg = r#"
+            [target.a]
+            xargo = false
+            build-std = true
+            image = "local"
+            dockerfile.file = "Dockerfile"
+            dockerfile.context = ".."
+            pre-build = ["sh"]
+            zig = true
+
+            [target.b]
+            pre-build = "sh"
+            zig = "2.17"
+        "#;
+
+        let (cfg, _) = CrossToml::parse_from_cross(cfg, &mut m!())?;
+        serde_json::from_value::<CrossToml>(serde_json::to_value(cfg)?)?;
+        Ok(())
+    }
+
     #[test]
     pub fn merge() -> Result<()> {
         let cfg1_str = r#"
diff --git a/src/docker/custom.rs b/src/docker/custom.rs
index 31e2df6..780247d 100644
--- a/src/docker/custom.rs
+++ b/src/docker/custom.rs
@@ -23,7 +23,7 @@ pub enum Dockerfile<'a> {
     },
 }
 
-#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
+#[derive(Debug, Clone, PartialEq, Eq, serde::Deserialize)]
 pub enum PreBuild {
     /// A path to a file to copy or a single line to `RUN` if line comes from env
     Single { line: String, env: bool },
@@ -31,6 +31,21 @@ pub enum PreBuild {
     Lines(Vec<String>),
 }
 
+impl serde::Serialize for PreBuild {
+    fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
+        match self {
+            PreBuild::Single { line, .. } => serializer.serialize_str(line),
+            PreBuild::Lines(lines) => {
+                use serde::ser::SerializeSeq;
+                let mut seq = serializer.serialize_seq(Some(lines.len()))?;
+                for line in lines {
+                    seq.serialize_element(line)?;
+                }
+                seq.end()
+            }
+        }
+    }
+}
 impl FromStr for PreBuild {
     type Err = std::convert::Infallible;
 
diff --git a/src/docker/local.rs b/src/docker/local.rs
index 2d86d3d..ed65f0b 100644
--- a/src/docker/local.rs
+++ b/src/docker/local.rs
@@ -39,21 +39,21 @@ pub(crate) fn run(
     docker_user_id(&mut docker, engine.kind);
 
     docker
-        .args(&["-v", &format!("{}:/xargo:Z", dirs.xargo.to_utf8()?)])
-        .args(&["-v", &format!("{}:/cargo:Z", dirs.cargo.to_utf8()?)])
+        .args(&["-v", &format!("{}:/xargo:z", dirs.xargo.to_utf8()?)])
+        .args(&["-v", &format!("{}:/cargo:z", dirs.cargo.to_utf8()?)])
         // Prevent `bin` from being mounted inside the Docker container.
         .args(&["-v", "/cargo/bin"]);
     if mount_volumes {
         docker.args(&[
             "-v",
-            &format!("{}:{}:Z", dirs.host_root.to_utf8()?, dirs.mount_root),
+            &format!("{}:{}:z", dirs.host_root.to_utf8()?, dirs.mount_root),
         ]);
     } else {
-        docker.args(&["-v", &format!("{}:/project:Z", dirs.host_root.to_utf8()?)]);
+        docker.args(&["-v", &format!("{}:/project:z", dirs.host_root.to_utf8()?)]);
     }
     docker
-        .args(&["-v", &format!("{}:/rust:Z,ro", dirs.sysroot.to_utf8()?)])
-        .args(&["-v", &format!("{}:/target:Z", dirs.target.to_utf8()?)]);
+        .args(&["-v", &format!("{}:/rust:z,ro", dirs.sysroot.to_utf8()?)])
+        .args(&["-v", &format!("{}:/target:z", dirs.target.to_utf8()?)]);
     docker_cwd(&mut docker, &paths, mount_volumes)?;
 
     // When running inside NixOS or using Nix packaging we need to add the Nix
@@ -61,7 +61,7 @@ pub(crate) fn run(
     if let Some(ref nix_store) = dirs.nix_store {
         docker.args(&[
             "-v",
-            &format!("{}:{}:Z", nix_store.to_utf8()?, nix_store.as_posix()?),
+            &format!("{}:{}:z", nix_store.to_utf8()?, nix_store.as_posix()?),
         ]);
     }
 
diff --git a/xtask/src/build_docker_image.rs b/xtask/src/build_docker_image.rs
index fc00310..6feb367 100644
--- a/xtask/src/build_docker_image.rs
+++ b/xtask/src/build_docker_image.rs
@@ -84,7 +84,21 @@ fn locate_dockerfile(
     } else {
         eyre::bail!("unable to find dockerfile for target \"{target}\"");
     };
-    let dockerfile = dockerfile_root.join(dockerfile_name).to_utf8()?.to_string();
+    let dockerfile = if matches!(
+        target.triplet.as_str(),
+        "powerpc64-unknown-linux-gnu"
+            | "x86_64-sun-solaris"
+            | "i686-pc-windows-gnu"
+            | "x86_64-pc-windows-gnu"
+            | "sparc64-unknown-linux-gnu"
+    ) {
+        crate::util::project_dir(&mut <_>::default())?
+            .join("Dockerfile.hack")
+            .to_utf8()?
+            .to_string()
+    } else {
+        dockerfile_root.join(dockerfile_name).to_utf8()?.to_string()
+    };
     Ok((target, dockerfile))
 }
 
@@ -243,6 +257,11 @@ pub fn build_docker_image(
             docker_build.args(&["--build-arg", "VERBOSE=1"]);
         }
 
+        docker_build.args(&[
+            "--build-arg",
+            &format!("CROSS_IMAGE={}", target.image_name(&repository, "0.2.4")),
+        ]);
+
         if target.needs_workspace_root_context() {
             docker_build.arg(&root);
         } else {


Test patch:
diff --git a/src/tests/toml.rs b/src/tests/toml.rs
index d917ea9..b7b7e75 100644
--- a/src/tests/toml.rs
+++ b/src/tests/toml.rs
@@ -60,14 +60,17 @@ fn toml_check() -> Result<(), Box<dyn std::error::Error>> {
                 text_line_no(&contents, fence.range().start),
             );
             let mut msg_info = crate::shell::MessageInfo::default();
-            assert!(if !cargo {
+            let toml = if !cargo {
                 crate::cross_toml::CrossToml::parse_from_cross(&fence_content, &mut msg_info)?
             } else {
                 crate::cross_toml::CrossToml::parse_from_cargo(&fence_content, &mut msg_info)?
                     .unwrap_or_default()
-            }
-            .1
-            .is_empty());
+            };
+            assert!(toml.1.is_empty());
+
+            // TODO: Add serde_path_to_error
+            // Check if roundtrip works, needed for merging Cross.toml and Cargo.toml
+            serde_json::from_value::<crate::cross_toml::CrossToml>(serde_json::to_value(toml.0)?)?;
         }
     }
     Ok(())