ktock / container2wasm

Container to WASM converter
https://ktock.github.io/container2wasm-demo/
Apache License 2.0
2.08k stars 85 forks source link

Impossible to run with mac M1 #155

Closed demangejeremy closed 1 year ago

demangejeremy commented 1 year ago

I'm trying to run c2w on Mac M1. Here are the errors I get:

c2w ubuntu:22.04 out.wasm

This gives me this error:

...
#39 2.127 HEAD is now at 89bec45 bump: version 0.3.0
#39 2.150 info: syncing channel updates for '1.61.0-aarch64-unknown-linux-gnu'
#39 CANCELED
------
 > [runc-amd64-dev 2/2] RUN --mount=type=cache,target=/root/.cache/go-build     --mount=type=cache,target=/go/pkg/mod     git clone https://github.com/opencontainers/runc.git /go/src/github.com/opencontainers/runc &&     cd /go/src/github.com/opencontainers/runc &&     git checkout "v1.1.9" &&     make static GOARCH=amd64 CC=gcc EXTRA_LDFLAGS='-s -w' BUILDTAGS="" EXTRA_LDFLAGS='-s -w' BUILDTAGS="" &&     mkdir -p /out/ && mv runc /out/runc:
3.151 
3.151   git switch -
3.151 
3.151 Turn off this advice by setting config variable advice.detachedHead to false
3.151 
3.151 HEAD is now at ccaecfcb VERSION: release 1.1.9
3.225 go build -trimpath -buildmode=pie  -tags " netgo osusergo" -ldflags "-X main.gitCommit=v1.1.9-0-gccaecfcb -X main.version=1.1.9 -linkmode external -extldflags --static-pie -s -w" -o runc .
3.470 # runtime/cgo
3.470 gcc: error: unrecognized command-line option '-m64'
3.508 make: *** [Makefile:69: static] Error 1
------
Dockerfile:332
--------------------
 331 |     RUN apt-get update -y && apt-get install -y git make gperf
 332 | >>> RUN --mount=type=cache,target=/root/.cache/go-build \
 333 | >>>     --mount=type=cache,target=/go/pkg/mod \
 334 | >>>     git clone https://github.com/opencontainers/runc.git /go/src/github.com/opencontainers/runc && \
 335 | >>>     cd /go/src/github.com/opencontainers/runc && \
 336 | >>>     git checkout "${RUNC_VERSION}" && \
 337 | >>>     make static GOARCH=amd64 CC=gcc EXTRA_LDFLAGS='-s -w' BUILDTAGS="" EXTRA_LDFLAGS='-s -w' BUILDTAGS="" && \
 338 | >>>     mkdir -p /out/ && mv runc /out/runc
 339 |     
--------------------
ERROR: failed to solve: process "/bin/sh -c git clone https://github.com/opencontainers/runc.git /go/src/github.com/opencontainers/runc &&     cd /go/src/github.com/opencontainers/runc &&     git checkout \"${RUNC_VERSION}\" &&     make static GOARCH=amd64 CC=gcc EXTRA_LDFLAGS='-s -w' BUILDTAGS=\"\" EXTRA_LDFLAGS='-s -w' BUILDTAGS=\"\" &&     mkdir -p /out/ && mv runc /out/runc" did not complete successfully: exit code: 2
exit status 1

And with a target arm :

c2w --target-arch=arm ubuntu:22.04 out.wasm

This gives me this error:

...
#23 12.37 info: downloading component 'rust-std' for 'wasm32-unknown-unknown'
#23 16.47 info: downloading component 'rust-std' for 'wasm32-wasi'
#23 CANCELED
------
 > [gcc-riscv64-linux-gnu-base 2/2] RUN apt-get update && apt-get install -y gcc-riscv64-linux-gnu libc-dev-riscv64-cross git make:
7.705 Fetched 22.4 MB in 7s (3171 kB/s)
7.705 Reading package lists...
12.05 Reading package lists...
16.13 Building dependency tree...
16.66 Reading state information...
16.67 Package gcc-riscv64-linux-gnu is not available, but is referred to by another package.
16.67 This may mean that the package is missing, has been obsoleted, or
16.67 is only available from another source
16.67 
16.67 E: Package 'gcc-riscv64-linux-gnu' has no installation candidate
------
Dockerfile:71
--------------------
  69 |     
  70 |     FROM ubuntu:22.04 AS gcc-riscv64-linux-gnu-base
  71 | >>> RUN apt-get update && apt-get install -y gcc-riscv64-linux-gnu libc-dev-riscv64-cross git make
  72 |     
  73 |     FROM gcc-riscv64-linux-gnu-base AS bbl-dev
--------------------
ERROR: failed to solve: process "/bin/sh -c apt-get update && apt-get install -y gcc-riscv64-linux-gnu libc-dev-riscv64-cross git make" did not complete successfully: exit code: 100
exit status 1

This doesn't work with other containers (like Python, for example).

If you have any idea how to solve this problem, I'd love to hear from you. I'm trying to find a solution myself, and if I do, I'll update this page.

Many thanks :)

ktock commented 1 year ago

@demangejeremy Does the following Dockerfile diff (for container2wasm v0.5.1 and without --target-arch=arm) solve the build error?

$ c2w --show-dockerfile > /tmp/org-dockerfile
$ cat <<'EOF' > /tmp/dockerfile.diff
--- a/Dockerfile
+++ b/Dockerfile
@@ -328,13 +328,13 @@ RUN mkdir -p /out/usr/share/udhcpc/ && cp ./examples/udhcp/simple.script /out/us

 FROM golang-base AS runc-amd64-dev
 ARG RUNC_VERSION
-RUN apt-get update -y && apt-get install -y git make gperf
+RUN apt-get update -y && apt-get install -y gcc-x86-64-linux-gnu libc-dev-amd64-cross git make gperf
 RUN --mount=type=cache,target=/root/.cache/go-build \
     --mount=type=cache,target=/go/pkg/mod \
     git clone https://github.com/opencontainers/runc.git /go/src/github.com/opencontainers/runc && \
     cd /go/src/github.com/opencontainers/runc && \
     git checkout "${RUNC_VERSION}" && \
-    make static GOARCH=amd64 CC=gcc EXTRA_LDFLAGS='-s -w' BUILDTAGS="" EXTRA_LDFLAGS='-s -w' BUILDTAGS="" && \
+    make static GOARCH=amd64 CC=x86_64-linux-gnu-gcc EXTRA_LDFLAGS='-s -w' BUILDTAGS="" EXTRA_LDFLAGS='-s -w' BUILDTAGS="" && \
     mkdir -p /out/ && mv runc /out/runc

 FROM gcc-x86-64-linux-gnu-base AS tini-amd64-dev
EOF
$ patch -o /tmp/new-dockerfile /tmp/org-dockerfile /tmp/dockerfile.diff
$ c2w --dockerfile /tmp/new-dockerfile alpine:3.18 /tmp/out/out.wasm
demangejeremy commented 1 year ago

Thank you @ktock.

With version v0.5.1 and the proposed patch, it still doesn't work. Here's the error:

...
#43 [runc-amd64-dev 1/2] RUN apt-get update -y && apt-get install -y gcc-x86-64-linux-gnu libc-dev-amd64-cross git make gperf
#43 0.537 Get:1 http://deb.debian.org/debian bullseye InRelease [116 kB]
#43 0.570 Get:2 http://deb.debian.org/debian-security bullseye-security InRelease [48.4 kB]
#43 0.587 Get:3 http://deb.debian.org/debian bullseye-updates InRelease [44.1 kB]
#43 0.721 Get:4 http://deb.debian.org/debian bullseye/main arm64 Packages [7951 kB]
#43 0.885 Get:5 http://deb.debian.org/debian-security bullseye-security/main arm64 Packages [250 kB]
#43 CANCELED

#34 [bochs-dev-common  4/25] RUN curl -o wasi-sdk.tar.gz -fSL https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-19/wasi-sdk-19.0-linux.tar.gz &&     tar xvf wasi-sdk.tar.gz && rm wasi-sdk.tar.gz
#34 CANCELED
------
 > [bios-amd64-dev 5/7] RUN CC="x86_64-linux-gnu-gcc" ./configure --enable-x86-64 --with-nogui:
0.732 checking build system type... aarch64-unknown-linux-gnu
0.772 checking host system type... aarch64-unknown-linux-gnu
0.774 checking target system type... aarch64-unknown-linux-gnu
0.775 checking if you are configuring for another platform... no
0.775 checking for standard CFLAGS on this platform... 
0.785 checking for gcc... x86_64-linux-gnu-gcc
0.835 checking whether the C compiler works... no
0.850 configure: error: in `/Bochs/bochs':
0.851 configure: error: C compiler cannot create executables
0.851 See `config.log' for more details
------
new-dockerfile:370
--------------------
 368 |     COPY --link --from=assets ./patches/bochs/Bochs /Bochs
 369 |     WORKDIR /Bochs/bochs
 370 | >>> RUN CC="x86_64-linux-gnu-gcc" ./configure --enable-x86-64 --with-nogui
 371 |     RUN make -j$(nproc) bios/BIOS-bochs-latest bios/VGABIOS-lgpl-latest
 372 |     RUN mkdir /out/ && mv bios/BIOS-bochs-latest bios/VGABIOS-lgpl-latest /out/
--------------------
ERROR: failed to solve: process "/bin/sh -c CC=\"x86_64-linux-gnu-gcc\" ./configure --enable-x86-64 --with-nogui" did not complete successfully: exit code: 77
exit status 1

Thanks again for your time. For my part, I tried a few tests (activation of new features in docker desktop, tried with Orbstack, no positive results yet).

ktock commented 1 year ago

@demangejeremy Thanks for trying that. The errors seem to be caused by the architecture difference. What do you get from the following Dockerfile diff?

$ c2w --show-dockerfile > /tmp/org-dockerfile
$ cat <<'EOF' > /tmp/dockerfile.diff
--- a/Dockerfile
+++ b/Dockerfile
@@ -328,13 +328,13 @@ RUN mkdir -p /out/usr/share/udhcpc/ && cp ./examples/udhcp/simple.script /out/us

 FROM golang-base AS runc-amd64-dev
 ARG RUNC_VERSION
-RUN apt-get update -y && apt-get install -y git make gperf
+RUN apt-get update -y && apt-get install -y gcc-x86-64-linux-gnu libc-dev-amd64-cross git make gperf
 RUN --mount=type=cache,target=/root/.cache/go-build \
     --mount=type=cache,target=/go/pkg/mod \
     git clone https://github.com/opencontainers/runc.git /go/src/github.com/opencontainers/runc && \
     cd /go/src/github.com/opencontainers/runc && \
     git checkout "${RUNC_VERSION}" && \
-    make static GOARCH=amd64 CC=gcc EXTRA_LDFLAGS='-s -w' BUILDTAGS="" EXTRA_LDFLAGS='-s -w' BUILDTAGS="" && \
+    make static GOARCH=amd64 CC=x86_64-linux-gnu-gcc EXTRA_LDFLAGS='-s -w' BUILDTAGS="" EXTRA_LDFLAGS='-s -w' BUILDTAGS="" && \
     mkdir -p /out/ && mv runc /out/runc

 FROM gcc-x86-64-linux-gnu-base AS tini-amd64-dev
@@ -363,7 +363,7 @@ COPY --link --from=assets ./patches/bochs/grub.cfg.template /
 RUN cat /grub.cfg.template | LOGLEVEL=$LINUX_LOGLEVEL envsubst > /iso/boot/grub/grub.cfg
 RUN mkdir /out && grub-mkrescue --directory ./grub-core -o /out/boot.iso /iso

-FROM ubuntu AS bios-amd64-dev
+FROM gcc-x86-64-linux-gnu-base AS bios-amd64-dev
 RUN apt-get update && apt-get install -y build-essential
 COPY --link --from=assets ./patches/bochs/Bochs /Bochs
 WORKDIR /Bochs/bochs
EOF
$ patch -o /tmp/new-dockerfile /tmp/org-dockerfile /tmp/dockerfile.diff
$ c2w --dockerfile /tmp/new-dockerfile alpine:3.18 /tmp/out/out.wasm
demangejeremy commented 1 year ago

I get exactly the same error as above. I'm not a specialist, but could this be related? : https://github.com/docker/roadmap/issues/384

I also tried this: https://github.com/messense/homebrew-macos-cross-toolchains

No results either :/

ktock commented 1 year ago

@demangejeremy Sorry for the slow reply. I believe #155 fixed this issue. Please try the latest commit in the main branch.