From 998c08066012ea1141c8c7c2b27821f5b6ad4fad Mon Sep 17 00:00:00 2001 From: CrazyMax <1951866+crazy-max@users.noreply.github.com> Date: Thu, 21 Dec 2023 16:11:19 +0100 Subject: [PATCH 1/4] dockerfile: remove APT_MIRROR Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com> --- docker-bake.hcl | 1 - src/Dockerfile | 4 ---- 2 files changed, 5 deletions(-) diff --git a/docker-bake.hcl b/docker-bake.hcl index 92c761a3..04525133 100644 --- a/docker-bake.hcl +++ b/docker-bake.hcl @@ -32,7 +32,6 @@ target "test-alpine" { target "test-debian" { inherits = ["test-src"] args = { - APT_MIRROR = "cdn-fastly.deb.debian.org" TEST_BASE_TYPE = "debian" TEST_BASE_IMAGE = "debian:bookworm" } diff --git a/src/Dockerfile b/src/Dockerfile index 40f425e4..abf8c966 100644 --- a/src/Dockerfile +++ b/src/Dockerfile @@ -25,15 +25,11 @@ RUN --mount=type=cache,target=/pkg-cache \ WORKDIR /work FROM ${TEST_BASE_IMAGE} AS test-base-debian -ARG APT_MIRROR=deb.debian.org RUN --mount=type=cache,target=/pkg-cache \ rm -rf /var/cache/apt/archives && \ ln -s /pkg-cache /var/cache/apt/archives && \ rm /etc/apt/apt.conf.d/docker-clean && \ echo 'Binary::apt::APT::Keep-Downloaded-Packages "1";' > /etc/apt/apt.conf.d/keep-downloads && \ - touch /etc/apt/sources.list && \ - sed -ri "s/(httpredir|deb).debian.org/${APT_MIRROR:-deb.debian.org}/g" /etc/apt/sources.list && \ - sed -ri "s/(security).debian.org/${APT_MIRROR:-security.debian.org}/g" /etc/apt/sources.list && \ apt update && apt install --no-install-recommends -y bats vim WORKDIR /work From 6a115afd099dc190021839816c48a4f1ab1241d9 Mon Sep 17 00:00:00 2001 From: CrazyMax <1951866+crazy-max@users.noreply.github.com> Date: Thu, 21 Dec 2023 16:11:19 +0100 Subject: [PATCH 2/4] debian/ubuntu: fix apt sources list location Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com> --- src/xx-apt | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/xx-apt b/src/xx-apt index 20400e5c..4b3e747a 100755 --- a/src/xx-apt +++ b/src/xx-apt @@ -21,6 +21,16 @@ checkpkg() { apt show "$@" } +aptsourcesfile() { + if [ -f /etc/apt/sources.list.d/debian.sources ]; then + echo /etc/apt/sources.list.d/debian.sources + elif [ -f /etc/apt/sources.list.d/ubuntu.sources ]; then + echo /etc/apt/sources.list.d/ubuntu.sources + else + echo /etc/apt/sources.list + fi +} + exitnolinux() { if [ "${TARGETOS}" != "linux" ]; then echo >&2 "skipping packages installation on ${XX_OS}" @@ -37,7 +47,7 @@ case "${TARGETARCH}" in riscv*) case "${XX_VENDOR}" in debian) - if ! grep "sid main" /etc/apt/sources.list >/dev/null; then + if ! grep "sid main" "$(aptsourcesfile)" >/dev/null; then echo >&2 "skipping packages installation on ${XX_ARCH}. riscv64 currently only supported on sid" exit 0 fi @@ -64,7 +74,7 @@ fi fixubuntusources() { # fix all current sources to native arch nativearch="$(TARGETPLATFORM="" TARGETPAIR="" TARGETARCH="" TARGETOS="" xx-info arch)" - sed -E "/arch=/! s/^(# )?(deb|deb-src) /\1\2 [arch=$nativearch] /" -i /etc/apt/sources.list + sed -E "/arch=/! s/^(# )?(deb|deb-src) /\1\2 [arch=$nativearch] /" -i "$(aptsourcesfile)" if ! xx-info is-cross; then return; fi From dd94c5c2ee8c9dd612d495df33fa7aff022e598f Mon Sep 17 00:00:00 2001 From: CrazyMax <1951866+crazy-max@users.noreply.github.com> Date: Wed, 10 Jan 2024 10:14:24 +0100 Subject: [PATCH 3/4] readme: fix note blockquote syntax related to https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax#alerts Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com> --- README.md | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index ee46f8b9..a3af70bd 100644 --- a/README.md +++ b/README.md @@ -146,8 +146,7 @@ RUN xx-clang --static -o /out/myapp app.c && \ xx-verify --static /out/myapp ``` -> **Note** -> +> [!NOTE] > `XX_VERIFY_STATIC=1` environment variable can be defined to make `xx-verify` > always verify that the compiler produced a static binary. @@ -372,8 +371,7 @@ RUN cargo build --target=$(xx-cargo --print-target-triple) --release --target-di xx-verify ./build/$(xx-cargo --print-target-triple)/release/hello_cargo ``` -> **Note** -> +> [!NOTE] > `xx-cargo --print-target-triple` does not always have the same value as > `xx-clang --print-target-triple`. This is because prebuilt Rust and C > libraries sometimes use a different value. @@ -400,8 +398,7 @@ RUN --mount=type=cache,target=/root/.cargo/git/db \ xx-verify ./build/$(xx-cargo --print-target-triple)/release/hello_cargo ``` -> **Note** -> +> [!NOTE] > By calling `cargo fetch` before `ARG TARGETPLATFORM` your packages are > fetched only once for the whole build while the building happens separately > for each target architecture. From d0af07ff775f5d7565cc200e04346ab8d99a5221 Mon Sep 17 00:00:00 2001 From: CrazyMax <1951866+crazy-max@users.noreply.github.com> Date: Wed, 10 Jan 2024 10:03:57 +0100 Subject: [PATCH 4/4] xx-apt: print-source-file flag Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com> --- README.md | 3 +++ src/test-apt.bats | 9 +++++++++ src/xx-apt | 14 ++++++++++++++ 3 files changed, 26 insertions(+) diff --git a/README.md b/README.md index a3af70bd..274d1c7b 100644 --- a/README.md +++ b/README.md @@ -134,6 +134,9 @@ ARG TARGETPLATFORM RUN xx-apt-get install -y libc6-dev zlib1g-dev ``` +> [!NOTE] +> `xx-apt --print-source-file` can be used to print the path of the main [Apt sources configuration file](https://manpages.debian.org/bookworm/apt/sources.list.5.en.html) + Installing two meta-libraries, `xx-c-essentials`, `xx-cxx-essentials` is also allowed that expand the minimum necessary packages for either base image. ## `xx-verify` - Verifying compilation results diff --git a/src/test-apt.bats b/src/test-apt.bats index 4cde980a..8b0b9688 100755 --- a/src/test-apt.bats +++ b/src/test-apt.bats @@ -219,3 +219,12 @@ load 'assert' run apt show wget-notexist assert_failure } + +@test "print-source-file" { + run xx-apt --print-source-file + assert_success + assert_output --partial "/etc/apt/sources.list" + + run test -e "$(xx-apt --print-source-file)" + assert_success +} diff --git a/src/xx-apt b/src/xx-apt index 4b3e747a..bac13bbb 100755 --- a/src/xx-apt +++ b/src/xx-apt @@ -38,6 +38,20 @@ exitnolinux() { fi } +n=$# +for a in "$@"; do + if [ $# = $n ]; then set --; fi + case "$a" in + "--print-source-file") + aptsourcesfile + exit 0 + ;; + *) + set -- "$@" "$a" + ;; + esac +done + # these are not supported yet case "${TARGETARCH}" in mips*)