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 25, 2019
1 parent 701bebf commit 3303173
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 5 deletions.
29 changes: 29 additions & 0 deletions .ci/install_rust.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/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

# rust specific packages
sudo -E apt-get update && apt-get install -y build-essential g++ \
make cmake automake autoconf m4 libc6-dev libstdc++-8-dev coreutils \
binutils debianutils gcc musl musl-dev musl-tools

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++
51 changes: 46 additions & 5 deletions .ci/static-checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,27 @@ static_check_go_arch_specific()
eval "$linter" "${linter_args}" "$dirs"
}

static_check_rust_arch_specific()
{
local -r libs=("rustjail" "oci")
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 +402,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 +506,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 +729,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 @@ -826,7 +850,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 +902,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 +939,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 @@ -1090,6 +1114,23 @@ main()
fi
fi

if [ "${RUST_AGENT:-}" == "yes" ]; then
# skip checks specific to go
if [[ "${func}" =~ "go_arch_specific" ]]; then
continue
fi

if [ "${func}" == "static_check_vendor" ]; then
continue
fi
else
# skip checks specific to rust
if [[ "${func}" =~ "rust_arch_specific" ]]; then
info "Skipping ${func}"
continue
fi
fi

run_or_list_check_function "$func"
done
}
Expand Down

0 comments on commit 3303173

Please sign in to comment.