diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000000..851fa44c43 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,5 @@ +{ + "image": "gcr.io/crosvm-packages/crosvm_dev:latest", + "extensions": [ + ] +} diff --git a/tools/dev_container b/tools/dev_container new file mode 100755 index 0000000000..b98d73bccf --- /dev/null +++ b/tools/dev_container @@ -0,0 +1,27 @@ +#!/usr/bin/env bash +# Copyright 2021 The Chromium OS Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +set -e +cd "$(dirname $0)/.." + +docker_args=( + --rm + --volume $(pwd):/workspace:rw + --device /dev/net/tun + --device /dev/kvm + --volume /dev/log:/dev/log + --privileged +) + +# Enable interactive mode when running in an interactive terminal. +if [ -t 1 ]; then + docker_args+=(-it) +fi + +docker run \ + ${docker_args[@]} \ + gcr.io/crosvm-packages/crosvm_dev:$(cat tools/impl/dev_container/version) \ + "$@" + diff --git a/tools/impl/dev_container/Dockerfile b/tools/impl/dev_container/Dockerfile new file mode 100644 index 0000000000..3e2beae607 --- /dev/null +++ b/tools/impl/dev_container/Dockerfile @@ -0,0 +1,43 @@ +# Copyright 2021 The Chromium OS Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. +ARG RUST_VERSION +FROM docker.io/rust:${RUST_VERSION}-slim-bullseye + +# Use a dedicated target directory so we do not write into the source directory. +RUN mkdir -p /scratch/cargo_target +ENV CARGO_TARGET_DIR=/scratch/cargo_target + +# Prevent the container from writing root-owned __pycache__ files into the src. +ENV PYTHONDONTWRITEBYTECODE=1 + +# Add foreign architectures for cross-compilation. +RUN dpkg --add-architecture arm64 \ + && dpkg --add-architecture armhf + +# Install dependencies for native builds. +COPY tools/install-deps /tools/ +RUN apt-get update \ + && apt-get install --yes sudo \ + && /tools/install-deps \ + # Clear apt cache to save space in layer. + && rm -rf /var/lib/apt/lists/* \ + # Delete build artifacts from 'cargo install' to save space in layer. + && rm -rf /scratch/cargo_target/* + +# Install cross-compilation dependencies. +COPY tools/install-aarch64-deps tools/install-armhf-deps /tools/ +RUN apt-get update \ + && /tools/install-aarch64-deps \ + && /tools/install-armhf-deps \ + # Clear apt cache to save space in layer. + && rm -rf /var/lib/apt/lists/* + +# Prebuild aarch64 VM image for faster startup. +COPY tools/aarch64vm /tools/ +COPY /tools/impl/testvm.py /tools/impl/ +COPY /tools/impl/testvm/version /tools/impl/testvm/ +RUN /tools/aarch64vm build + +VOLUME /workspace +WORKDIR /workspace diff --git a/tools/impl/dev_container/Makefile b/tools/impl/dev_container/Makefile new file mode 100644 index 0000000000..85afa5d3f1 --- /dev/null +++ b/tools/impl/dev_container/Makefile @@ -0,0 +1,36 @@ +# Copyright 2021 The Chromium OS Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. +# +# To locally build the docker container for usage with dev_container: +# +# make -C tools/impl/dev_container crosvm_dev +# +# To upload a new version of the container, uprev the `version` file and run; +# +# make -C tools/impl/dev_container upload +# +# You need write permission to the crosvm-packages cloud registry to do so. + +export DOCKER_BUILDKIT=1 + +TAG_BASE=gcr.io/crosvm-packages +VERSION=$(shell cat version) +RUST_VERSION=$(shell cat ../../../rust-toolchain) +BUILD_CONTEXT=$(shell realpath ../../../) + +DOCKER ?= docker + +all: crosvm_dev + +upload: all + $(DOCKER) push $(TAG_BASE)/crosvm_dev:$(VERSION) + +crosvm_dev: + $(DOCKER) build \ + --build-arg RUST_VERSION=$(RUST_VERSION) \ + -t $(TAG_BASE)/$@:$(VERSION) \ + -f Dockerfile \ + $(BUILD_CONTEXT) + +.PHONY: all crosvm_dev upload diff --git a/tools/impl/dev_container/version b/tools/impl/dev_container/version new file mode 100644 index 0000000000..75d30fb532 --- /dev/null +++ b/tools/impl/dev_container/version @@ -0,0 +1 @@ +r0001 diff --git a/tools/install-aarch64-deps b/tools/install-aarch64-deps new file mode 100755 index 0000000000..69d92ca181 --- /dev/null +++ b/tools/install-aarch64-deps @@ -0,0 +1,28 @@ +#!/usr/bin/env bash +# Copyright 2021 The Chromium OS Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. +set -ex + +sudo apt-get install --yes --no-install-recommends \ + g++-aarch64-linux-gnu \ + gcc-aarch64-linux-gnu \ + ipxe-qemu \ + libc-dev:arm64 \ + libcap-dev:arm64 \ + libdbus-1-dev:arm64 \ + libdrm-dev:arm64 \ + libepoxy-dev:arm64 \ + libssl-dev:arm64 \ + libwayland-dev:arm64 \ + libxext-dev:arm64 \ + qemu-efi-aarch64 \ + qemu-system-aarch64 \ + qemu-user-static + +rustup target add aarch64-unknown-linux-gnu + +# Generate a cross file for meson to compile for aarch64 +sudo mkdir -p -m 0755 /usr/local/share/meson/cross +sudo /usr/share/meson/debcrossgen --arch arm64 \ + -o /usr/local/share/meson/cross/aarch64 diff --git a/tools/install-armhf-deps b/tools/install-armhf-deps new file mode 100755 index 0000000000..cb06f07bf2 --- /dev/null +++ b/tools/install-armhf-deps @@ -0,0 +1,24 @@ +#!/usr/bin/env bash +# Copyright 2021 The Chromium OS Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. +set -ex + +sudo apt-get install --yes --no-install-recommends \ + g++-arm-linux-gnueabihf \ + gcc-arm-linux-gnueabihf \ + libc-dev:armhf \ + libcap-dev:armhf \ + libdbus-1-dev:armhf \ + libdrm-dev:armhf \ + libepoxy-dev:armhf \ + libssl-dev:armhf \ + libwayland-dev:armhf \ + libxext-dev:armhf + +rustup target add armv7-unknown-linux-gnueabihf + +# Generate a cross file for meson to compile for armhf +sudo mkdir -p -m 0755 /usr/local/share/meson/cross +sudo /usr/share/meson/debcrossgen --arch armhf \ + -o /usr/local/share/meson/cross/armhf diff --git a/tools/install-deps b/tools/install-deps new file mode 100755 index 0000000000..00d96361b4 --- /dev/null +++ b/tools/install-deps @@ -0,0 +1,48 @@ +#!/usr/bin/env bash +# Copyright 2021 The Chromium OS Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. +set -ex + +sudo apt-get install --yes --no-install-recommends \ + ca-certificates \ + clang \ + cloud-image-utils \ + curl \ + dpkg-dev \ + expect \ + g++ \ + gcc \ + git \ + jq \ + libasound2-dev \ + libcap-dev \ + libclang-dev \ + libdbus-1-dev \ + libdrm-dev \ + libepoxy-dev \ + libssl-dev \ + libwayland-dev \ + libxext-dev \ + make \ + meson \ + nasm \ + ninja-build \ + openssh-client \ + pkg-config \ + protobuf-compiler \ + python3 \ + python3-setuptools \ + qemu-system-x86 \ + rsync \ + screen \ + wayland-protocols + + +# The bindgen tool is required to build a crosvm dependency. +cargo install bindgen + +# The mdbook and mdbook-mermaid tools are used to build the crosvm book. +cargo install mdbook --no-default-features --version "^0.4.10" +cargo install mdbook-mermaid --version "^0.8.3" +