Skip to content

Commit db5744d

Browse files
committed
build: install DADK from the vendored workspace
Share installation and version checks between bootstrap, developer images, and Make. Exercise the vendored install and workspace tests in CI. Signed-off-by: longjin <longjin@dragonos.org>
1 parent f0368a2 commit db5744d

9 files changed

Lines changed: 105 additions & 33 deletions

File tree

‎.github/workflows/dadk.yml‎

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: DADK
2+
3+
on:
4+
push:
5+
branches: ["master", "feat-*", "fix-*"]
6+
paths:
7+
- "tools/dadk/**"
8+
- "tools/install-dadk.sh"
9+
- "tools/bootstrap.sh"
10+
- "tools/Dockerfile"
11+
- "tools/.dockerignore"
12+
- "user/Makefile"
13+
- ".github/workflows/dadk.yml"
14+
pull_request:
15+
branches: ["master", "feat-*", "fix-*"]
16+
paths:
17+
- "tools/dadk/**"
18+
- "tools/install-dadk.sh"
19+
- "tools/bootstrap.sh"
20+
- "tools/Dockerfile"
21+
- "tools/.dockerignore"
22+
- "user/Makefile"
23+
- ".github/workflows/dadk.yml"
24+
25+
jobs:
26+
build-test:
27+
name: Build, test, and format
28+
runs-on: ubuntu-latest
29+
defaults:
30+
run:
31+
working-directory: tools/dadk
32+
steps:
33+
- uses: actions/checkout@v4
34+
35+
- name: Install native TLS build dependencies
36+
working-directory: .
37+
run: |
38+
sudo apt-get update
39+
sudo apt-get install -y --no-install-recommends libssl-dev pkg-config
40+
41+
- name: Install the vendored CLI
42+
run: |
43+
export CARGO_INSTALL_ROOT="$RUNNER_TEMP/dadk-install"
44+
export CARGO_TARGET_DIR="$PWD/target"
45+
export PATH="$CARGO_INSTALL_ROOT/bin:$PATH"
46+
make -C ../../user DADK="$CARGO_INSTALL_ROOT/bin/dadk" install_dadk
47+
make -C ../../user DADK="$CARGO_INSTALL_ROOT/bin/dadk" install_dadk
48+
49+
- name: Test
50+
run: cargo test --workspace --locked
51+
52+
- name: Check formatting
53+
run: cargo fmt --all --check

‎docs/userland/appdev/rust-quick-start.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ cargo generate --git https://git.mirrors.dragonos.org/DragonOS-Community/Rust-Ap
2626
```
2727

2828
4. Use `cargo run` to run the project.
29-
5. In the `user/dadk/config` directory of DragonOS, refer to the template [userapp_config.toml](https://github.com/DragonOS-Community/DADK/blob/main/dadk-config/templates/config/userapp_config.toml) to create a compilation configuration, and install it to the `/` directory of DragonOS.
29+
5. In the `user/dadk/config` directory of DragonOS, refer to the template `tools/dadk/dadk-config/templates/config/userapp_config.toml` to create a compilation configuration, and install it to the `/` directory of DragonOS.
3030
(When using the compilation command options of dadk, please use the `make install` configuration in the Makefile for compilation and installation)
3131
6. Compile DragonOS to install.
3232

‎docs/zh/userland/appdev/rust-quick-start.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ cargo generate --git https://git.mirrors.dragonos.org/DragonOS-Community/Rust-Ap
2626
```
2727

2828
4. 使用`cargo run`来运行项目
29-
5. 在DragonOS的`user/dadk/config`目录下,参考模版[userapp_config.toml](https://github.com/DragonOS-Community/DADK/blob/main/dadk-config/templates/config/userapp_config.toml),创建编译配置,安装到DragonOS的`/`目录下。
29+
5. 在DragonOS的`user/dadk/config`目录下,参考模版 `tools/dadk/dadk-config/templates/config/userapp_config.toml`,创建编译配置,安装到DragonOS的`/`目录下。
3030
(在dadk的编译命令选项处,请使用Makefile里面的`make install`配置进行编译、安装)
3131
6. 编译DragonOS即可安装
3232

‎tools/.dockerignore‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
dadk/target
2+
dadk/docs/node_modules
3+
dadk/docs/.vuepress/dist

‎tools/Cargo.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
members = [
33
"debugging/logmonitor",
44
]
5+
exclude = ["dadk"]
56

67
resolver = "2"

‎tools/Dockerfile‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
1111
# 设置工作目录
1212
WORKDIR /tmp
1313

14-
# 将本地的脚本复制到工作目录
14+
# 将本地的脚本和 dadk 源码复制到工作目录。
15+
# 安装脚本按自身位置寻找 ./dadk,安装结果写入 cargo bin。
1516
COPY *.sh ./
17+
COPY dadk /tmp/dadk
1618

1719
# 设置sudo免密码
1820
RUN apt update && \

‎tools/bootstrap.sh‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -689,8 +689,8 @@ fi
689689
# 安装rust
690690
rustInstall
691691

692-
# 安装dadk
693-
cargo +nightly install --git https://git.mirrors.dragonos.org.cn/DragonOS-Community/DADK.git --tag v0.6.1 --locked || exit 1
692+
# 安装源码树自带的 DADK。
693+
bash "$(dirname -- "${BASH_SOURCE[0]}")/install-dadk.sh" || exit 1
694694

695695
bashpath=$(cd `dirname $0`; pwd)
696696

‎tools/install-dadk.sh‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
dadk_bin=${1:-dadk}
5+
min_version=0.6.1
6+
7+
ready() {
8+
local output core
9+
output=$("$dadk_bin" -V 2>/dev/null) || return 1
10+
[[ $output =~ ^dadk[[:blank:]]+([0-9]+\.[0-9]+\.[0-9]+)(-[0-9A-Za-z.-]+)?(\+[0-9A-Za-z.-]+)?$ ]] || return 1
11+
core=${BASH_REMATCH[1]}
12+
if [[ $core == "$min_version" && -n ${BASH_REMATCH[2]} ]]; then
13+
return 1
14+
fi
15+
[[ $(printf '%s\n' "$core" "$min_version" | sort -V | head -n1) == "$min_version" ]] || return 1
16+
printf '%s\n' "$output"
17+
}
18+
19+
if ready; then
20+
exit 0
21+
fi
22+
23+
script_dir=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)
24+
package_dir="$script_dir/dadk/dadk"
25+
if [[ ! -f $package_dir/Cargo.toml ]]; then
26+
printf 'DADK source is missing at %s\n' "$package_dir" >&2
27+
exit 1
28+
fi
29+
30+
cargo install --path "$package_dir" --locked
31+
if ! ready; then
32+
printf 'DADK installation did not make %s resolve to DADK %s or newer; check DADK and PATH.\n' \
33+
"$dadk_bin" "$min_version" >&2
34+
exit 1
35+
fi

‎user/Makefile‎

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ user_sub_dirs = apps
33
ROOT_PATH ?= $(abspath ..)
44
DADK ?= dadk
55

6-
DADK_VERSION=$(shell dadk -V | awk 'END {print $$2}')
7-
# 最小的DADK版本
8-
MIN_DADK_VERSION = 0.6.1
6+
DADK_BIN = $(or $(strip $(DADK)),dadk)
97
DADK_CACHE_DIR = $(ROOT_PATH)/bin/dadk_cache
108
# 统一使用由 tools/rootfs_manifest_resolve.sh 生成的 manifest
119
DADK_MANIFEST_FILE ?= $(ROOT_PATH)/dadk-manifest.generated.toml
@@ -22,29 +20,9 @@ ECHO:
2220
@echo "$@"
2321

2422

23+
.PHONY: install_dadk
2524
install_dadk:
26-
# 如果未安装
27-
ifeq ("$(DADK_VERSION)", "")
28-
@echo "\ndadk is not installed."
29-
@echo "Please install dadk $(MIN_DADK_VERSION) or higher version"
30-
@echo "\nYou can install dadk by running the following command:"
31-
@echo "\n\tcargo install dadk"
32-
@echo "\nOr you can install dadk from source by running the following command:"
33-
@echo "\n\tcargo install --git https://git.mirrors.dragonos.org.cn/DragonOS-Community/DADK.git --tag v$(MIN_DADK_VERSION) --locked"
34-
@echo "\n"
35-
@echo "Auto installing dadk..."
36-
cargo install --git https://git.mirrors.dragonos.org.cn/DragonOS-Community/DADK.git --tag v$(MIN_DADK_VERSION) --locked
37-
else
38-
# 如果DADK版本过低,则自动更新
39-
@echo "dadk version $(DADK_VERSION) installed"
40-
# 如果DADK版本过低,则自动更新
41-
ifneq ($(shell printf '%s\n%s' "$(DADK_VERSION)" "$(MIN_DADK_VERSION)" | sort -V | head -n1), $(MIN_DADK_VERSION))
42-
@echo "dadk version is too low, please update to $(MIN_DADK_VERSION) or higher version"
43-
@echo "Updating dadk..."
44-
cargo install --git https://git.mirrors.dragonos.org.cn/DragonOS-Community/DADK.git --tag v$(MIN_DADK_VERSION) --locked || (echo "dadk update failed" && exit 1)
45-
@echo "dadk updated"
46-
endif
47-
endif
25+
@bash "$(ROOT_PATH)/tools/install-dadk.sh" "$(DADK_BIN)"
4826

4927
.PHONY: dadk_run
5028
dadk_run: install_dadk
@@ -71,10 +49,10 @@ dadk_run: install_dadk
7149
rm -rf "$(ROOT_PATH)/bin/sysroot"; \
7250
mkdir -p "$(ROOT_PATH)/bin/sysroot"; \
7351
fi; \
74-
$(DADK) -f $(DADK_MANIFEST_FILE) user clean --level output -w $(ROOT_PATH) || true; \
52+
"$(DADK_BIN)" -f $(DADK_MANIFEST_FILE) user clean --level output -w $(ROOT_PATH) || true; \
7553
fi
76-
$(DADK) -f $(DADK_MANIFEST_FILE) user build -w $(ROOT_PATH)
77-
$(DADK) -f $(DADK_MANIFEST_FILE) user install -w $(ROOT_PATH)
54+
"$(DADK_BIN)" -f $(DADK_MANIFEST_FILE) user build -w $(ROOT_PATH)
55+
"$(DADK_BIN)" -f $(DADK_MANIFEST_FILE) user install -w $(ROOT_PATH)
7856
@marker_expected="manifest=$(ROOTFS_MANIFEST);layout=$(SYSROOT_LAYOUT_VERSION)"; \
7957
if [ -f "$(ROOT_PATH)/config/rootfs.generated.toml" ]; then \
8058
rootfs_hash="$$(sha256sum "$(ROOT_PATH)/config/rootfs.generated.toml" | awk '{print $$1}')"; \

0 commit comments

Comments
 (0)