Skip to content

Commit 88cf46b

Browse files
committed
setup DI
1 parent fc9cafa commit 88cf46b

8 files changed

Lines changed: 337 additions & 6 deletions

File tree

.github/workflows/release.yml

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- '*'
7+
8+
defaults:
9+
run:
10+
shell: bash
11+
12+
jobs:
13+
qa:
14+
runs-on: ubuntu-20.04
15+
steps:
16+
- uses: actions/checkout@v2
17+
18+
- uses: actions-rs/toolchain@v1
19+
with:
20+
toolchain: stable
21+
profile: minimal
22+
components: rustfmt, clippy
23+
override: true
24+
25+
- uses: actions/cache@v3
26+
continue-on-error: false
27+
with:
28+
path: |
29+
~/.cargo/bin/
30+
~/.cargo/registry/index/
31+
~/.cargo/registry/cache/
32+
~/.cargo/git/db/
33+
target/
34+
key: ${{ runner.os }}-cargo-${{ hashFiles('Cargo.lock') }}
35+
36+
- run: |
37+
make qa
38+
39+
build:
40+
needs:
41+
- qa
42+
runs-on: ${{ matrix.platform.on }}
43+
name: ${{ matrix.platform.name }}
44+
strategy:
45+
fail-fast: false
46+
matrix:
47+
platform:
48+
- { on: ubuntu-20.04, name: linux-amd64, target: x86_64-unknown-linux-musl }
49+
- { on: ubuntu-20.04, name: freebsd-amd64, target: x86_64-unknown-freebsd }
50+
- { on: macos-11, name: darwin-amd64, target: x86_64-apple-darwin }
51+
- { on: macos-11, name: darwin-arm64, target: aarch64-apple-darwin }
52+
- { on: windows-2022, name: windows-amd64, target: x86_64-pc-windows-gnu }
53+
54+
steps:
55+
- uses: actions/checkout@v2
56+
57+
- uses: actions-rs/toolchain@v1
58+
with:
59+
toolchain: stable
60+
target: ${{ matrix.platform.target }}
61+
profile: minimal
62+
override: true
63+
64+
- uses: actions/cache@v3
65+
continue-on-error: false
66+
with:
67+
path: |
68+
~/.cargo/bin/
69+
~/.cargo/registry/index/
70+
~/.cargo/registry/cache/
71+
~/.cargo/git/db/
72+
target/
73+
key: ${{ runner.os }}-cargo-release-${{ hashFiles('Cargo.lock') }}
74+
75+
- run: |
76+
make release
77+
tar -czvf sold-${{ github.ref_name }}-${{ matrix.platform.name }}.tar.gz -C release sold*
78+
79+
- uses: actions/upload-artifact@v3
80+
with:
81+
name: sold-${{ github.ref_name }}-${{ matrix.platform.name }}
82+
path: |
83+
release/sold*
84+
85+
- uses: softprops/action-gh-release@v1
86+
if: ${{ startsWith(github.ref, 'refs/tags/') }}
87+
with:
88+
draft: false
89+
files: |
90+
sold-${{ github.ref_name }}-${{ matrix.platform.name }}.tar.gz
91+
prerelease: false
92+
env:
93+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ build/
22
sold/target/
33
target/
44
.idea/
5+
.deps-ready
6+
release

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@
22
members = [
33
'sold'
44
]
5+
6+
[profile.release]
7+
strip = true # Automatically strip symbols from the binary.

Makefile

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
UNAME := $(shell uname)
2+
3+
ifeq ($(UNAME), win)
4+
TARGET = sold.exe
5+
else
6+
TARGET = sold
7+
endif
8+
9+
.deps-ready:
10+
bash script/toolchain.sh -s
11+
touch .deps-ready
12+
13+
clean:
14+
rm -fr release
15+
cargo clean
16+
17+
test: .deps-ready
18+
cargo test
19+
20+
fmt:
21+
cargo fmt
22+
23+
lint: .deps-ready
24+
cargo fmt --all -- --check
25+
cargo clippy --all-targets
26+
27+
qa: lint test
28+
29+
target/release/$(TARGET): .deps-ready
30+
cargo build --release
31+
32+
release: target/release/$(TARGET)
33+
mkdir -p release
34+
cp target/release/$(TARGET) release/
35+

compiler/scripts/install_deps.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,14 @@ case $(uname -s) in
9393
10.15)
9494
echo "Installing solidity dependencies on macOS 10.15 Catalina."
9595
;;
96-
11.0 | 11.1 | 11.2 | 11.3 | 11.4)
97-
echo "Installing solidity dependencies on macOS 11.0 / 11.1 / 11.2 / 11.3 / 11.4 Big Sur."
96+
11.*)
97+
echo "Installing solidity dependencies on macOS 11.x Big Sur."
9898
;;
9999
12.*)
100100
echo "Installing solidity dependencies on macOS 12 Monterey."
101101
;;
102102
*)
103-
echo "Unsupported macOS version."
103+
echo "Unsupported macOS version: $(sw_vers -productVersion)"
104104
echo "We only support Mavericks, Yosemite, El Capitan, Sierra, High Sierra, Mojave, Catalina, Big Sur and Monterey."
105105
exit 1
106106
;;
@@ -177,7 +177,7 @@ case $(uname -s) in
177177
Debian*)
178178
#Debian
179179
. /etc/os-release
180-
180+
181181
# Install "normal packages"
182182
sudo apt-get -y update
183183
sudo apt-get -y install \
@@ -254,7 +254,7 @@ case $(uname -s) in
254254
Ubuntu|LinuxMint)
255255
#LinuxMint is a distro on top of Ubuntu.
256256
#Ubuntu
257-
257+
258258
sudo apt-get -y update
259259
sudo apt-get -y install \
260260
build-essential \

script/toolchain.sh

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
#!/usr/bin/env bash
2+
3+
set -o errexit
4+
5+
projectDir=$(cd "$(dirname "${0}")/.." && pwd)
6+
# shellcheck source=script/util.sh
7+
source "${projectDir}/script/util.sh" || source ./util.sh
8+
9+
usage() {
10+
println "POSIX-compliant bash script to manage toolchain for develop project"
11+
println "Usage: ${0} <option>"
12+
println "Options:"
13+
println " -h this help"
14+
println " -x enable debug mode (trace per command line in scripts)"
15+
println " -c check requirements for environment"
16+
println " -s setup environment ENV_TYPE=${ENV_TYPE}"
17+
}
18+
19+
commonSetup() {
20+
info "setup common"
21+
}
22+
23+
debianSetup() {
24+
info "setup for platform debian"
25+
sudo apt-get update
26+
info "Installing libs for build project"
27+
sudo apt-get install -qq -y \
28+
build-essential \
29+
cmake \
30+
g++ \
31+
gcc \
32+
libboost-all-dev \
33+
unzip \
34+
curl \
35+
libclang-dev
36+
commonSetup
37+
}
38+
39+
macosSetup() {
40+
info "setup for platform macos"
41+
checkCommand brew "Requires a Homebrew install, see https://brew.sh"
42+
brew update
43+
brew install boost
44+
brew install cmake
45+
brew install curl
46+
if [ "$CI" = true ]; then
47+
brew upgrade cmake
48+
fi
49+
commonSetup
50+
}
51+
52+
windowsSetup() {
53+
info "setup for platform windows"
54+
tryCommand make || choco install -y make
55+
tryCommand curl || choco install -y curl
56+
tryCommand cmake || choco install -y cmake
57+
cmake -P "${projectDir}/compiler/scripts/install_deps.cmake"
58+
commonSetup
59+
}
60+
61+
checkRequirements() {
62+
tryCommand git && git --version
63+
tryCommand cargo && cargo --version
64+
tryCommand make && println "make $(make --version | grep Make | cut -d" " -f3)"
65+
}
66+
67+
checkEnvironment() {
68+
printENV
69+
tryCommand bash && println "bash ${BASH_VERSION}"
70+
checkRequirements
71+
}
72+
73+
setupEnvironment() {
74+
checkRequirements
75+
76+
case "$OS_FAMILY" in
77+
debian) debianSetup ;;
78+
macos) macosSetup ;;
79+
windows) windowsSetup ;;
80+
*) notReady "setup toolchain" ;;
81+
esac
82+
}
83+
84+
main() {
85+
if [ "$(id -u)" == "0" ]; then fatal "Not running as root"; fi
86+
if [ -z "$*" ]; then usage; fi
87+
88+
cmd=
89+
while getopts ":hxsc" flag; do
90+
case "${flag}" in
91+
x) set -o xtrace ;;
92+
s) cmd=setupEnvironment ;;
93+
c) cmd=checkEnvironment ;;
94+
?) usage ;;
95+
esac
96+
done
97+
98+
${cmd}
99+
}
100+
101+
main "$*"

script/util.sh

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
#!/usr/bin/env bash
2+
3+
set -o errexit
4+
5+
lowercase() { printf "%s" "${1}" | tr '[:upper:]' '[:lower:]'; }
6+
println() { printf "%s\n" "${*}"; }
7+
info() { println "[INFO] ${1}"; }
8+
error() { println "[ERROR] ${1}"; }
9+
warning() { println "[WARNING] ${1}"; }
10+
unsupported() { warning "${1} not supported"; }
11+
notImplemented() { warning "${1} is not yet implemented on ${OS_FAMILY}/${ENV_TYPE} environment"; }
12+
13+
fatal() {
14+
if [ -n "${1}" ]; then
15+
println "[FATAL] ${1}"
16+
fi
17+
exit 1
18+
}
19+
20+
notReady() {
21+
printENV
22+
notImplemented "${1}"
23+
exit 1
24+
}
25+
26+
checkCommand() {
27+
if ! [ -x "$(command -v "${1}")" ]; then
28+
if [ -n "${2}" ]; then
29+
info "${2}"
30+
fi
31+
fatal "'${1}' is not installed."
32+
fi
33+
}
34+
35+
checkPOSIX() {
36+
checkCommand uname
37+
checkCommand id
38+
checkCommand cut
39+
checkCommand grep
40+
checkCommand tr
41+
}
42+
43+
tryCommand() {
44+
if ! [ -x "$(command -v "${1}")" ]; then
45+
println "'${1}' is not installed."
46+
fi
47+
}
48+
49+
printPlatform() {
50+
println "KERNEL: ${KERNEL}"
51+
println "OS: ${OS}"
52+
println "OS_FAMILY: ${OS_FAMILY}"
53+
}
54+
55+
printENV() {
56+
printPlatform
57+
println "ENV_TYPE: ${ENV_TYPE}"
58+
}
59+
60+
detectPlatform() {
61+
ENV_TYPE=${ENV_TYPE:-destop}
62+
KERNEL=$(lowercase "$(uname -a 2>/dev/null)" || printf unknown)
63+
KERNEL_NAME=$(lowercase "$(uname -s 2>/dev/null)" || printf unknown)
64+
OS=unknown
65+
OS_FAMILY=unknown
66+
67+
case "$KERNEL_NAME" in
68+
darwin*)
69+
OS=darwin
70+
OS_FAMILY=macos
71+
;;
72+
linux*)
73+
OS=linux
74+
if [ -f /etc/os-release ]; then
75+
OS_FAMILY=$(grep </etc/os-release '^ID_LIKE' | cut -d= -f2)
76+
if [ -z "${OS_FAMILY}" ]; then
77+
OS_FAMILY=$(grep </etc/os-release '^ID' | cut -d= -f2)
78+
fi
79+
fi
80+
;;
81+
cygwin* | mingw32* | msys* | mingw* | win*)
82+
OS=windows
83+
OS_FAMILY=windows
84+
;;
85+
*)
86+
OS=$(uname -a 2>/dev/null || printf unknown)
87+
;;
88+
esac
89+
OS_FAMILY=$(lowercase "$OS_FAMILY")
90+
91+
export KERNEL
92+
export ENV_TYPE
93+
export OS
94+
export OS_FAMILY
95+
}
96+
97+
checkPOSIX
98+
detectPlatform

sold/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,3 @@ predicates = '2.1.1'
3232
[lib]
3333
name = 'sold_lib'
3434
path = 'src/lib.rs'
35-

0 commit comments

Comments
 (0)