Skip to content

Commit

Permalink
Add env overrides to cargo simics-build for properties specified in C…
Browse files Browse the repository at this point in the history
…argo.toml
  • Loading branch information
novafacing committed May 7, 2024
1 parent 3c429cb commit 1697142
Show file tree
Hide file tree
Showing 9 changed files with 242 additions and 20 deletions.
5 changes: 4 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@
**/Dockerfile
**/target/
**/*.img
**/*.diff.craff
**/*.diff.craff
# Don't add scripts so that builds dont have to rerun on script changes to those builds
scripts
target
6 changes: 3 additions & 3 deletions .github/builder/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ FROM fedora:20

ENV PATH="${PATH}:/root/.cargo/bin/"

COPY .github/builder/rsrc/rustup-init /install/rustup-init
COPY .github/builder/rsrc/rust-nightly-x86_64-unknown-linux-gnu.tar.xz /install/rust-nightly-x86_64-unknown-linux-gnu.tar.xz
COPY .github/builder/rsrc/make-4.4.1.tar.gz /install/make-4.4.1.tar.gz
COPY .github/builder/rsrc/cmake-3.28.0-rc5-linux-x86_64.tar.gz /install/cmake-3.28.0-rc5-linux-x86_64.tar.gz
COPY .github/builder/rsrc/lld-5.0.2.src.tar.xz /install/lld-5.0.2.src.tar.xz
Expand All @@ -13,8 +13,8 @@ COPY .github/builder/rsrc/rpms /install/rpms

RUN yum -y install /install/rpms/*.rpm && yum clean all

RUN chmod +x /install/rustup-init && \
/install/rustup-init -y --default-toolchain nightly && \
RUN tar -C /install -xvf /install/rust-nightly-x86_64-unknown-linux-gnu.tar.xz && \
/install/rust-nightly-x86_64-unknown-linux-gnu/install.sh && \
mkdir -p /make && \
tar -C /make --strip-components=1 -xf /install/make-4.4.1.tar.gz && \
pushd /make && \
Expand Down
62 changes: 62 additions & 0 deletions .github/builder/Dockerfile-internal
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# hadolint global ignore=DL3033,SC3044
FROM fedora:20

ENV PATH="${PATH}:/root/.cargo/bin/"

COPY .github/builder/rsrc/rust-nightly-x86_64-unknown-linux-gnu.tar.xz /install/rust-nightly-x86_64-unknown-linux-gnu.tar.xz
COPY .github/builder/rsrc/make-4.4.1.tar.gz /install/make-4.4.1.tar.gz
COPY .github/builder/rsrc/cmake-3.28.0-rc5-linux-x86_64.tar.gz /install/cmake-3.28.0-rc5-linux-x86_64.tar.gz
COPY .github/builder/rsrc/lld-5.0.2.src.tar.xz /install/lld-5.0.2.src.tar.xz
COPY .github/builder/rsrc/cfe-5.0.2.src.tar.xz /install/cfe-5.0.2.src.tar.xz
COPY .github/builder/rsrc/llvm-5.0.2.src.tar.xz /install/llvm-5.0.2.src.tar.xz
COPY .github/builder/rsrc/rpms /install/rpms
COPY .github/builder/rsrc/simics /simics
COPY .github/builder/rsrc/ispm /simics/ispm

RUN yum -y install /install/rpms/*.rpm && yum clean all

RUN tar -C /install -xvf /install/rust-nightly-x86_64-unknown-linux-gnu.tar.xz && \
/install/rust-nightly-x86_64-unknown-linux-gnu/install.sh && \
mkdir -p /make && \
tar -C /make --strip-components=1 -xf /install/make-4.4.1.tar.gz && \
pushd /make && \
./configure && \
make && \
make install && \
make clean && \
popd && \
tar -C /usr/local/ --strip-components=1 -xf /install/cmake-3.28.0-rc5-linux-x86_64.tar.gz && \
mkdir -p /llvm/tools/clang && \
mkdir -p /llvm/tools/lld && \
tar -C /llvm --strip-components=1 -xf /install/llvm-5.0.2.src.tar.xz && \
tar -C /llvm/tools/clang --strip-components=1 -xf /install/cfe-5.0.2.src.tar.xz && \
tar -C /llvm/tools/lld --strip-components=1 -xf /install/lld-5.0.2.src.tar.xz && \
mkdir -p /llvm/build && \
pushd /llvm/build && \
cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE="MinSizeRel" -DLLVM_TARGETS_TO_BUILD="X86" .. && \
make -j "$(nproc)" && \
make install && \
make clean && \
rm -rf /llvm/build/ && \
popd && \
rm -rf /make /llvm

WORKDIR /

ENV PATH="${PATH}:/simics/ispm/"
ENV PATH="${PATH}:/root/.cargo/bin/"

COPY . /tsffs/

WORKDIR /tsffs/

RUN ispm settings install-dir /simics && \
ispm packages --list

RUN RUSTFLAGS="-C linker=clang -C link-arg=-fuse-ld=$(which ld.lld)" && \
export RUSTFLAGS && \
cargo install --path simics-rs/cargo-simics-build && \
export SIMICS_PACKAGE_VERSION="$(ispm packages --list | grep 1000 | awk '{print $3}' | cut -d '.' -f1).$(grep -E '^version = ' < Cargo.toml | sed -n '$p' | grep -oE '\"[^\"]+\"' | tr -d '\"' | cut -d'.' -f2-)" && \
cargo simics-build -r && \
mkdir -p /packages-internal && \
cp target/release/*.ispm /packages-internal
11 changes: 6 additions & 5 deletions .github/builder/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ LLD_URL="https://releases.llvm.org/5.0.2/lld-5.0.2.src.tar.xz"
CFE_URL="https://releases.llvm.org/5.0.2/cfe-5.0.2.src.tar.xz"
LLVM_SRC_URL="https://releases.llvm.org/5.0.2/llvm-5.0.2.src.tar.xz"
MAKE_SRC_URL="https://ftp.gnu.org/gnu/make/make-4.4.1.tar.gz"
RUSTUP_INIT_URL="https://static.rust-lang.org/rustup/dist/x86_64-unknown-linux-gnu/rustup-init"
RUST_URL="https://static.rust-lang.org/dist/rust-nightly-x86_64-unknown-linux-gnu.tar.xz"
CMAKE_URL="https://github.com/Kitware/CMake/releases/download/v3.28.0-rc5/cmake-3.28.0-rc5-linux-x86_64.tar.gz"
PUBLIC_SIMICS_PKGS_URL="https://registrationcenter-download.intel.com/akdlm/IRC_NAS/ead79ef5-28b5-48c7-8d1f-3cde7760798f/simics-6-packages-2024-05-linux64.ispm"
PUBLIC_SIMICS_ISPM_URL="https://registrationcenter-download.intel.com/akdlm/IRC_NAS/ead79ef5-28b5-48c7-8d1f-3cde7760798f/intel-simics-package-manager-1.8.3-linux64.tar.gz"
Expand Down Expand Up @@ -51,12 +51,13 @@ if [ ! -f "${BUILDER_DIR}/rsrc/make-4.4.1.tar.gz" ]; then
"${MAKE_SRC_URL}"
fi

if [ ! -f "${BUILDER_DIR}/rsrc/rustup-init" ]; then
curl --noproxy '*.intel.com' -L -o "${BUILDER_DIR}/rsrc/rustup-init" \
"${RUSTUP_INIT_URL}"
chmod +x "${BUILDER_DIR}/rsrc/rustup-init"
if [ ! -f "${BUILDER_DIR}/rsrc/rust-nightly-x86_64-unknown-linux-gnu.tar.xz" ]; then
echo "rust not found. Downloading..."
curl --noproxy '*.intel.com' -L -o "${BUILDER_DIR}/rsrc/rust-nightly-x86_64-unknown-linux-gnu.tar.xz" \
"${RUST_URL}"
fi


if [ ! -f "${BUILDER_DIR}/rsrc/cmake-3.28.0-rc5-linux-x86_64.tar.gz" ]; then
curl --noproxy '*.intel.com' -L -o "${BUILDER_DIR}/rsrc/cmake-3.28.0-rc5-linux-x86_64.tar.gz" \
"${CMAKE_URL}"
Expand Down
7 changes: 3 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ env:
LLD_URL: "https://releases.llvm.org/5.0.2/lld-5.0.2.src.tar.xz"
LLVM_SRC_URL: "https://releases.llvm.org/5.0.2/llvm-5.0.2.src.tar.xz"
MAKE_SRC_URL: "https://ftp.gnu.org/gnu/make/make-4.4.1.tar.gz"
RUSTUP_INIT_URL: "https://static.rust-lang.org/rustup/dist/x86_64-unknown-linux-gnu/rustup-init"
RUST_URL: "https://static.rust-lang.org/dist/rust-nightly-x86_64-unknown-linux-gnu.tar.xz"
CMAKE_URL: "https://github.com/Kitware/CMake/releases/download/v3.28.0-rc5/cmake-3.28.0-rc5-linux-x86_64.tar.gz"
PUBLIC_SIMICS_PKGS_URL_WINDOWS: "https://registrationcenter-download.intel.com/akdlm/IRC_NAS/ead79ef5-28b5-48c7-8d1f-3cde7760798f/simics-6-packages-2024-05-win64.ispm"
# NOTE: We use the old ISPM because there is something wrong with 1.8.3 with unattended installation
Expand Down Expand Up @@ -610,9 +610,8 @@ jobs:
"${{ env.LLVM_SRC_URL }}"
curl -L -o .github/builder/rsrc/make-4.4.1.tar.gz \
"${{ env.MAKE_SRC_URL }}"
curl -L -o .github/builder/rsrc/rustup-init \
"${{ env.RUSTUP_INIT_URL }}"
chmod +x .github/builder/rsrc/rustup-init
curl -L -o .github/builder/rsrc/rust-nightly-x86_64-unknown-linux-gnu.tar.xz \
"${{ env.RUST_URL }}"
curl -L -o .github/builder/rsrc/cmake-3.28.0-rc5-linux-x86_64.tar.gz \
"${{ env.CMAKE_URL }}"
docker run -v "$(pwd)/.github/builder/rsrc/rpms:/rpms" fedora:20 bash -c \
Expand Down
109 changes: 109 additions & 0 deletions scripts/build-internal.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@

#!/bin/bash

# Copyright (C) 2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

# NOTE: This script requires the Intel version of `ispm` to be installed and available
# on the PATH. We do not download a new copy of it because despite its public
# unavailability, we want to be able to keep this script in the public repository
# without revealing any internal URLs. It will *not* work correctly with the public
# version of ISPM unless you are an Intel or Wind River Simics customer.

set -e

LLD_URL="https://releases.llvm.org/5.0.2/lld-5.0.2.src.tar.xz"
CFE_URL="https://releases.llvm.org/5.0.2/cfe-5.0.2.src.tar.xz"
LLVM_SRC_URL="https://releases.llvm.org/5.0.2/llvm-5.0.2.src.tar.xz"
MAKE_SRC_URL="https://ftp.gnu.org/gnu/make/make-4.4.1.tar.gz"
RUST_URL="https://static.rust-lang.org/dist/rust-nightly-x86_64-unknown-linux-gnu.tar.xz"
CMAKE_URL="https://github.com/Kitware/CMake/releases/download/v3.28.0-rc5/cmake-3.28.0-rc5-linux-x86_64.tar.gz"
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)
ROOT_DIR="${SCRIPT_DIR}/../"
BUILDER_DIR="${ROOT_DIR}/.github/builder/"
IMAGE_NAME="tsffs-builder-internal"
CONTAINER_UID=$(echo "${RANDOM}" | sha256sum | head -c 8)
CONTAINER_NAME="${IMAGE_NAME}-tmp-${CONTAINER_UID}"

mkdir -p "${BUILDER_DIR}/rsrc"

ISPM=$(which ispm)
ISPM_DIR=$(dirname "${ISPM}")

if [ ! -d "${BUILDER_DIR}/rsrc/ispm" ]; then
echo "ISPM not found. Copying local installation..."
cp -a "${ISPM_DIR}" "${BUILDER_DIR}/rsrc/ispm"
fi

if [ ! -d "${BUILDER_DIR}/rsrc/simics" ]; then
echo "Simics packages not found. Installing..."
mkdir -p "${BUILDER_DIR}/rsrc/simics"
ispm packages --install-dir "${BUILDER_DIR}/rsrc/simics" -i \
1000-latest \
1020-latest \
1030-latest \
1031-latest \
2050-latest \
2053-latest \
2096-latest \
4094-latest \
6010-latest \
7801-latest \
8112-latest \
8126-latest \
8144-latest \
--non-interactive
fi

if [ ! -f "${BUILDER_DIR}/rsrc/lld-5.0.2.src.tar.xz" ]; then
echo "LLD not found. Downloading..."
curl --noproxy '*.intel.com' -L -o "${BUILDER_DIR}/rsrc/lld-5.0.2.src.tar.xz" \
"${LLD_URL}"
fi

if [ ! -f "${BUILDER_DIR}/rsrc/cfe-5.0.2.src.tar.xz" ]; then
echo "CFE not found. Downloading..."
curl --noproxy '*.intel.com' -L -o "${BUILDER_DIR}/rsrc/cfe-5.0.2.src.tar.xz" \
"${CFE_URL}"
fi

if [ ! -f "${BUILDER_DIR}/rsrc/llvm-5.0.2.src.tar.xz" ]; then
echo "LLVM not found. Downloading..."
curl --noproxy '*.intel.com' -L -o "${BUILDER_DIR}/rsrc/llvm-5.0.2.src.tar.xz" \
"${LLVM_SRC_URL}"
fi

if [ ! -f "${BUILDER_DIR}/rsrc/make-4.4.1.tar.gz" ]; then
echo "Make not found. Downloading..."
curl --noproxy '*.intel.com' -L -o "${BUILDER_DIR}/rsrc/make-4.4.1.tar.gz" \
"${MAKE_SRC_URL}"
fi

if [ ! -f "${BUILDER_DIR}/rsrc/rust-nightly-x86_64-unknown-linux-gnu.tar.xz" ]; then
echo "rust not found. Downloading..."
curl --noproxy '*.intel.com' -L -o "${BUILDER_DIR}/rsrc/rust-nightly-x86_64-unknown-linux-gnu.tar.xz" \
"${RUST_URL}"
fi

if [ ! -f "${BUILDER_DIR}/rsrc/cmake-3.28.0-rc5-linux-x86_64.tar.gz" ]; then
echo "CMake not found. Downloading..."
curl --noproxy '*.intel.com' -L -o "${BUILDER_DIR}/rsrc/cmake-3.28.0-rc5-linux-x86_64.tar.gz" \
"${CMAKE_URL}"
fi

if [ ! -d "${BUILDER_DIR}/rsrc/rpms" ]; then
echo "RPM dependencies not found. Downloading..."
# NOTE: This may stop working at some point, as Fedora 20 is EOL. Therefore, we download the
# packages with the expectation that we will provide them separately if they are no longer
# available.
docker run -v "${BUILDER_DIR}/rsrc/rpms:/rpms" fedora:20 bash -c \
'yum -y update && yum install --downloadonly --downloaddir=/rpms coreutils gcc gcc-c++ make which && chmod -R 755 /rpms/'
fi

unset SIMICS_BASE
docker build \
-t "${IMAGE_NAME}" -f "${BUILDER_DIR}/Dockerfile-internal" "${ROOT_DIR}"
docker create --name "${CONTAINER_NAME}" "${IMAGE_NAME}" bash
mkdir -p "${ROOT_DIR}/packages-internal"
docker cp "${CONTAINER_NAME}:/packages-internal" "${ROOT_DIR}/"
docker rm -f "${CONTAINER_NAME}"
11 changes: 5 additions & 6 deletions scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ LLD_URL="https://releases.llvm.org/5.0.2/lld-5.0.2.src.tar.xz"
CFE_URL="https://releases.llvm.org/5.0.2/cfe-5.0.2.src.tar.xz"
LLVM_SRC_URL="https://releases.llvm.org/5.0.2/llvm-5.0.2.src.tar.xz"
MAKE_SRC_URL="https://ftp.gnu.org/gnu/make/make-4.4.1.tar.gz"
RUSTUP_INIT_URL="https://static.rust-lang.org/rustup/dist/x86_64-unknown-linux-gnu/rustup-init"
RUST_URL="https://static.rust-lang.org/dist/rust-nightly-x86_64-unknown-linux-gnu.tar.xz"
CMAKE_URL="https://github.com/Kitware/CMake/releases/download/v3.28.0-rc5/cmake-3.28.0-rc5-linux-x86_64.tar.gz"
PUBLIC_SIMICS_PKGS_URL="https://registrationcenter-download.intel.com/akdlm/IRC_NAS/ead79ef5-28b5-48c7-8d1f-3cde7760798f/simics-6-packages-2024-05-linux64.ispm"
PUBLIC_SIMICS_ISPM_URL="https://registrationcenter-download.intel.com/akdlm/IRC_NAS/ead79ef5-28b5-48c7-8d1f-3cde7760798f/intel-simics-package-manager-1.8.3-linux64.tar.gz"
Expand Down Expand Up @@ -58,11 +58,10 @@ if [ ! -f "${BUILDER_DIR}/rsrc/make-4.4.1.tar.gz" ]; then
"${MAKE_SRC_URL}"
fi

if [ ! -f "${BUILDER_DIR}/rsrc/rustup-init" ]; then
echo "rustup not found. Downloading..."
curl --noproxy '*.intel.com' -L -o "${BUILDER_DIR}/rsrc/rustup-init" \
"${RUSTUP_INIT_URL}"
chmod +x "${BUILDER_DIR}/rsrc/rustup-init"
if [ ! -f "${BUILDER_DIR}/rsrc/rust-nightly-x86_64-unknown-linux-gnu.tar.xz" ]; then
echo "rust not found. Downloading..."
curl --noproxy '*.intel.com' -L -o "${BUILDER_DIR}/rsrc/rust-nightly-x86_64-unknown-linux-gnu.tar.xz" \
"${RUST_URL}"
fi

if [ ! -f "${BUILDER_DIR}/rsrc/cmake-3.28.0-rc5-linux-x86_64.tar.gz" ]; then
Expand Down
5 changes: 5 additions & 0 deletions simics-rs/scripts/test-build-versions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

set -e

ispm packages --list-installed --json | jq -r '.installedPackages[] | select(.pkgNumber == 1000) | .version' | tac | grep -v pre | sed -ne '/6.0.163/,$ p'
46 changes: 45 additions & 1 deletion simics-rs/simics-package/src/spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

//! Specifications for internal file formats used in the Simics packaging process
use std::{iter::once, path::PathBuf};
use std::{env::var, iter::once, path::PathBuf};

use crate::{Error, PackageArtifacts, Result, HOST_DIRNAME};
use cargo_metadata::{MetadataCommand, Package};
Expand Down Expand Up @@ -374,6 +374,50 @@ impl ManifestPackageSpec {
spec.doc_title = Some(package.name.clone());
}

if let Ok(package_name) = var("SIMICS_PACKAGE_PACKAGE_NAME") {
spec.package_name = Some(package_name);
}

if let Ok(package_number) = var("SIMICS_PACKAGE_PACKAGE_NUMBER") {
spec.package_number = Some(package_number.parse().map_err(Error::from)?);
}

if let Ok(package_name) = var("SIMICS_PACKAGE_NAME") {
spec.name = Some(package_name);
}

if let Ok(description) = var("SIMICS_PACKAGE_DESCRIPTION") {
spec.description = Some(description);
}

if let Ok(host) = var("SIMICS_PACKAGE_HOST") {
spec.host = Some(host);
}

if let Ok(version) = var("SIMICS_PACKAGE_VERSION") {
spec.version = Some(version);
}

if let Ok(build_id) = var("SIMICS_PACKAGE_BUILD_ID") {
spec.build_id = Some(build_id.parse().map_err(Error::from)?);
}

if let Ok(build_id_namespace) = var("SIMICS_PACKAGE_BUILD_ID_NAMESPACE") {
spec.build_id_namespace = Some(build_id_namespace);
}

if let Ok(confidentiality) = var("SIMICS_PACKAGE_CONFIDENTIALITY") {
spec.confidentiality = Some(confidentiality);
}

if let Ok(typ) = var("SIMICS_PACKAGE_TYPE") {
spec.typ = Some(typ);
}

if let Ok(doc_title) = var("SIMICS_PACKAGE_DOC_TITLE") {
spec.doc_title = Some(doc_title);
}

Ok(spec)
}

Expand Down

0 comments on commit 1697142

Please sign in to comment.