轻量级GCC高山 [英] Lightweight GCC for Alpine

查看:116
本文介绍了轻量级GCC高山的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以在Alpine中安装轻量级的GCC发行版吗?



我正在尝试制作一个小的Docker映像。因此,我使用Alpine作为基本映像(5MB)。与之相比,标准的GCC安装使它相形见((> 100MB)。



那么我可以在Alpine上安装轻量级的GCC发行版吗?



注意:Clang差很多(我最后检查了475MB)。

解决方案

没有这样的图像,AFAIK,但是您可以通过删除不需要的GCC二进制文件来使GCC更苗条。 p>

这在很大程度上取决于GCC所需的功能。



首先,我假设您是仅需要C支持,这意味着安装了 gcc musl-dev 软件包(用于标准标头),结果带有约100MB的图像,带有Alpine 3.8。




  • 如果不需要Objective-C支持,则可以删除 cc1obj ,这是Objective-C后端。在Alpine 3.8上,它位于 /usr/libexec/gcc/x86_64-alpine-linux-musl/6.4.0/cc1obj ,占用17.6MB。 / li>
  • 如果不需要链接时间优化(LTO),则可以删除LTO包装器和主要可执行文件, lto-wrapper lto1 ,分别占用700kb和16.8MB。
    虽然LTO优化功能可能很强大,但在大多数应用程序中,它可能只会带来较小的速度和尺寸改进(只有百分之几)。另外,您必须选择加入LTO,这不是大多数应用程序所能完成的,因此它可能是删除的不错选择。

  • 您可以删除Java前端, gcj ,似乎仍然无法正常工作。它位于 / usr / bin / x86_64-alpine-linux-musl-gcj ,权重812kb。



通过除去这些并挤压所得图像,它将缩小为64.4MB,这仍然很大。您也许可以通过删除其他文件来进一步缩小文件,但是随后您可能会放弃一些所需的功能,并且权衡要求降低。



下面是一个示例Dockerfile:

 从高山:3.8 

RUN set -ex& \
apk添加--no-cache gcc musl-dev

RUN set -ex&& \
rm -f /usr/libexec/gcc/x86_64-alpine-linux-musl/6.4.0/cc1obj&& \
rm -f /usr/libexec/gcc/x86_64-alpine-linux-musl/6.4.0/lto1&& \
rm -f /usr/libexec/gcc/x86_64-alpine-linux-musl/6.4.0/lto-wrapper&& \
rm -f / usr / bin / x86_64-alpine-linux-musl-gcj

使用以下命令测试:
sudo docker image build --squash -t alpine-gcc-minimal。


Is there a lightweight GCC distribution that I can install in Alpine?

I am trying to make a small Docker image. For that reason, I am using Alpine as the base image (5MB). The standard GCC install dwarfs this in comparison (>100MB).

So is there a lightweight GCC distribution that I can install on Alpine?

Note: Clang is much worse (475MB last I checked).

解决方案

There isn't such an image available, AFAIK, but you can make GCC slimmer by deleting unneeded GCC binaries.

It very much depends on what capabilities are required from GCC.

As a starting point, I'm assuming you need C support only, which means the gcc and musl-dev packages (for standard headers) are installed, which result with a ~100MB image with Alpine 3.8.

  • If you don't need Objective-C support, you could remove cc1obj, which is the Objective-C backend. On Alpine 3.8, it would be located at /usr/libexec/gcc/x86_64-alpine-linux-musl/6.4.0/cc1obj, and takes up 17.6MB.
  • If you don't need link time optimization (LTO), you could remove the LTO wrapper and main executables, lto-wrapper and lto1, which take up 700kb and 16.8MB respectively. While LTO optimization may be powerful, on most applications it's likely to result with only minor speed and size improvements (few percents). Plus, you have to opt-in for LTO, which is not done by most applications, so it may be a good candidate for removal.
  • You could remove the Java front end, gcj, which doesn't seem to be working anyways. It is located at /usr/bin/x86_64-alpine-linux-musl-gcj, and weights 812kb.

By removing these, and squashing the resulting image, it would shrink into 64.4MB, which is still considerably large. You may be able to shrink further by removing additional files, but then you may loose some desired functionality and with a less appealing tradeoff.

Here's an example Dockerfile:

FROM alpine:3.8

RUN set -ex && \
    apk add --no-cache gcc musl-dev

RUN set -ex && \
    rm -f /usr/libexec/gcc/x86_64-alpine-linux-musl/6.4.0/cc1obj && \
    rm -f /usr/libexec/gcc/x86_64-alpine-linux-musl/6.4.0/lto1 && \
    rm -f /usr/libexec/gcc/x86_64-alpine-linux-musl/6.4.0/lto-wrapper && \
    rm -f /usr/bin/x86_64-alpine-linux-musl-gcj

Tested using: sudo docker image build --squash -t alpine-gcc-minimal .

这篇关于轻量级GCC高山的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆