Skip to content

Commit

Permalink
ci: Add rust support to CI
Browse files Browse the repository at this point in the history
This patch adds preliminary support to rust agent.

Fixes: #1965

Signed-off-by: Yang Bo <bo@hyper.sh>
  • Loading branch information
yyyeerbo committed Sep 26, 2019
1 parent 701bebf commit 0ea3ee6
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 5 deletions.
24 changes: 24 additions & 0 deletions .ci/install_rust.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash
#
# Copyright (c) 2019 Ant Financial
#
# SPDX-License-Identifier: Apache-2.0

set -e

cidir=$(dirname "$0")
rustarch=$(uname -m)
release="nightly"

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

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
rustup target install ${rustarch}-unknown-linux-musl
ln -sf /usr/bin/g++ /bin/musl-g++
1 change: 1 addition & 0 deletions .ci/setup_env_ubuntu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ declare -A minimal_packages=( \
[spell-check]="hunspell hunspell-en-gb hunspell-en-us pandoc" \
[xml_validator]="libxml2-utils" \
[yaml_validator]="yamllint" \
[rust-agent]="build-essential g++ make cmake automake autoconf m4 libc6-dev libstdc++-8-dev coreutils binutils debianutils gcc musl musl-dev musl-tools git" \
)

declare -A packages=( \
Expand Down
43 changes: 38 additions & 5 deletions .ci/static-checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,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 +302,30 @@ static_check_go_arch_specific()
eval "$linter" "${linter_args}" "$dirs"
}

static_check_rust_arch_specific()
{
if [ "${RUST_AGENT:-}" != "yes" ]; then
return
fi
local -r libs=${RUST_LIBS:-}
local -r bins=(".")
for lib in ${libs[@]}; do
rustfmt --check ${lib}/src/lib.rs > /dev/null 2>&1
if [ $? -ne 0 ]; then
die "library crate ${lib} is not formatted by rustfmt.
use \"rustfmt ${lib}/src/lib.rs\" to format the code."
fi
done

for bin in ${bins[@]}; do
rustfmt --check ${bin}/src/main.rs > /dev/null 2>&1
if [ $? -ne 0 ]; then
die "binary crate ${bin} is not formatted by rustfmt.
use \"rustfmt ${bin}/src/main.rs\" to format the code."
fi
done
}

# Check the "versions database".
#
# Some repositories use a versions database to maintain version information
Expand Down Expand Up @@ -381,6 +408,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 +512,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 +735,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 +803,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 +859,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 +911,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 +948,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

0 comments on commit 0ea3ee6

Please sign in to comment.