Skip to content

Commit 9156089

Browse files
WenyuanLauFei Xu
authored andcommitted
build: Allow stratovirt to be built in an openeuler container
Add a `tools` directory at root, and initialize it with a stratovirt docker-build script and Dockerfile, which allows users to build stratovirt in isolated environment. It also can be used for automated build. Signed-off-by: Liu Wenyuan <[email protected]>
1 parent 3256cb5 commit 9156089

File tree

4 files changed

+127
-0
lines changed

4 files changed

+127
-0
lines changed

docs/build_guide.ch.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,31 @@ $ cargo build --release --target ${arch}-unknown-linux-musl
6363
```shell
6464
$ cargo build --release --features "scream_alsa"
6565
```
66+
67+
# 通过容器构建StratoVirt静态链接二进制
68+
69+
## 1. 检查docker环境
70+
71+
为了通过容器构建StratoVirt,需保证已经安装了docker软件。可通过下面的命令检查:
72+
73+
```shell
74+
$ docker -v
75+
Docker version 18.09.0
76+
```
77+
78+
如果你想部署docker环境,下面的链接可以帮助你:
79+
80+
<https://docs.docker.com/get-docker/>
81+
82+
## 2. 使用tools下提供的构建工具
83+
84+
运行tools/build_stratovirt_static下的脚本,自动拉起docker容器构建静态链接的StratoVirt。
85+
86+
```shell
87+
$ cd tools/build_stratovirt_static
88+
# 自定义一个镜像名称,构建StratoVirt静态链接二进制
89+
$ sh build_stratovirt_from_docker.sh custom_image_name
90+
```
91+
92+
构建完成后,可找到StratoVirt构建静态链接二进制的路径在 `target/${arch}-unknown-linux-musl/release/stratovirt`.
93+

docs/build_guide.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,31 @@ List of optional features:
6464
```shell
6565
$ cargo build --release --features "scream_alsa"
6666
```
67+
68+
# Build static StratoVirt in containers
69+
70+
## 1. Check docker environment
71+
72+
In order to build StratoVirt in containers, ensure that the docker software is installed. This can be checked with the following command:
73+
74+
```shell
75+
$ docker -v
76+
Docker version 18.09.0
77+
```
78+
79+
If you want to deploy a docker environment, the following link can help you:
80+
81+
<https://docs.docker.com/get-docker/>
82+
83+
## 2. Run the build script
84+
85+
Run the script under tools/build_stratovirt_static directory to automatically run a docker container to build a statically linked StratoVirt.
86+
87+
```shell
88+
$ cd tools/build_stratovirt_static
89+
# Build StratoVirt with your custom_image_name
90+
$ sh build_stratovirt_from_docker.sh custom_image_name
91+
```
92+
93+
After the build is complete, you can find the statically linked binary StratoVirt in the path: `target/${arch}-unknown-linux-musl/release/stratovirt`.
94+
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Copyright (c) 2023 Huawei Technologies Co.,Ltd. All rights reserved.
2+
#
3+
# StratoVirt is licensed under Mulan PSL v2.
4+
# You can use this software according to the terms and conditions of the Mulan
5+
# PSL v2.
6+
# You may obtain a copy of Mulan PSL v2 at:
7+
# http://license.coscl.org.cn/MulanPSL2
8+
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY
9+
# KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
10+
# NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
11+
# See the Mulan PSL v2 for more details.
12+
13+
from openeuler/openeuler:22.03-lts-sp2
14+
15+
ARG ARCH
16+
17+
RUN yum update -y && \
18+
yum upgrade -y && \
19+
yum install -y cargo musl-gcc cyrus-sasl-devel && \
20+
yum install -y libcap-devel libcap-ng-devel libseccomp-devel && \
21+
if [ "${ARCH}" == aarch64 ]; then yum install -y dtc-devel; fi && \
22+
yum clean all
23+
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/bin/bash
2+
#
3+
# Copyright (c) 2023 Huawei Technologies Co.,Ltd. All rights reserved.
4+
#
5+
# StratoVirt is licensed under Mulan PSL v2.
6+
# You can use this software according to the terms and conditions of the Mulan
7+
# PSL v2.
8+
# You may obtain a copy of Mulan PSL v2 at:
9+
# http://license.coscl.org.cn/MulanPSL2
10+
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY
11+
# KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
12+
# NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
13+
# See the Mulan PSL v2 for more details.
14+
15+
set -o errexit
16+
set -o nounset
17+
set -o pipefail
18+
19+
build_stratovirt() {
20+
sudo "${container_engine}" run \
21+
--rm -i \
22+
--env ARCH="${ARCH}" \
23+
-v "${repo_root_dir}:/root/stratovirt" \
24+
"${container_image}" \
25+
bash -c "cd /root/stratovirt && ${CARGO} build --workspace --bin stratovirt --release --target=${RUST_TARGET}"
26+
}
27+
28+
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
29+
repo_root_dir="$(cd ${script_dir}/../.. && pwd)"
30+
31+
ARCH=${ARCH:-$(uname -m)}
32+
CARGO="/usr/bin/env CARGO_HOME=.cargo RUSTC_BOOTSTRAP=1 /usr/bin/cargo"
33+
container_engine="${container_engine:-docker}"
34+
container_image="${container_image:-$1}"
35+
36+
if [ "${ARCH}" == "x86_64" ]; then RUST_TARGET="x86_64-unknown-linux-musl"; fi
37+
if [ "${ARCH}" == "aarch64" ]; then RUST_TARGET="aarch64-unknown-linux-musl"; fi
38+
39+
echo "Building StratoVirt with ${RUST_TARGET}"
40+
41+
sudo "${container_engine}" build \
42+
--build-arg ARCH="${ARCH}" \
43+
"${repo_root_dir}" \
44+
-f "${script_dir}/Dockerfile" \
45+
-t "${container_image}" && \
46+
47+
build_stratovirt
48+

0 commit comments

Comments
 (0)