Switch to C officially, especially for multi-architecture compatibility#17
Merged
yosifkit merged 2 commits intodocker-library:masterfrom Jun 30, 2016
Merged
Switch to C officially, especially for multi-architecture compatibility#17yosifkit merged 2 commits intodocker-library:masterfrom
yosifkit merged 2 commits intodocker-library:masterfrom
Conversation
Build a minimal version in C instead of assembly so it easily can be ported to other archs. This statically linked C version builds a binary that is 1472 bytes. fixes docker-library#7
… to ensure cross-architecture compatibility is maximized
Contributor
|
Protip: link static with musl using |
Member
Author
|
Oh, that is available in Debian! (https://packages.debian.org/sid/musl-dev) I'll play, thanks! 😄 |
Member
Author
|
It appears not to cover |
Member
Author
|
Before: ( + ls -l hello-seattle/hello hello-world/hello hola-mundo/hello
-rwxr-xr-x 1 root root 1864 Jun 29 23:37 hello-seattle/hello
-rwxr-xr-x 1 root root 1848 Jun 29 23:37 hello-world/hello
-rwxr-xr-x 1 root root 1864 Jun 29 23:37 hola-mundo/helloAfter: ( + ls -l hello-seattle/hello hello-world/hello hola-mundo/hello
-rwxr-xr-x 1 root root 1760 Jun 30 17:13 hello-seattle/hello
-rwxr-xr-x 1 root root 1736 Jun 30 17:13 hello-world/hello
-rwxr-xr-x 1 root root 1760 Jun 30 17:13 hola-mundo/helloChanges: diff --git a/Dockerfile.build b/Dockerfile.build
index ed3de7c..b81d465 100644
--- a/Dockerfile.build
+++ b/Dockerfile.build
@@ -1,10 +1,15 @@
# explicitly use Debian for maximum cross-architecture compatibility
FROM debian:jessie
-RUN apt-get update && apt-get install -y --no-install-recommends \
- gcc \
- libc6-dev \
- make \
+RUN set -ex \
+ && apt-get update \
+# s390x does not have "musl-tools" or "musl-dev", so we need a fallback
+ && if apt-cache show musl-tools > /dev/null 2>&1; then \
+ gcc='musl-tools musl-dev'; \
+ else \
+ gcc='gcc libc6-dev'; \
+ fi \
+ && apt-get install -y --no-install-recommends make $gcc \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /usr/src/hello
diff --git a/Makefile b/Makefile
index d0b0b63..35c0fb4 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,8 @@
+SHELL := /bin/bash
+
C_TARGETS := $(addsuffix hello, $(wildcard */))
-CC := gcc
+CC := $(shell command -v musl-gcc &> /dev/null && echo musl-gcc || echo gcc)
CFLAGS := -static -Os -nostartfiles -fno-asynchronous-unwind-tables
.PHONY: all
diff --git a/hello-seattle/hello b/hello-seattle/hello
index f7ef94c..7e1d530 100755
Binary files a/hello-seattle/hello and b/hello-seattle/hello differ
diff --git a/hello-world/hello b/hello-world/hello
index 7f3f7f8..9f6f7da 100755
Binary files a/hello-world/hello and b/hello-world/hello differ
diff --git a/hola-mundo/hello b/hola-mundo/hello
index 4d6496d..6a8804c 100755
Binary files a/hola-mundo/hello and b/hola-mundo/hello differ |
Member
|
LGTM, I don't think ~100 bytes warrants the extra complexity. |
tianon
added a commit
to infosiftr/stackbrew
that referenced
this pull request
Jul 1, 2016
- `docker`: ootb support for `--userns-remap=default` (docker-library/docker#13) - `elasticsearch`: 5.0.0-alpha4 - `golang`: Alpine `ca-certificates` (esp. for `net/http` usage; docker-library/golang#99) - `hello-seattle`: use C for multi-architecture compatibility (docker-library/hello-world#17) - `hello-world`: use C for multi-architecture compatibility (docker-library/hello-world#17) - `hola-mundo`: use C for multi-architecture compatibility (docker-library/hello-world#17) - `kibana`: 5.0.0-alpha4 - `logstash`: 5.0.0-alpha4 - `mariadb`: 10.1.15 - `owncloud`: 9.0.3, 8.2.6 - `python`: remove double-`pip` (docker-library/python#121) - `rocket.chat`: 0.35.0
tianon
added a commit
to infosiftr/stackbrew
that referenced
this pull request
Jul 1, 2016
- `docker`: ootb support for `--userns-remap=default` (docker-library/docker#13) - `elasticsearch`: 5.0.0-alpha4 - `golang`: Alpine `ca-certificates` (esp. for `net/http` usage; docker-library/golang#99) - `hello-seattle`: use C for multi-architecture compatibility (docker-library/hello-world#17) - `hello-world`: use C for multi-architecture compatibility (docker-library/hello-world#17) - `hola-mundo`: use C for multi-architecture compatibility (docker-library/hello-world#17) - `kibana`: 5.0.0-alpha4 - `logstash`: 5.0.0-alpha4 - `mariadb`: 10.1.15 - `owncloud`: 9.0.3, 8.2.6 - `python`: remove double-`pip` (docker-library/python#121) - `rocket.chat`: 0.35.0
stuart-c
pushed a commit
to stuart-c/official-images
that referenced
this pull request
Jul 2, 2016
- `docker`: ootb support for `--userns-remap=default` (docker-library/docker#13) - `elasticsearch`: 5.0.0-alpha4 - `golang`: Alpine `ca-certificates` (esp. for `net/http` usage; docker-library/golang#99) - `hello-seattle`: use C for multi-architecture compatibility (docker-library/hello-world#17) - `hello-world`: use C for multi-architecture compatibility (docker-library/hello-world#17) - `hola-mundo`: use C for multi-architecture compatibility (docker-library/hello-world#17) - `kibana`: 5.0.0-alpha4 - `logstash`: 5.0.0-alpha4 - `mariadb`: 10.1.15 - `owncloud`: 9.0.3, 8.2.6 - `python`: remove double-`pip` (docker-library/python#121) - `rocket.chat`: 0.35.0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #7
Closes #9 (carried)