在Alpine Linux的Docker容器中构建GNATCOLL

9

我似乎无法在基于Alpine Linux的Docker容器中编译GNATCOLL。

我的容器目前为:

FROM alpine:edge

# Add extra repositories
RUN echo 'http://dl-cdn.alpinelinux.org/alpine/edge/testing' >> /etc/apk/repositories; \
    echo 'http://dl-cdn.alpinelinux.org/alpine/edge/community' >> /etc/apk/repositories; \
    echo 'http://dl-cdn.alpinelinux.org/alpine/edge/main' >> /etc/apk/repositories;

RUN apk add --no-cache build-base coreutils curl-dev gcc-gnat git gmp-dev openssl

# Bootstrap GPRBuild
RUN git clone https://github.com/AdaCore/xmlada.git; \
    git clone https://github.com/AdaCore/gprbuild.git; \
    cd gprbuild; ./bootstrap.sh --with-xmlada=../xmlada; \
    cd ..; \
    rm -rf xmlada gprbuild

这可以正常运行并给我提供了一个使用GNAT GPR构建的可工作Ada开发环境的容器。当我尝试在此容器中安装GNATCOLL时出现问题。
运行 docker run -i -t <built_image>,会发生以下情况:
/ # git clone https://github.com/AdaCore/gnatcoll-core.git
<Typical git clone output>
/ # cd gnatcoll-core/
/gnatcoll-core # make setup
/gnatcoll-core # make
gprbuild -p -m --target=x86_64-linux  -j0 -XGNATCOLL_MMAP=yes -XGNATCOLL_MADVISE=yes -XGNATCOLL_VERSION=0.0 -XGNATCOLL_OS=unix -XBUILD=PROD  -XLIBRARY_TYPE=static -XXMLADA_BUILD=static -XGPR_BUILD=static \
        -XGNATCOLL_MMAP=yes -XGNATCOLL_MADVISE=yes -XGNATCOLL_VERSION=0.0 -XGNATCOLL_OS=unix -XBUILD=PROD gnatcoll.gpr
Setup
   [mkdir]        object directory for project GnatColl
   [mkdir]        library directory for project GnatColl
gnatcoll.gpr:24:06: unknown project file: "gpr"
make: *** [Makefile:128: build-static] Error 4

根据 https://github.com/AdaCore/gnatcoll-core/issues/30 中的讨论,我检查了我的gprbuild版本:

/gnatcoll-core # gprbuild --version
GPRBUILD Pro 18.0w (19940713) (x86_64-alpine-linux-musl)
Copyright (C) 2004-2016, AdaCore
This is free software; see the source for copying conditions.
See your AdaCore support agreement for details of warranty and support.
If you do not have a current support agreement, then there is absolutely
no warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.

看起来musl的gprbuild版本过时了,导致无法构建GNATCOLL。有没有获取musl-c更更新的gprbuild版本的方法?如果没有,还有其他方式可以安装GNATCOLL吗?


考虑到你是直接从GitHub代码库中克隆的,所以我不认为该版本是正确的。关于为什么该版本被声明为它是什么,可以在文件gpr-version.ads的包规范开始之前的注释中找到一些提示。 - DeeDee
看起来你是对的,但这并不能解释为什么我无法构建gnatcoll。 - LambdaBeta
在构建GNATCOLL时,GPRbuild似乎找不到项目gpr.gpr。该项目文件位于GPRbuild存储库的gpr目录中(请参见此处)。您可能需要将gpr.gpr项目的位置添加到环境变量GPR_PROJECT_PATH中(并使用export使其对子进程可见)。另请参阅GPR工具手册中的导入项目 - DeeDee
转念一想,您可能还需要检查 gpr.gpr 是否已经与 GPRbuild 可执行文件一起安装在某个地方。如果是这种情况,您也可以使用该版本。 - DeeDee
我检查了一下,确实没有安装 gpr.gpr。我尝试使用项目中的一个,但它重用了一些构建变量。特别是 gnatcoll 使用 -XBUILD=PROD,但 gprbuild 的 gpr.gpr 源文件使用 -XBUILD=production,所以它们不兼容。肯定有其他方法可以获得所需的 gpr.gpr 文件,但在 gprbuild 项目中运行 make install 似乎行不通。 - LambdaBeta
没关系,我已经解决了... 我很快会发布一个答案,只需要整理一下我的解决方案。 - LambdaBeta
1个回答

11
问题在于gprbuild中的"./bootstrap.sh"没有安装所有内容,它只创建了一个最基本的gprbuild安装。此外,它不会构建gprlib,而这对于gnatcoll是必需的,也必须安装。
所需步骤为:
# As before...
git clone https://github.com/AdaCore/xmlada.git
git clone https://github.com/AdaCore/gprbuild.git
cd gprbuild; ./bootstrap.sh --with-xmlada=../xmlada

# New: build and install xmlada
cd ../xmlada; ./configure && make && make install

# New: build and install gprbuild fully
cd ../gprbuild
export GPR_PROJECT_PATH=/usr/local/share/gpr
make prefix=/usr/local setup && make all && make install

# New: build and install gprlib
make libgpr.build && make libgpr.install

通过这些添加,我按照其项目规格成功地构建了gnatcoll。


1
浪费了许多时间后,这个答案解决了问题。谢谢! - mndrix

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接