-
Notifications
You must be signed in to change notification settings - Fork 79
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
Conda pack support #213
base: master
Are you sure you want to change the base?
Conda pack support #213
Changes from all commits
cb8b8df
9c615cd
c375d29
cbda6eb
e462a06
a8acfac
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
#!/bin/bash | ||
|
||
### This script is, in principle, similar to download-env.sh | ||
### Notable differences: | ||
### - download-env does not download everything, but depends on system variables | ||
### - download-env installs LiteX submodules. This is not allowed here as | ||
### conda-pack fails when it finds editable pip modules | ||
### - download-env downloads Zephyr SDK if needed. This script does not do it, | ||
### but will when the SDK conda package is created | ||
|
||
SETUP_SRC="$(realpath ${BASH_SOURCE[0]})" | ||
SETUP_DIR="$(dirname "${SETUP_SRC}")" | ||
TOP_DIR="$(realpath "${SETUP_DIR}/..")" | ||
|
||
source "$SETUP_DIR/setup-helpers.sh" | ||
source "$SETUP_DIR/settings.sh" | ||
|
||
verify_system || exit 1 | ||
|
||
set -e | ||
set -u | ||
|
||
# Ensure the build dir | ||
mkdir -p $BUILD_DIR | ||
|
||
echo "" | ||
echo "Initializing environment" | ||
echo "------------------------" | ||
# Install and setup conda for downloading packages | ||
export PATH=$CONDA_DIR/bin:$PATH:/sbin | ||
( | ||
install_conda | ||
) | ||
|
||
echo "" | ||
echo "Preparing packages" | ||
echo "------------------" | ||
|
||
# this file will contain final env description | ||
ENV_FILE=$BUILD_DIR/environment.yml | ||
|
||
# this file contains packages which versions are not specified in settings.sh | ||
ENV_TEMPLATE=$SETUP_DIR/template-environment.yml | ||
|
||
# This is the name of the new environment from which the pack will be created. | ||
# Note that this name appears in the template file as well. These values should | ||
# match each other | ||
ENV_NAME=lxbe-env | ||
|
||
# As conda environment yml format does not seem to allow variables and we want | ||
# to rely on settings.sh to specify package versions, we programatically fill up | ||
# the env file with proper versions. | ||
cat $ENV_TEMPLATE > $ENV_FILE | ||
echo " - conda=$CONDA_VERSION" >> $ENV_FILE | ||
echo " - python=$PYTHON_VERSION" >> $ENV_FILE | ||
echo " - openocd=$OPENOCD_VERSION" >> $ENV_FILE | ||
|
||
# This code is supposed to add entries for all architectures and toolchain | ||
# flavors. | ||
# Some conda packages are not there yet (namely x86_64 and lm32 with musl), | ||
# so we comment these out. | ||
for ARCH in or1k riscv32 lm32 x86_64; do | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not per se, it was actually an emulation of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How can it be used in a meaningful way? I mean, how do we define "works"? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For a compiler, test it is able to compile something? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you mean x86 compiler? I don't really understand the way you'd like to use it. To effectively include this option in the general flow I need to understand how can it be useful. |
||
if [[ "$ARCH" == "x86_64" ]]; then | ||
echo -n "#" >> $ENV_FILE | ||
fi | ||
echo " - binutils-$ARCH-elf=$BINUTILS_VERSION" >> $ENV_FILE | ||
for FLAVOR in elf-nostdc elf-newlib linux-musl; do | ||
if [[ "$ARCH" == "x86_64" || ( "$ARCH" == "lm32" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A case statement here is probably clearer. |
||
&& "$FLAVOR" == "linux-musl" ) ]]; then | ||
echo -n "#" >> $ENV_FILE | ||
fi | ||
echo " - gcc-$ARCH-$FLAVOR=$GCC_VERSION" >> $ENV_FILE | ||
done | ||
done | ||
|
||
echo "" | ||
echo "Preparing dependencies" | ||
echo "----------------------" | ||
cat $ENV_FILE | ||
|
||
# This creates an lxbe-env environment. | ||
conda env create -f $ENV_FILE | ||
|
||
#required to not rely on user site-packages | ||
export PYTHONNOUSERSITE=1 | ||
|
||
# We enter the conda env to install things via pip manually. | ||
# This can't be done via the yml file because we invariably use the user's | ||
# site-packages. | ||
# Unfortunately, the activate/deactivate scripts have to have -e/-u disabled. | ||
# This also applies to Renode package installation. | ||
set +u | ||
set +e | ||
source activate $ENV_NAME | ||
|
||
# We install Renode separately, no to polute the ENV_FILE with conda-forge repo. | ||
# It is needed for mono. | ||
conda install -y $CONDA_FLAGS -c antmicro -c conda-forge renode | ||
|
||
set -u | ||
set -e | ||
|
||
# We're using pip install instead of putting it in the yml, because we want to | ||
# ensure isolation. | ||
# conda env create does not seem to take PYTHONNOUSERSITE=1 very seriously. | ||
# We're not installing conda-pack from conda because it requires conda-forge | ||
# source. | ||
pip install conda-pack \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you use a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please see #213 (comment) |
||
tinyfpgab \ | ||
progressbar2 \ | ||
colorama \ | ||
sphinx_rtd_theme \ | ||
sphinx \ | ||
pyelftools \ | ||
west \ | ||
pykwalify \ | ||
"git+https://github.com/tinyfpga/TinyFPGA-Bootloader#egg=tinyprog&subdirectory=programmer&subdirectory=programmer" \ | ||
git+https://github.com/mithro/hexfile.git \ | ||
git+https://github.com/timvideos/HDMI2USB-mode-switch.git \ | ||
"cmake==$CMAKE_VERSION" | ||
|
||
|
||
# This has to be installed manually in the environment | ||
MIMASV2CONFIG=$BUILD_DIR/conda/bin/MimasV2Config.py | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's make it into a Python package? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As I don't think it would make sense to PR to the original repo, do you want to have it in timvideos GH? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It does make sense to PR to the original repo, they will probably accept the pull request. I have contacts at Numato if you run into trouble. |
||
echo | ||
echo "Installing MimasV2Config.py (mimasv2 flashing tool)" | ||
if [ ! -e $MIMASV2CONFIG ]; then | ||
wget https://raw.githubusercontent.com/numato/samplecode/master/FPGA/MimasV2/tools/configuration/python/MimasV2Config.py -O $MIMASV2CONFIG | ||
chmod a+x $MIMASV2CONFIG | ||
fi | ||
check_exists MimasV2Config.py | ||
|
||
echo "" | ||
echo "Working environment" | ||
echo "-------------------" | ||
|
||
conda env export | ||
|
||
echo "" | ||
echo "Creating a pack" | ||
echo "---------------" | ||
|
||
rm -f $BUILD_DIR/$ENV_NAME.tar.gz | ||
conda pack -p $CONDA_DIR/envs/$ENV_NAME -o $BUILD_DIR/$ENV_NAME.tar.gz | ||
|
||
# The activate/deactivate conda scripts have to have -e/-u disabled. | ||
set +u | ||
set +e | ||
conda deactivate | ||
set -e | ||
set -u | ||
|
||
echo "" | ||
echo "Package created in $BUILD_DIR/$ENV_NAME.tar.gz!" | ||
echo "" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be better to extract the versions from the environment.yml file and remove the settings.sh file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it makes sense, parsing it will be trivial and will allow us to drop this quasi-auto-generation of yml. It's a shame conda does not allow variables substitution. Even python-pip does.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mithro So we gave some thought to it and this calls for more discussion.
Right now cmake is the only pip-installed package that has a version specified. It turns out that Conda has it in an older, but still suitable version available.
This means we could have multiple requirements.txt files in scripts/dependencies. There could be requirements.txt for common stuff, requirements-zephyr.txt, requirements-tinyfpga_b2.txt etc.
This way we could:
a) have a clear distinction over what requires which packages
b) install via
pip install -r
in both download-env and build-pack.For Conda we can do it similarly, and have multiple requirement files for different dependencies, and then use them all to create a pack.
There are, allegedly, some problems with using files as source for
conda install
, but I'm sure it's manageable. The format is also not really specified, but I think thatpip
files work fine, just as yml files.Parsing files is something we'd prefer to avoid, for example to be able to easily switch the format/backend in the future.
Summing up, the flow would be:
What's your opinion on that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the idea of having;
requirements-<board>.txt
requirements-<firmware>.txt
requirements-<cpu>.txt
I'm unclear if it should be separate firmware / cpu files or if it should be
requirements-<firmware>-<cpu>
?Another option is that we could use dummy conda packages with the requirements as dependencies?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe I will be enough to have
requirements-<something>.txt
, with only one dimension. If more is needed, we can always add it.