用docker编译方舟编译器

准备工作

  1. 下载方舟源码: git clone https://code.opensource.huaweicloud.com/HarmonyOS/OpenArkCompiler.git
  2. 需要安装docker

    生成出来的镜像以后可作为CI里编译方舟应用时的编译环境。
    现在可用来做getting start的环境,简单编译环境的搭建

dockerfile

把下面的dockerfile放到方舟源码根目录下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
FROM ubuntu:16.04 AS build-env
MAINTAINER https://www.openarkcompiler.cn

# Setting up the build environment
RUN sed -i 's/archive.ubuntu.com/mirrors.163.com/g' /etc/apt/sources.list && \
dpkg --add-architecture i386 && \
apt-get -y update && \
apt-get -y dist-upgrade && \
apt-get -y install openjdk-8-jdk git-core build-essential zlib1g-dev libc6-dev-i386 g++-multilib gcc-multilib linux-libc-dev:i386 && \
apt-get -y install gcc-5-aarch64-linux-gnu g++-5-aarch64-linux-gnu unzip tar curl && \
apt-get -y install python3-paramiko python-paramiko python-requests && \
mkdir -p /tools/ninja /tools/gn

# 在国内请反注释下行, 因为容器也是个单独的系统,所以别用127.0.0.1
#ENV http_proxy=http://192.168.3.81:1081 \
# https_proxy=http://192.168.3.81:1081

RUN cd /tools && \
curl -C - -LO http://releases.llvm.org/8.0.0/clang+llvm-8.0.0-x86_64-linux-gnu-ubuntu-16.04.tar.xz && \
curl -LO https://github.com/ninja-build/ninja/releases/download/v1.9.0/ninja-linux.zip && \
curl -LO http://tools.harmonyos.com/mirrors/gn/1523/linux/gn.1523.tar && \
tar Jvxf /tools/clang+llvm-8.0.0-x86_64-linux-gnu-ubuntu-16.04.tar.xz -C /tools/ && \
unzip /tools/ninja-linux.zip -d /tools/ninja/ && \
tar xvf /tools/gn.1523.tar && \
chmod a+x /tools/gn/gn && \
rm /tools/clang+llvm-8.0.0-x86_64-linux-gnu-ubuntu-16.04.tar.xz /tools/ninja-linux.zip && \
rm -rf /var/cache/apt/archives

# copy source
COPY . /OpenArkCompiler
WORKDIR /OpenArkCompiler

# create symbolic link
RUN mkdir -p /OpenArkCompiler/tools /OpenArkCompiler/tools/gn && \
ln -s /tools/ninja /OpenArkCompiler/tools/ninja_1.9.0 && \
ln -s /tools/gn/gn /OpenArkCompiler/tools/gn/gn && \
ln -s /tools/clang+llvm-8.0.0-x86_64-linux-gnu-ubuntu-16.04 /OpenArkCompiler/tools/clang+llvm-8.0.0-x86_64-linux-gnu-ubuntu-16.04

# compile
RUN ["/bin/bash", "-c", "source build/envsetup.sh && make && ls -al "]

# build final docker image
FROM ubuntu:16.04
RUN sed -i 's/archive.ubuntu.com/mirrors.163.com/g' /etc/apt/sources.list && \
apt-get -y update && \
apt-get install -y openjdk-8-jdk curl vim && \
rm -rf /var/cache/apt/archives
COPY --from=build-env /OpenArkCompiler/output /OpenArkCompiler
VOLUME /OpenArkCompiler
ENV PATH=/OpenArkCompiler/bin:$PATH
CMD maple -h

编译

第一次编译安装依赖会慢点, 之后因为docker缓存每次编译会跳过依赖安装从复制源码开始

1
docker build -t ark:latest .

测试

1
docker run --rm ark:latest

交互模式

1
2
docker run --rm -ti ark:latest bash
maple -h

方舟编译java代码教程