Skip to content

Commit 5107c8c

Browse files
authored
Merge branch 'main' into add_xqci
2 parents 637fcf9 + 55e2cf1 commit 5107c8c

File tree

5 files changed

+175
-65
lines changed

5 files changed

+175
-65
lines changed

.devcontainer/Dockerfile

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,26 @@
1-
FROM ubuntu:24.04 AS spython-base
1+
FROM ubuntu:24.04
2+
3+
ENV DEBIAN_FRONTEND=noninteractive
4+
5+
WORKDIR /workspace
6+
27
RUN export DEBIAN_FRONTEND=noninteractive
38
RUN apt-get update
49
RUN apt-get install -y --no-install-recommends git gh
510
RUN apt-get install -y --no-install-recommends less
611
RUN apt-get install -y --no-install-recommends python3
7-
RUN apt-get install -y --no-install-recommends python3.12-venv python3-pip
12+
RUN apt-get install -y --no-install-recommends python3.12-venv
13+
RUN apt-get install -y --no-install-recommends python3-pip
814
RUN apt-get install -y --no-install-recommends build-essential
9-
RUN apt-get install -y --no-install-recommends ruby ruby-dev
15+
RUN apt-get install -y --no-install-recommends ruby
16+
RUN apt-get install -y --no-install-recommends ruby-dev
1017
RUN apt-get install -y --no-install-recommends bundler
1118
RUN apt-get install -y --no-install-recommends nodejs
1219
RUN apt-get install -y --no-install-recommends npm
1320
RUN apt-get install -y --no-install-recommends ditaa
1421
RUN apt-get install -y --no-install-recommends libyaml-dev
1522
RUN apt-get clean autoclean
1623
RUN apt-get autoremove -y
17-
RUN rm -rf /var/lib/{apt, dpkg, cache, log}
24+
RUN rm -rf /var/lib/{apt,dpkg,cache,log}/*
25+
26+
WORKDIR /workspace

.github/workflows/nightly.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ jobs:
2626
needs: check_date
2727
if: ${{ needs.check_date.outputs.should_run != 'false' }}
2828
runs-on: ubuntu-latest
29+
env:
30+
SINGULARITY: 1
2931
steps:
3032
- name: Clone Github Repo Action
3133
uses: actions/checkout@v4

.github/workflows/regress.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ jobs:
1313
- uses: pre-commit/[email protected]
1414
regress-smoke:
1515
runs-on: ubuntu-latest
16+
env:
17+
SINGULARITY: 1
1618
steps:
1719
- name: Clone Github Repo Action
1820
uses: actions/checkout@v4
@@ -45,6 +47,7 @@ jobs:
4547
env:
4648
MANUAL_NAME: isa
4749
VERSIONS: all
50+
SINGULARITY: 1
4851
steps:
4952
- name: Clone Github Repo Action
5053
uses: actions/checkout@v4
@@ -75,6 +78,7 @@ jobs:
7578
env:
7679
EXT: B
7780
VERSION: latest
81+
SINGULARITY: 1
7882
steps:
7983
- name: Clone Github Repo Action
8084
uses: actions/checkout@v4
@@ -102,6 +106,8 @@ jobs:
102106
regress-gen-certificate:
103107
runs-on: ubuntu-latest
104108
needs: regress-smoke
109+
env:
110+
SINGULARITY: 1
105111
steps:
106112
- name: Clone Github Repo Action
107113
uses: actions/checkout@v4
@@ -129,6 +135,8 @@ jobs:
129135
regress-gen-profile:
130136
runs-on: ubuntu-latest
131137
needs: regress-smoke
138+
env:
139+
SINGULARITY: 1
132140
steps:
133141
- name: Clone Github Repo Action
134142
uses: actions/checkout@v4

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
.stamps
88
.venv
99
.asciidoctor
10+
.container-type
1011
diag-ditaa-*
1112
arch/manual/isa/**/riscv-isa-manual
1213
gen

bin/setup

Lines changed: 151 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -6,104 +6,194 @@ cd $ROOT
66

77
CONTAINER_TAG=`cat ${ROOT}/bin/.container-tag`
88

9+
# Supported container types:
10+
#
11+
# = devcontainer
12+
#
13+
# When devcontainer is used, all commands run "natively" (no container prefix), because it's assumed
14+
# that the command itself is already in the container context
15+
#
16+
# = docker
17+
#
18+
# A docker container. All commands on the host (using ./do or ./bin/*) are run in the context of a Docker image.
19+
#
20+
# = singularity
21+
#
22+
# An apptainer/singularity container. All commands on the host (using ./do or ./bin/*) are run in the context of an Apptainer/Singularity image.
23+
#
24+
#
25+
# ALL THREE CONTAINERS ARE IDENTICAL. Which one you use is a preference of your setup and installed
26+
# software.
27+
28+
29+
# get the container type
30+
#
31+
# use, in priority order:
32+
# 1. devcontainer, if DEVCONTAINER_ENV is set in the enviornment
33+
# 2. the type stored in .container-type
34+
# 3. Docker, if DOCKER is set in the enviornment
35+
# 4. Singularity, if SINGULARITY is set in the enviornment
36+
# 5. The choice made by the user, which will be cached in .container-type
37+
if [ -v DEVCONTAINER_ENV ]; then
38+
CONTAINER_TYPE=devcontainer
39+
elif [ -f ${ROOT}/.container-type ]; then
40+
CONTAINER_TYPE=`cat ${ROOT}/.container-type`
41+
elif [ -v DOCKER ]; then
42+
CONTAINER_TYPE=docker
43+
elif [ -v SINGULARITY ]; then
44+
CONTAINER_TYPE=singularity
45+
else
46+
echo -e "UDB tools run in a container. Both Docker and Singularity/Apptainer are supported.\\n\\n1. Docker\\n2. Singularity\\n"
47+
while true; do
48+
echo "Which would you like to use? (1/2) "
49+
read ans
50+
case $ans in
51+
[1]* ) CONTAINER_TYPE=docker; break;;
52+
[2]* ) CONTAINER_TYPE=singularity; break;;
53+
* ) echo -e "\\nPlease answer 1 or 2.";;
54+
esac
55+
done
56+
fi
57+
58+
if [ "${CONTAINER_TYPE}" != "docker" -a "${CONTAINER_TYPE}" != "singularity" ]; then
59+
echo "BAD CONTAINER TYPE: ${CONTAINER_TYPE}"
60+
fi
61+
62+
if [ ! -f ${ROOT}/.container-type ]; then
63+
echo ${CONTAINER_TYPE} > ${ROOT}/.container-type
64+
fi
65+
66+
print_env() {
67+
if [ "${CONTAINER_TYPE}" == "docker" ]; then
68+
echo "Using Docker environment"
69+
else
70+
echo "Using Singularity environment"
71+
fi
72+
}
73+
974
if [ -v GITHUB_ACTIONS ]; then
10-
echo "ACTIONS"
11-
CONTAINER_PATH=${ROOT}/.singularity/image.sif
12-
HOME_PATH=${GITHUB_WORKSPACE}
13-
HOME_OPT="--home ${ROOT}/.home"
14-
SINGULARITY_CACHE=--disable-cache
75+
echo "ACTIONS"
76+
CONTAINER_PATH=${ROOT}/.singularity/image.sif
77+
HOME_PATH=${GITHUB_WORKSPACE}
78+
HOME_OPT="--home ${ROOT}/.home"
79+
SINGULARITY_CACHE=--disable-cache
80+
elif [ "${CONTAINER_TYPE}" == "docker" ]; then
81+
print_env
82+
if ! docker images riscvintl/udb:${CONTAINER_TAG} | grep -q udb ; then
83+
# TODO: pull the image if it can be found
84+
echo "Building Docker image..."
85+
docker build -t riscvintl/udb:${CONTAINER_TAG} -f .devcontainer/Dockerfile .
86+
fi
87+
if [ -t 1 -a -t 0 ]; then
88+
DOCKER_BASE="docker run -it -v $(ROOT):$(ROOT) -w $(ROOT) riscvintl/udb:${CONTAINER_TAG}"
89+
else
90+
DOCKER_BASE="docker run -v $(ROOT):$(ROOT) -w $(ROOT) riscvintl/udb:${CONTAINER_TAG}"
91+
fi
92+
RUN="${DOCKER_BASE}"
1593
else
16-
CONTAINER_PATH=${ROOT}/.singularity/image-$CONTAINER_TAG.sif
17-
HOME_PATH=${HOME}
18-
HOME_OPT="--bind ${ROOT}/.home:${HOME_PATH} --bind /local/mnt/workspace/.vscode-server:/local/mnt/workspace/.vscode-server"
19-
SINGULARITY_CACHE=
94+
print_env
95+
CONTAINER_PATH=${ROOT}/.singularity/image-$CONTAINER_TAG.sif
96+
HOME_PATH=${HOME}
97+
HOME_OPT="--bind ${ROOT}/.home:${HOME_PATH}"
98+
SINGULARITY_CACHE=
99+
if [ ! -f ${CONTAINER_PATH} ]; then
100+
echo "Fetching container..."
101+
if [ ! -d "${ROOT}/.singularity" ]; then
102+
mkdir -p ${ROOT}/.singularity
103+
fi
104+
singularity pull ${SINGULARITY_CACHE} ${CONTAINER_PATH} oras://docker.io/riscvintl/spec-generator:$CONTAINER_TAG
105+
fi
20106
fi
21107

22108
if [ -f $ROOT/.git ]; then
23-
# if this is a worktree, need to add the parent git repo in, too
24-
GIT_PATH=`git rev-parse --git-common-dir | tr -d '\n' | xargs dirname`
25-
HOME_OPT="${HOME_OPT} --bind ${GIT_PATH}:${GIT_PATH}"
109+
# if this is a worktree, need to add the parent git repo in, too
110+
GIT_PATH=`git rev-parse --git-common-dir | tr -d '\n' | xargs dirname`
111+
HOME_OPT="${HOME_OPT} --bind ${GIT_PATH}:${GIT_PATH}"
26112
fi
27113

28114
if [ -v DEVCONTAINER_ENV ]; then
29-
RUN=""
115+
RUN=""
116+
elif [ "${CONTAINER_TYPE}" == "docker" ]; then
117+
RUN="${DOCKER_BASE}"
30118
else
31-
RUN="singularity run ${HOME_OPT} ${CONTAINER_PATH} "
119+
RUN="singularity run ${HOME_OPT} ${CONTAINER_PATH}"
32120
fi
33121

34122
if [ ! -d $ROOT/.home ]; then
35-
mkdir $ROOT/.home
36-
fi
37-
38-
if [ ! -v DEVCONTAINER_ENV ]; then
39-
if [ ! -f ${CONTAINER_PATH} ]; then
40-
echo "Fetching container..."
41-
if [ ! -d "${ROOT}/.singularity" ]; then
42-
mkdir -p ${ROOT}/.singularity
43-
fi
44-
singularity pull ${SINGULARITY_CACHE} ${CONTAINER_PATH} oras://docker.io/riscvintl/spec-generator:$CONTAINER_TAG
45-
fi
123+
mkdir $ROOT/.home
46124
fi
47125

48126
if [ ! -f $ROOT/.bundle/config ]; then
49-
OLDDIR=$PWD
50-
cd $ROOT
51-
${RUN} bundle config set --local path ${ROOT}/.home/.gems
52-
${RUN} bundle config set --local cache_path ${ROOT}/.home/.cache
53-
cd $OLDDIR
127+
OLDDIR=$PWD
128+
cd $ROOT
129+
${RUN} bundle config set --local path ${ROOT}/.home/.gems
130+
${RUN} bundle config set --local cache_path ${ROOT}/.home/.cache
131+
cd $OLDDIR
54132
fi
55133

56134
if [ ! -d $ROOT/.home/.gems ]; then
57-
OLDDIR=$PWD
58-
cd $ROOT
59-
${RUN} bundle install
60-
cd $OLDDIR
135+
OLDDIR=$PWD
136+
cd $ROOT
137+
${RUN} bundle install
138+
cd $OLDDIR
61139
fi
62140

63141
if [ ! -d $ROOT/.home/.venv ]; then
64-
${RUN} /usr/bin/python3 -m venv ${ROOT}/.home/.venv
142+
${RUN} /usr/bin/python3 -m venv ${ROOT}/.home/.venv
65143
fi
144+
66145
source ${ROOT}/.home/.venv/bin/activate
146+
67147
if [ ! -f ${ROOT}/.home/.venv/bin/pre-commit ]; then
68-
${RUN} ${ROOT}/.home/.venv/bin/pip install -r requirements.txt
148+
${RUN} ${ROOT}/.home/.venv/bin/pip install -r requirements.txt
69149
fi
70150

71151
# if [ ! -f $ROOT/ext/riscv-opcodes/README.md ]; then
72152
# git submodule update --init ext/riscv-opcodes
73153
# fi
74154

75155
if [[ ! -z "$DEVELOPMENT" && $DEVELOPMENT -eq 1 ]]; then
76-
if [ ! -d "${ROOT}/.home/.yard/gem_index"]; then
77-
${RUN} bundle exec --gemfile ${ROOT}/Gemfile yard config --gem-install-yri
78-
${RUN} bundle exec --gemfile ${ROOT}/Gemfile yard gems
79-
touch ${ROOT}/.stamps/dev_gems
80-
fi
156+
if [ ! -d "${ROOT}/.home/.yard/gem_index"]; then
157+
${RUN} bundle exec --gemfile ${ROOT}/Gemfile yard config --gem-install-yri
158+
${RUN} bundle exec --gemfile ${ROOT}/Gemfile yard gems
159+
touch ${ROOT}/.stamps/dev_gems
160+
fi
81161
fi
82162

83163
if [ ! -d ${ROOT}/node_modules ]; then
84-
${RUN} npm i
164+
${RUN} npm i
85165
fi
86166

87167
if [ -v DEVCONTAINER_ENV ]; then
88-
BUNDLE="bundle"
89-
RUBY="bundle exec ruby"
90-
RAKE="bundle exec rake"
91-
NPM="npm"
92-
NPX="npx"
93-
NODE="node"
94-
PYTHON="${ROOT}/.home/.venv/bin/python3"
95-
PIP="${ROOT}/.home/.venv/bin/pip"
96-
BASH="bash"
168+
BUNDLE="bundle"
169+
RUBY="bundle exec ruby"
170+
RAKE="bundle exec rake"
171+
NPM="npm"
172+
NPX="npx"
173+
NODE="node"
174+
PYTHON="${ROOT}/.home/.venv/bin/python3"
175+
PIP="${ROOT}/.home/.venv/bin/pip"
176+
BASH="bash"
177+
elif [ "${CONTAINER_TYPE}" == "docker" ]; then
178+
BUNDLE="${DOCKER_BASE} bundle"
179+
RUBY="${DOCKER_BASE} bundle exec ruby"
180+
RAKE="${DOCKER_BASE} bundle exec rake"
181+
NPM="${DOCKER_BASE} npm"
182+
NPX="${DOCKER_BASE} npx"
183+
NODE="${DOCKER_BASE} node"
184+
PYTHON="${DOCKER_BASE} ${ROOT}/.home/.venv/bin/python3"
185+
PIP="${DOCKER_BASE} ${ROOT}/.home/.venv/bin/pip"
186+
BASH="${DOCKER_BASE} bash"
97187
else
98-
BUNDLE="singularity run ${HOME_OPT} ${CONTAINER_PATH} bundle"
99-
RUBY="singularity run ${HOME_OPT} ${CONTAINER_PATH} bundle exec ruby"
100-
RAKE="singularity run ${HOME_OPT} ${CONTAINER_PATH} bundle exec rake"
101-
NPM="singularity run ${HOME_OPT} ${CONTAINER_PATH} npm"
102-
NPX="singularity run ${HOME_OPT} ${CONTAINER_PATH} npx"
103-
NODE="singularity run ${HOME_OPT} ${CONTAINER_PATH} node"
104-
PYTHON="singularity run ${HOME_OPT} ${CONTAINER_PATH} ${ROOT}/.home/.venv/bin/python3"
105-
PIP="singularity run ${HOME_OPT} ${CONTAINER_PATH} ${ROOT}/.home/.venv/bin/pip"
106-
BASH="singularity run ${HOME_OPT} ${CONTAINER_PATH} bash"
188+
BUNDLE="singularity run ${HOME_OPT} ${CONTAINER_PATH} bundle"
189+
RUBY="singularity run ${HOME_OPT} ${CONTAINER_PATH} bundle exec ruby"
190+
RAKE="singularity run ${HOME_OPT} ${CONTAINER_PATH} bundle exec rake"
191+
NPM="singularity run ${HOME_OPT} ${CONTAINER_PATH} npm"
192+
NPX="singularity run ${HOME_OPT} ${CONTAINER_PATH} npx"
193+
NODE="singularity run ${HOME_OPT} ${CONTAINER_PATH} node"
194+
PYTHON="singularity run ${HOME_OPT} ${CONTAINER_PATH} ${ROOT}/.home/.venv/bin/python3"
195+
PIP="singularity run ${HOME_OPT} ${CONTAINER_PATH} ${ROOT}/.home/.venv/bin/pip"
196+
BASH="singularity run ${HOME_OPT} ${CONTAINER_PATH} bash"
107197
fi
108198

109199
if [ ! -f $ROOT/.git/hooks/pre-commit ]; then
@@ -125,7 +215,7 @@ if [ -x "\$INSTALL_PYTHON" ]; then
125215
elif command -v pre-commit > /dev/null; then
126216
exec pre-commit "\${ARGS[@]}"
127217
else
128-
echo '`pre-commit` not found. Did you forget to activate your virtualenv?' 1>&2
218+
echo '\`pre-commit\` not found. Did you forget to activate your virtualenv?' 1>&2
129219
exit 1
130220
fi
131221
HOOK

0 commit comments

Comments
 (0)