Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add rust support to CI #1966

Merged
merged 1 commit into from
Oct 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 22 additions & 0 deletions .ci/install_rust.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash
#
# Copyright (c) 2019 Ant Financial
#
# SPDX-License-Identifier: Apache-2.0

set -e

[ -n "${KATA_DEV_MODE:-}" ] && exit 0

cidir=$(dirname "$0")
rustarch=$(${cidir}/kata-arch.sh --rust)
release="nightly"

if ! command -v rustup > /dev/null; then
curl https://sh.rustup.rs -sSf | sh
fi

rustup toolchain install ${release}-${rustarch}-unknown-linux-gnu
rustup default ${release}-${rustarch}-unknown-linux-gnu
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might want to add a check for KATA_DEV_MODE to avoid surprising people running this "outside of the CI":

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

rustup target install ${rustarch}-unknown-linux-musl
ln -sf /usr/bin/g++ /bin/musl-g++
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks distro dependent as well

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, it is not

20 changes: 18 additions & 2 deletions .ci/kata-arch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Options:

-d, --default : Show arch(1) architecture (this is the default).
-g, --golang : Show architecture name using golang naming.
-r, --rust : Shoe architecture name using rust naming
-h, --help : Show this help.
-k, --kernel : Show architecture name compatible with Linux* build system.

Expand All @@ -43,6 +44,18 @@ arch_to_golang()
esac
}

# Convert architecture to the name used by rust
arch_to_rust()
{
local arch="$1"

if [ "${arch}" == "ppc64le" ]; then
arch="powerpc64le"
fi

echo "${arch}"
}

# Convert architecture to the name used by the Linux kernel build system
arch_to_kernel()
{
Expand All @@ -69,8 +82,8 @@ main()
local args=$("$getopt_cmd" \
-n "$script_name" \
-a \
--options="dghk" \
--longoptions="default golang help kernel" \
--options="dgrhk" \
--longoptions="default golang rust help kernel" \
-- "$@")

eval set -- "$args"
Expand All @@ -83,6 +96,8 @@ main()

-g|--golang) type="golang";;

-r|--rust) type="rust";;

-h|--help)
usage
exit 0
Expand All @@ -103,6 +118,7 @@ main()
case "$type" in
default) echo "$arch";;
golang) arch_to_golang "$arch";;
rust) arch_to_rust "${arch}";;
kernel) arch_to_kernel "$arch";;
esac
}
Expand Down
24 changes: 24 additions & 0 deletions .ci/setup_env_ubuntu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,25 @@ declare -A packages=( \
[redis]="redis-server" \
)

rust_agent_pkgs=()
rust_agent_pkgs+=("build-essential")
rust_agent_pkgs+=("g++")
rust_agent_pkgs+=("make")
rust_agent_pkgs+=("cmake")
rust_agent_pkgs+=("automake")
rust_agent_pkgs+=("autoconf")
rust_agent_pkgs+=("m4")
rust_agent_pkgs+=("libc6-dev")
rust_agent_pkgs+=("libstdc++-8-dev")
rust_agent_pkgs+=("coreutils")
rust_agent_pkgs+=("binutils")
rust_agent_pkgs+=("debianutils")
rust_agent_pkgs+=("gcc")
rust_agent_pkgs+=("musl")
rust_agent_pkgs+=("musl-dev")
rust_agent_pkgs+=("musl-tools")
rust_agent_pkgs+=("git")

main()
{
local setup_type="$1"
Expand All @@ -63,6 +82,11 @@ main()
done
fi

# packages for rust agent, build on 18.04 or later
if [ ! "${VERSION_ID}" < "18.04" ]; then
pkgs_to_install+=" ${rust_agent_pkgs[@]}"
fi

chronic sudo -E apt -y install $pkgs_to_install

[ "$setup_type" = "minimal" ] && exit 0
Expand Down
32 changes: 27 additions & 5 deletions .ci/static-checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ long_options=(
[files]="Check files"
[force]="Force a skipped test to run"
[golang]="Check '.go' files"
[rust]="Check '.rs' files"
[help]="Display usage statement"
[json]="Check JSON files"
[labels]="Check labels databases"
Expand Down Expand Up @@ -223,6 +224,9 @@ EOT

static_check_go_arch_specific()
{
if [ "${RUST_AGENT:-}" == "yes" ]; then
return
fi
local go_packages
local submodule_packages
local all_packages
Expand Down Expand Up @@ -299,6 +303,17 @@ static_check_go_arch_specific()
eval "$linter" "${linter_args}" "$dirs"
}

static_check_rust_arch_specific()
chavafg marked this conversation as resolved.
Show resolved Hide resolved
{
if [ "${RUST_AGENT:-}" != "yes" ]; then
return
fi

find . -type f -name "*.rs" | egrep -v "target/|grpc-rs/|protocols/" | xargs rustfmt --check > /dev/null 2>&1

[ $? -eq 0 ] || die "crate not formatted by rustfmt."
}

# Check the "versions database".
#
# Some repositories use a versions database to maintain version information
Expand Down Expand Up @@ -381,6 +396,9 @@ static_check_license_headers()
--exclude="*.yml" \
--exclude="go.mod" \
--exclude="go.sum" \
--exclude="*.lock" \
--exclude="grpc-rs/*" \
--exclude="target/*" \
-EL "\<${pattern}\>" \
$files || true)

Expand Down Expand Up @@ -482,7 +500,7 @@ static_check_docs()
local new_urls
local url

all_docs=$(git ls-files "*.md" | grep -v "^vendor/" | sort || true)
all_docs=$(git ls-files "*.md" | grep -v "/\(vendor\|grpc-rs\|target\)/" | sort || true)

if [ "$specific_branch" = "true" ]
then
Expand Down Expand Up @@ -705,7 +723,7 @@ static_check_files()
then
info "Checking all files in $branch branch"

files=$(git ls-files | grep -v "^(.git|vendor)/" || true)
files=$(git ls-files | egrep -v "/(.git|vendor|grpc-rs|target)/" || true)
else
info "Checking local branch for changed files only"

Expand Down Expand Up @@ -773,6 +791,9 @@ static_check_files()
# - Ensure vendor metadata is valid.
static_check_vendor()
{
if [ "${RUST_AGENT:-}" == "yes" ]; then
return
fi
local files
local vendor_files
local result
Expand Down Expand Up @@ -826,7 +847,7 @@ static_check_xml()
local all_xml
local files

all_xml=$(git ls-files "*.xml" | grep -v "^vendor/" | sort || true)
all_xml=$(git ls-files "*.xml" | grep -v "/\(vendor\|grpc-rs\|target\)/" | sort || true)

if [ "$specific_branch" = "true" ]
then
Expand Down Expand Up @@ -878,7 +899,7 @@ static_check_shell()
local all_scripts
local scripts

all_scripts=$(git ls-files "*.sh" "*.bash" | grep -v "^vendor/" | sort || true)
all_scripts=$(git ls-files "*.sh" "*.bash" | grep -v "/\(vendor\|grpc-rs\|target\)/" | sort || true)

if [ "$specific_branch" = "true" ]
then
Expand Down Expand Up @@ -915,7 +936,7 @@ static_check_json()
local all_json
local json_files

all_json=$(git ls-files "*.json" | grep -v "^vendor/" | sort || true)
all_json=$(git ls-files "*.json" | grep -v "/\(vendor\|grpc-rs\|target\)/" | sort || true)

if [ "$specific_branch" = "true" ]
then
Expand Down Expand Up @@ -1025,6 +1046,7 @@ main()
--files) func=static_check_files ;;
--force) force="true" ;;
--golang) func=static_check_go_arch_specific ;;
--rust) func=static_check_rust_arch_specific ;;
-h|--help) usage; exit 0 ;;
--json) func=static_check_json ;;
--labels) func=static_check_labels;;
Expand Down