Skip to content

Commit

Permalink
ci/mkosi.build: install rust 1.81
Browse files Browse the repository at this point in the history
Signed-off-by: Ming Lei <[email protected]>
  • Loading branch information
ming1 committed Dec 26, 2024
1 parent 5aa9e38 commit 8c20f7b
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions ci/mkosi.build
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,52 @@
# $BUILDDIR
#

install_rust_1_81_to_path() {
local target_dir="$1"

if [[ -z "$target_dir" ]]; then
echo "Usage: install_rust_1_81_to_path <target-directory>"
return 1
fi

# Ensure the script is not run as root
if [[ $EUID -eq 0 ]]; then
echo "Please do not run as root. Run this function as a regular user."
return 1
fi

# Create the target directory if it doesn't exist
mkdir -p "$target_dir"

# Set environment variables for custom installation paths
export CARGO_HOME="$target_dir"
export RUSTUP_HOME="$target_dir"

# Remove any system-installed Rust to avoid conflicts
dnf remove -y rust

# Install rustup in non-interactive mode
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y

# Add the custom CARGO_HOME bin directory to PATH for this session
export PATH="$CARGO_HOME/bin:$PATH"

# Install Rust 1.81
rustup install 1.81.0

# Set Rust 1.81 as the default version globally (in the custom path)
rustup default 1.81.0

# Verify the installation
if "$CARGO_HOME/bin/rustc" --version | grep -q "1.81.0"; then
echo "Rust 1.81.0 has been installed successfully to $target_dir!"
else
echo "Rust installation failed."
return 1
fi
}


create_rublk_test()
{
local rs_dir=$1
Expand All @@ -27,8 +73,11 @@ set -eo pipefail

mkdir -p $DESTDIR/root/
echo "systemctl restart systemd-networkd" >> $DESTDIR/root/.bash_profile
echo "export PATH=/root/bin:\$PATH" >> $DESTDIR/root/.bash_profile
chmod +x $DESTDIR/root/.bash_profile

install_rust_1_81_to_path $DESTDIR/root/

# Copy tests into the dest
mkdir -p $DESTDIR/usr/share
cp -fr $SRCDIR $DESTDIR/usr/share/rublk
Expand Down

0 comments on commit 8c20f7b

Please sign in to comment.