From 5b1d3208167c2a7d57f6c774e8bbb3f428da29f7 Mon Sep 17 00:00:00 2001 From: memento Date: Sun, 26 Jan 2025 17:25:39 -0600 Subject: [PATCH 01/26] Add renode-cli --- recipes/renode-cli/build.sh | 121 ++++++ .../renode-cli/helpers/build-with-cmake.sh | 107 +++++ .../patches/resolve-posix-unix.patch | 67 ++++ .../update-IronPython-Renode_NET.csproj.patch | 5 + ...pdate-IronPython-Unittest_NET.csproj.patch | 18 + .../patches/update-for-cmake-build.sh.patch | 367 ++++++++++++++++++ recipes/renode-cli/recipe.yaml | 114 ++++++ 7 files changed, 799 insertions(+) create mode 100644 recipes/renode-cli/build.sh create mode 100644 recipes/renode-cli/helpers/build-with-cmake.sh create mode 100644 recipes/renode-cli/patches/resolve-posix-unix.patch create mode 100644 recipes/renode-cli/patches/update-IronPython-Renode_NET.csproj.patch create mode 100644 recipes/renode-cli/patches/update-IronPython-Unittest_NET.csproj.patch create mode 100644 recipes/renode-cli/patches/update-for-cmake-build.sh.patch create mode 100644 recipes/renode-cli/recipe.yaml diff --git a/recipes/renode-cli/build.sh b/recipes/renode-cli/build.sh new file mode 100644 index 0000000000000..85ff06dd68c42 --- /dev/null +++ b/recipes/renode-cli/build.sh @@ -0,0 +1,121 @@ +#!/usr/bin/env bash + +set -o xtrace -o nounset -o pipefail -o errexit + +update_antmicro_submodule() { + local commit=$1 + local module=$2 + + git clone https://github.com/antmicro/${module}.git + pushd ${module} + git fetch origin ${commit} + git submodule update --init --recursive + popd +} + +mkdir -p ${PREFIX}/bin +mkdir -p ${PREFIX}/libexec/${PKG_NAME} +export PATH="${DOTNET_ROOT}/dotnet:${PATH}" + +install_prefix="${PREFIX}/opt/${PKG_NAME}" + +dotnet_version=$(dotnet --version) +framework_version=${dotnet_version%.*} + +mkdir -p ${SRC_DIR}/src/Infrastructure/ +mv renode-infrastructure/* ${SRC_DIR}/src/Infrastructure/ && rm -rf renode-infrastructure + +mkdir -p ${SRC_DIR}/lib +pushd ${SRC_DIR}/lib + git clone https://github.com/renode/renode-resources.git + pushd renode-resources && git submodule update --init --recursive && popd + mv renode-resources resources + + update_antmicro_submodule b1d3d03d602581fc2bed6db586b5e5c3388456c7 AntShell + update_antmicro_submodule e7bfa5873f2300e6e87c185f466e227762dbf4b2 BigGustave + update_antmicro_submodule b0c2a820f28a7bdedb85575bfca6447c9e7fa955 CxxDemangler + update_antmicro_submodule de4e4f6ffab555771285cb810f17f61cfd38ef39 ELFsharp + rm -rf ELFSharp && mv ELFsharp ELFSharp + update_antmicro_submodule e379e8ae696676afffed2f33dd8083855af00f2f FdtSharp + update_antmicro_submodule 33e5ab24eaaab488e9a94f1a40d5d6ae2f7f02f1 InpliTftpServer + update_antmicro_submodule c6514e99f2c35afec083b9f4a7eec3408c0081d1 Migrant + update_antmicro_submodule 2fe74fd257f6d6f86076c100952178f347098b3d Packet.Net + update_antmicro_submodule 33d24f1307d267c34b7f1439bc159a8825c5aa3d bc-csharp + update_antmicro_submodule bde21d04fbfc540989b7a0ac13a54eae8b756994 cctask + update_antmicro_submodule e8c2051dec56c5ccd3a4927b07a5740f34eed8c8 options-parser + update_antmicro_submodule 71af57ef4fec29e416f48160b8918057a58548a9 termsharp +popd + +find lib src tests -name "*.csproj" -exec sed -i -E \ + -e "s/([>;])net6.0([<;])/\1net${framework_version}\2/" \ + -e "s|^((\s+))|\1\n\2\2CS0168;CS0219;CS8981;SYSLIB0050;SYSLIB0051|" \ + -e 's|^(\s+)<(Package)?Reference\s+Include="Mono.Posix".*\n||g' \ + {} \; +find . -type d -name "obj" -exec rm -rf {} + +find . -type d -name "bin" -exec rm -rf {} + +sed -i -E 's/(ReleaseHeadless\|Any .+ = )Debug/\1Release/' Renode_NET.sln + +export CC=${CC} +export CFLAGS="${CFLAGS} -fPIC" + +if [[ "${target_platform}" == linux-* ]] || [[ "${target_platform}" == osx-* ]]; then + _os_name=${target_platform%-*} + + ./build.sh --net --no-gui --force-net-framework-version ${framework_version} +else + _os_name=windows + ./build.sh --net --no-gui --force-net-framework-version ${framework_version} +fi + + +mkdir -p $PREFIX/libexec/${PKG_NAME} +cp -r output/bin/Release/net${framework_version}/* $PREFIX/libexec/${PKG_NAME}/ + +mkdir -p $PREFIX/opt/${PKG_NAME}/scripts +mkdir -p $PREFIX/opt/${PKG_NAME}/platforms +mkdir -p $PREFIX/opt/${PKG_NAME}/tests +mkdir -p $PREFIX/opt/${PKG_NAME}/tools +mkdir -p $PREFIX/opt/${PKG_NAME}/licenses + +cp .renode-root $PREFIX/opt/${PKG_NAME}/ +cp -r scripts/* $PREFIX/opt/${PKG_NAME}/scripts/ +cp -r platforms/* $PREFIX/opt/${PKG_NAME}/platforms/ +cp -r tests/* $PREFIX/opt/${PKG_NAME}/tests/ +cp -r tools/metrics_analyzer $PREFIX/opt/${PKG_NAME}/tools +cp -r tools/execution_tracer $PREFIX/opt/${PKG_NAME}/tools +cp -r tools/gdb_compare $PREFIX/opt/${PKG_NAME}/tools +cp -r tools/sel4_extensions $PREFIX/opt/${PKG_NAME}/tools + +cp lib/resources/styles/robot.css $PREFIX/opt/${PKG_NAME}/tests + +tools/packaging/common_copy_licenses.sh $PREFIX/opt/${PKG_NAME}/licenses $_os_name +cp -r $PREFIX/opt/${PKG_NAME}/licenses license-files + +sed -i.bak "s#os\.path\.join(this_path, '\.\./lib/resources/styles/robot\.css')#os.path.join(this_path,'robot.css')#g" $PREFIX/opt/${PKG_NAME}/tests/robot_tests_provider.py +rm $PREFIX/opt/${PKG_NAME}/tests/robot_tests_provider.py.bak + +mkdir -p $PREFIX/bin/ +cat > $PREFIX/bin/renode <<"EOF" +#!/bin/sh +exec "${DOTNET_ROOT}"/dotnet exec "${CONDA_PREFIX}"/libexec/renode-cli/Renode.dll "$@" +EOF +chmod +x ${PREFIX}/bin/renode + +ccat > $PREFIX/bin/renode.cmd <<"EOF" +call %DOTNET_ROOT%\dotnet exec %CONDA_PREFIX%\libexec\libexec\renode-cli\Renode.dll %* +EOF +chmod +x ${PREFIX}/bin/renode + +at > $PREFIX/bin/renode-test <<"EOF" +#!/usr/bin/env bash + +STTY_CONFIG=`stty -g 2>/dev/null` +python3 "${CONDA_PREFIX}"/opt/"${PKG_NAME}"/tests/run_tests.py --robot-framework-remote-server-full-directory "${CONDA_PREFIX}"/libexec/"${PKG_NAME}" "$@" +RESULT_CODE=$? +if [ -n "${STTY_CONFIG:-}" ] +then + stty "$STTY_CONFIG" +fi +exit $RESULT_CODE +EOF +chmod +x ${PREFIX}/bin/renode-test diff --git a/recipes/renode-cli/helpers/build-with-cmake.sh b/recipes/renode-cli/helpers/build-with-cmake.sh new file mode 100644 index 0000000000000..6da064642842d --- /dev/null +++ b/recipes/renode-cli/helpers/build-with-cmake.sh @@ -0,0 +1,107 @@ +HOST_ARCH="i386" +CMAKE_COMMON="" +CORES_PATH="$ROOT_PATH/src/Infrastructure/src/Emulator/Cores" +OUT_BIN_DIR="$(get_path "output/bin/${CONFIGURATION}")" +BUILD_TYPE_FILE=$(get_path "${OUT_BIN_DIR}/build_type") + +# clean instead of building +if $CLEAN +then + for project_dir in $(find "$(get_path "${ROOT_PATH}/src")" -iname '*.csproj' -exec dirname '{}' \;) + do + for dir in {bin,obj}/{Debug,Release} + do + output_dir="$(get_path "${project_dir}/${dir}")" + if [[ -d "${output_dir}" ]] + then + echo "Removing: ${output_dir}" + rm -rf "${output_dir}" + fi + done + done + + # Manually clean the main output directory as it's location is non-standard + main_output_dir="$(get_path "${OUTPUT_DIRECTORY}/bin")" + if [[ -d "${main_output_dir}" ]] + then + echo "Removing: ${main_output_dir}" + rm -rf "${main_output_dir}" + fi + exit 0 +fi + +# Check if a full rebuild is needed +if [[ -f "$BUILD_TYPE_FILE" ]] +then + if [[ "$(cat "$BUILD_TYPE_FILE")" != "$BUILD_TYPE" ]] + then + echo "Attempted to build Renode in a different configuration than the previous build" + echo "Please run '$0 -c' to clean the previous build before continuing" + exit 1 + fi +fi + +# Paths for tlib +CORES_BUILD_PATH="$CORES_PATH/obj/$CONFIGURATION" +CORES_BIN_PATH="$CORES_PATH/bin/$CONFIGURATION" + +# Cmake generator, handled in their own variable since the names contain spaces +if $ON_WINDOWS +then + CMAKE_GEN="-GMinGW Makefiles" +else + CMAKE_GEN="-GUnix Makefiles" +fi + +# Macos architecture flags, to make rosetta work properly +if $ON_OSX +then + CMAKE_COMMON+=" -DCMAKE_OSX_ARCHITECTURES=x86_64" + if [ $HOST_ARCH == "aarch64" ]; then + CMAKE_COMMON+=" -DCMAKE_OSX_ARCHITECTURES=arm64" + fi +fi + +# This list contains all cores that will be built. +# If you are adding a new core or endianness add it here to have the correct tlib built +CORES=(arm.le arm.be arm64.le arm-m.le arm-m.be ppc.le ppc.be ppc64.le ppc64.be i386.le x86_64.le riscv.le riscv64.le sparc.le sparc.be xtensa.le) + +# build tlib +for core_config in "${CORES[@]}" +do + CORE="$(echo $core_config | cut -d '.' -f 1)" + ENDIAN="$(echo $core_config | cut -d '.' -f 2)" + BITS=32 + # Check if core is 64-bit + if [[ $CORE =~ "64" ]]; then + BITS=64 + fi + # Core specific flags to cmake + CMAKE_CONF_FLAGS="-DTARGET_ARCH=$CORE -DTARGET_WORD_SIZE=$BITS -DCMAKE_BUILD_TYPE=$CONFIGURATION" + CORE_DIR=$CORES_BUILD_PATH/$CORE/$ENDIAN + mkdir -p $CORE_DIR + pushd "$CORE_DIR" > /dev/null + if [[ $ENDIAN == "be" ]]; then + CMAKE_CONF_FLAGS+=" -DTARGET_BIG_ENDIAN=1" + fi + cmake "$CMAKE_GEN" $CMAKE_COMMON $CMAKE_CONF_FLAGS -DHOST_ARCH=$HOST_ARCH $CORES_PATH + cmake --build . -j$(nproc) + CORE_BIN_DIR=$CORES_BIN_PATH/lib + mkdir -p $CORE_BIN_DIR + if $ON_OSX; then + # macos `cp` does not have the -u flag + cp -v tlib/*.so $CORE_BIN_DIR/ + else + cp -u -v tlib/*.so $CORE_BIN_DIR/ + fi + # copy compile_commands.json to tlib directory + if [[ "$TLIB_EXPORT_COMPILE_COMMANDS" = true ]]; then + command cp -v -f $CORE_DIR/compile_commands.json $CORES_PATH/tlib/ + fi + popd > /dev/null +done + +if $TLIB_ONLY +then + exit 0 +fi diff --git a/recipes/renode-cli/patches/resolve-posix-unix.patch b/recipes/renode-cli/patches/resolve-posix-unix.patch new file mode 100644 index 0000000000000..604bfdd3387e0 --- /dev/null +++ b/recipes/renode-cli/patches/resolve-posix-unix.patch @@ -0,0 +1,67 @@ +--- a/src/Plugins/VerilatorPlugin/Connection/SocketVerilatorConnection.cs ++++ b/src/Plugins/VerilatorPlugin/Connection/SocketVerilatorConnection.cs +@@ -7,4 +7,6 @@ + using System; ++using System.IO; + using System.Net; + using System.Net.Sockets; ++using System.Security.AccessControl; + using System.Text; +@@ -19,2 +21,3 @@ + using Antmicro.Renode.Peripherals; ++using Antmicro.Renode.Peripherals.Bus; + using Antmicro.Renode.Peripherals.CPU; +@@ -212,3 +215,7 @@ + #if !PLATFORM_WINDOWS +- Mono.Unix.Native.Syscall.chmod(value, FilePermissions.S_IRWXU); //setting permissions to 0x700 ++ // Use built-in .NET methods for file permissions ++ var fileInfo = new FileInfo(value); ++ var fileSecurity = fileInfo.GetAccessControl(); ++ fileSecurity.AddAccessRule(new FileSystemAccessRule(Environment.UserName, FileSystemRights.FullControl, AccessControlType.Allow)); ++ fileInfo.SetAccessControl(fileSecurity); + #endif +--- a/src/Renode/Backends/Terminals/UartPtyTerminal.cs 2024-09-17 03:09:19.000000000 -0500 ++++ b/src/Renode/Backends/Terminals/UartPtyTerminal.cs 2025-01-25 21:32:28.901091634 -0600 +@@ -10,2 +10,3 @@ + using System; ++using System.IO; + using Antmicro.Renode.Peripherals.UART; +@@ -14,4 +15,2 @@ + using Antmicro.Migrant; +-using Mono.Unix; +-using System.IO; + #endif +@@ -49,3 +48,3 @@ + { +- symlink.Delete(); ++ File.Delete(linkName); + } +@@ -53,3 +52,3 @@ + { +- throw new RecoverableException(string.Format("There was an error when removing symlink `{0}': {1}", symlink.FullName, e.Message)); ++ throw new RecoverableException(string.Format("There was an error when removing symlink `{0}': {1}", symlink, e.Message)); + } +@@ -105,4 +104,4 @@ + { +- var slavePtyFile = new UnixFileInfo(ptyStream.SlaveName); +- symlink = slavePtyFile.CreateSymbolicLink(linkName); ++ symlink = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); ++ File.CreateSymbolicLink(symlink, ptyStream.SlaveName); + } +@@ -114,4 +113,2 @@ + +- private UnixSymbolicLinkInfo symlink; +- + private readonly bool forceCreate; +@@ -122,2 +119,4 @@ + private IOProvider io; ++ [Transient] ++ private string symlink; + } +--- a/src/Renode/Program.cs 2024-09-17 03:09:19.000000000 -0500 ++++ b/src/Renode/Program.cs 2025-01-26 11:07:01.717709447 -0600 +@@ -98,3 +98,3 @@ + ConfigurationManager.Instance.Get("general", "terminal", "Termsharp"); +- ConsoleBackend.Instance.ReportRepeatingLines = !ConfigurationManager.Instance.Get("general", "collapse-repeated-log-entries", true); ++ // Logger.LogEntriesLimit = ConfigurationManager.Instance.Get("general", "log-entries-limit", 10000); + } diff --git a/recipes/renode-cli/patches/update-IronPython-Renode_NET.csproj.patch b/recipes/renode-cli/patches/update-IronPython-Renode_NET.csproj.patch new file mode 100644 index 0000000000000..c2a58810292ab --- /dev/null +++ b/recipes/renode-cli/patches/update-IronPython-Renode_NET.csproj.patch @@ -0,0 +1,5 @@ +--- a/src/Renode/Renode_NET.csproj ++++ b/src/Renode/Renode_NET.csproj +@@ -29 +29 @@ +- ++ diff --git a/recipes/renode-cli/patches/update-IronPython-Unittest_NET.csproj.patch b/recipes/renode-cli/patches/update-IronPython-Unittest_NET.csproj.patch new file mode 100644 index 0000000000000..b7509c25637e2 --- /dev/null +++ b/recipes/renode-cli/patches/update-IronPython-Unittest_NET.csproj.patch @@ -0,0 +1,18 @@ +--- a/src/Emulator/Main/Tests/UnitTests/UnitTests_NET.csproj ++++ b/src/Emulator/Main/Tests/UnitTests/UnitTests_NET.csproj +@@ -18,5 +18,4 @@ + +- +- ..\..\..\..\..\..\..\lib\resources\libraries\ironpython-netcore\IronPython.dll +- ++ ++ + +--- a/src/Emulator/Main/Foreign/Player.cs ++++ b/src/Emulator/Main/Foreign/Player.cs +@@ -26,3 +26,4 @@ + this.stream = stream; ++ byte[] metadataBytes = null; +- deserializer = new Serializer(new Settings(useBuffering: false, disableTypeStamping: true)).ObtainOpenStreamDeserializer(stream); ++ deserializer = new Serializer(new Settings(useBuffering: false, disableTypeStamping: true)).ObtainOpenStreamDeserializer(stream, out metadataBytes); + handlersCache = new Dictionary(); diff --git a/recipes/renode-cli/patches/update-for-cmake-build.sh.patch b/recipes/renode-cli/patches/update-for-cmake-build.sh.patch new file mode 100644 index 0000000000000..a9f480f68bc3d --- /dev/null +++ b/recipes/renode-cli/patches/update-for-cmake-build.sh.patch @@ -0,0 +1,367 @@ +--- /home/memento/PycharmProjects/staged-recipes-2/build_artifacts/src_cache/v1_15_3_692604eb/build.sh 2024-09-17 03:09:19.000000000 -0500 ++++ build.new.sh 2025-01-24 15:30:24.984659038 -0600 +@@ -18,4 +18,8 @@ + SKIP_FETCH=false ++TLIB_ONLY=false ++TLIB_EXPORT_COMPILE_COMMANDS=false ++TLIB_ARCH="" + NET=false +-TFM="net6.0" ++TFM="net8.0" ++GENERATE_DOTNET_BUILD_TARGET=true + PARAMS=() +@@ -24,5 +28,8 @@ + RID="linux-x64" ++HOST_ARCH="i386" ++# Common cmake flags ++CMAKE_COMMON="" + + function print_help() { +- echo "Usage: $0 [-cdvspnt] [-b properties-file.csproj] [--no-gui] [--skip-fetch] [--profile-build] [-- ]" ++ echo "Usage: $0 [-cdvspnt] [-b properties-file.csproj] [--no-gui] [--skip-fetch] [--profile-build] [--tlib-only] [--tlib-export-compile-commands] [--tlib-arch ] [--host-arch i386|aarch64] [-- ]" + echo +@@ -42,3 +49,9 @@ + echo "-B bundle target runtime (default value: $RID, requires --net, -t)" +- echo "--profile-build build optimized for tlib profiling" ++ echo "-F select the target framework for which Renode should be built (default value: $TFM)" ++ echo "--profile-build build optimized for profiling" ++ echo "--tlib-only only build tlib" ++ echo "--tlib-arch build only single arch (implies --tlib-only)" ++ echo "--tlib-export-compile-commands build tlibs with 'compile_commands.json' (requires --tlib-arch)" ++ echo "--host-arch build with a specific tcg host architecture (default: i386)" ++ echo "--skip-dotnet-target-generation don't generate 'Directory.Build.targets' file, useful when experimenting with different build settings" + echo " arguments to pass to the build system" +@@ -46,3 +59,3 @@ + +-while getopts "cdvpnstb:o:B:-:" opt ++while getopts "cdvpnstb:o:B:F:a:-:" opt + do +@@ -81,2 +94,9 @@ + ;; ++ F) ++ if ! $NET; then ++ echo "-F requires --net being set" ++ exit 1 ++ fi ++ TFM=$OPTARG ++ ;; + -) +@@ -100,3 +120,28 @@ + "profile-build") +- PARAMS+=('p:TlibProfilingBuild=true') ++ CMAKE_COMMON="-DPROFILING_BUILD=ON" ++ ;; ++ "tlib-only") ++ TLIB_ONLY=true ++ ;; ++ "tlib-arch") ++ # This only makes sense with '--tlib-only' set; it might as well imply it ++ TLIB_ONLY=true ++ shift $((OPTIND-1)) ++ TLIB_ARCH=$1 ++ OPTIND=2 ++ ;; ++ "tlib-export-compile-commands") ++ if [ -z $TLIB_ARCH ]; then ++ echo "--tlib-export-compile-commands requires --tlib-arch begin set" ++ exit 1 ++ fi ++ TLIB_EXPORT_COMPILE_COMMANDS=true ++ ;; ++ "host-arch") ++ shift $((OPTIND-1)) ++ HOST_ARCH=$1 ++ OPTIND=2 ++ ;; ++ "skip-dotnet-target-generation") ++ GENERATE_DOTNET_BUILD_TARGET=false + ;; +@@ -184,3 +229,4 @@ + BUILD_TARGET=Windows +- TFM="net6.0-windows10.0.17763.0" ++ TFM="$TFM-windows10.0.17763.0" ++ RID="win-x64" + else +@@ -189,10 +235,34 @@ + ++if [[ $GENERATE_DOTNET_BUILD_TARGET = true ]]; then ++ if $ON_WINDOWS; then ++ # CsWinRTAotOptimizerEnabled is disabled due to a bug in dotnet-sdk. ++ # See: https://github.com/dotnet/sdk/issues/44026 ++ OS_SPECIFIC_TARGET_OPTS='false' ++ fi ++ ++cat < "$(get_path "$PWD/Directory.Build.targets")" ++ ++ ++ $TFM ++ ${OS_SPECIFIC_TARGET_OPTS:+${OS_SPECIFIC_TARGET_OPTS}} ++ ++ ++EOF ++ ++fi ++ + if $NET + then ++ export DOTNET_CLI_TELEMETRY_OPTOUT=1 + CS_COMPILER="dotnet build" + TARGET="`get_path \"$PWD/Renode_NET.sln\"`" ++ BUILD_TYPE="dotnet" + else + TARGET="`get_path \"$PWD/Renode.sln\"`" ++ BUILD_TYPE="mono" + fi + ++OUT_BIN_DIR="$(get_path "output/bin/${CONFIGURATION}")" ++BUILD_TYPE_FILE=$(get_path "${OUT_BIN_DIR}/build_type") ++ + # Verify Mono and mcs version on Linux and macOS +@@ -203,3 +273,3 @@ + MINIMUM_MONO=`get_min_mono_version` +- echo "mcs not found. Renode requries Mono $MINIMUM_MONO or newer. Please refer to documentation for installation instructions. Exiting!" ++ echo "mcs not found. Renode requires Mono $MINIMUM_MONO or newer. Please refer to documentation for installation instructions. Exiting!" + exit 1 +@@ -237,20 +307,3 @@ + +-# Build CCTask in Release configuration +-CCTASK_OUTPUT=`mktemp` +-CCTASK_BUILD_ARGS=($NET_FRAMEWORK_VER p:Configuration=Release p:Platform="\"$BUILD_PLATFORM\"") +-set +e +-CCTASK_SLN=CCTask.sln +-if $NET +-then +- CCTASK_SLN=CCTask_NET.sln +-fi +-eval "$CS_COMPILER $(build_args_helper "${CCTASK_BUILD_ARGS[@]}") $(get_path $ROOT_PATH/lib/cctask/$CCTASK_SLN)" 2>&1 > $CCTASK_OUTPUT +- +-if [ $? -ne 0 ]; then +- cat $CCTASK_OUTPUT +- rm $CCTASK_OUTPUT +- exit 1 +-fi +-rm $CCTASK_OUTPUT +-set -e ++CORES_PATH="$ROOT_PATH/src/Infrastructure/src/Emulator/Cores" + +@@ -259,19 +312,22 @@ + then +- if ! $NET +- then +- PARAMS+=(t:Clean) +- fi +- for conf in Debug Release ++ for project_dir in $(find "$(get_path "${ROOT_PATH}/src")" -iname '*.csproj' -exec dirname '{}' \;) + do +- for build_target in Windows Mono Headless ++ for dir in {bin,obj}/{Debug,Release} + do +- if $NET ++ output_dir="$(get_path "${project_dir}/${dir}")" ++ if [[ -d "${output_dir}" ]] + then +- dotnet clean $(build_args_helper ${PARAMS[@]}) $(build_args_helper p:Configuration=${conf}${build_target}) "$TARGET" +- else +- $CS_COMPILER $(build_args_helper ${PARAMS[@]}) $(build_args_helper p:Configuration=${conf}${build_target}) "$TARGET" ++ echo "Removing: ${output_dir}" ++ rm -rf "${output_dir}" + fi + done +- rm -fr $OUTPUT_DIRECTORY/bin/$conf + done ++ ++ # Manually clean the main output directory as it's location is non-standard ++ main_output_dir="$(get_path "${OUTPUT_DIRECTORY}/bin")" ++ if [[ -d "${main_output_dir}" ]] ++ then ++ echo "Removing: ${main_output_dir}" ++ rm -rf "${main_output_dir}" ++ fi + exit 0 +@@ -279,2 +335,13 @@ + ++# Check if a full rebuild is needed ++if [[ -f "$BUILD_TYPE_FILE" ]] ++then ++ if [[ "$(cat "$BUILD_TYPE_FILE")" != "$BUILD_TYPE" ]] ++ then ++ echo "Attempted to build Renode in a different configuration than the previous build" ++ echo "Please run '$0 -c' to clean the previous build before continuing" ++ exit 1 ++ fi ++fi ++ + # check weak implementations of core libraries +@@ -286,12 +353,105 @@ + ++# Paths for tlib ++CORES_BUILD_PATH="$CORES_PATH/obj/$CONFIGURATION" ++CORES_BIN_PATH="$CORES_PATH/bin/$CONFIGURATION" ++ ++# Cmake generator, handled in their own variable since the names contain spaces ++if $ON_WINDOWS ++then ++ CMAKE_GEN="-GMinGW Makefiles" ++else ++ CMAKE_GEN="-GUnix Makefiles" ++fi ++ ++# Macos architecture flags, to make rosetta work properly ++if $ON_OSX ++then ++ CMAKE_COMMON+=" -DCMAKE_OSX_ARCHITECTURES=x86_64" ++ if [ $HOST_ARCH == "aarch64" ]; then ++ CMAKE_COMMON+=" -DCMAKE_OSX_ARCHITECTURES=arm64" ++ fi ++fi ++ ++# This list contains all cores that will be built. ++# If you are adding a new core or endianness add it here to have the correct tlib built ++CORES=(arm.le arm.be arm64.le arm-m.le arm-m.be ppc.le ppc.be ppc64.le ppc64.be i386.le x86_64.le riscv.le riscv64.le sparc.le sparc.be xtensa.le) ++ ++# if '--tlib-arch' was used - pick the first matching one ++if [[ ! -z $TLIB_ARCH ]]; then ++ NONE_MATCHED=true ++ for potential_match in "${CORES[@]}"; do ++ if [[ $potential_match == "$TLIB_ARCH"* ]]; then ++ CORES=($potential_match) ++ echo "Compiling tlib for $potential_match" ++ NONE_MATCHED=false ++ break ++ fi ++ done ++ if $NONE_MATCHED ; then ++ echo "Failed to match any tlib arch" ++ exit 1 ++ fi ++fi ++ ++# build tlib ++for core_config in "${CORES[@]}" ++do ++ CORE="$(echo $core_config | cut -d '.' -f 1)" ++ ENDIAN="$(echo $core_config | cut -d '.' -f 2)" ++ BITS=32 ++ # Check if core is 64-bit ++ if [[ $CORE =~ "64" ]]; then ++ BITS=64 ++ fi ++ # Core specific flags to cmake ++ CMAKE_CONF_FLAGS="-DTARGET_ARCH=$CORE -DTARGET_WORD_SIZE=$BITS -DCMAKE_BUILD_TYPE=$CONFIGURATION" ++ CORE_DIR=$CORES_BUILD_PATH/$CORE/$ENDIAN ++ mkdir -p $CORE_DIR ++ pushd "$CORE_DIR" > /dev/null ++ if [[ $ENDIAN == "be" ]]; then ++ CMAKE_CONF_FLAGS+=" -DTARGET_BIG_ENDIAN=1" ++ fi ++ if [[ "$TLIB_EXPORT_COMPILE_COMMANDS" = true ]]; then ++ CMAKE_CONF_FLAGS+=" -DCMAKE_EXPORT_COMPILE_COMMANDS=1" ++ fi ++ cmake "$CMAKE_GEN" $CMAKE_COMMON $CMAKE_CONF_FLAGS -DHOST_ARCH=$HOST_ARCH $CORES_PATH ++ cmake --build . ++ CORE_BIN_DIR=$CORES_BIN_PATH/lib ++ mkdir -p $CORE_BIN_DIR ++ if $ON_OSX; then ++ # macos `cp` does not have the -u flag ++ cp -v tlib/*.so $CORE_BIN_DIR/ ++ else ++ cp -u -v tlib/*.so $CORE_BIN_DIR/ ++ fi ++ # copy compile_commands.json to tlib directory ++ if [[ "$TLIB_EXPORT_COMPILE_COMMANDS" = true ]]; then ++ command cp -v -f $CORE_DIR/compile_commands.json $CORES_PATH/tlib/ ++ fi ++ popd > /dev/null ++done ++ ++if $TLIB_ONLY ++then ++ exit 0 ++fi ++ + # build + eval "$CS_COMPILER $(build_args_helper "${PARAMS[@]}") $TARGET" ++echo -n "$BUILD_TYPE" > "$BUILD_TYPE_FILE" + + # copy llvm library +-if $NET +-then +- cp src/Infrastructure/src/Emulator/Peripherals/bin/$CONFIGURATION/$TFM/libllvm-disas.* output/bin/$CONFIGURATION/$TFM ++LLVM_LIB="libllvm-disas" ++if [[ $HOST_ARCH == "aarch64" ]]; then ++ # aarch64 host binaries have a different name ++ LLVM_LIB="libllvm-disas-aarch64" ++fi ++if [[ "${DETECTED_OS}" == "windows" ]]; then ++ LIB_EXT="dll" ++elif [[ "${DETECTED_OS}" == "osx" ]]; then ++ LIB_EXT="dylib" + else +- cp src/Infrastructure/src/Emulator/Peripherals/bin/$CONFIGURATION/libllvm-disas.* output/bin/$CONFIGURATION ++ LIB_EXT="so" + fi ++cp lib/resources/llvm/$LLVM_LIB.$LIB_EXT $OUT_BIN_DIR/libllvm-disas.$LIB_EXT + +@@ -326,11 +486,24 @@ + then +- # Restore dependecies for linux-x64 runtime. It prevents error NETSDK1112 during publish. +- dotnet restore --runtime linux-x64 Renode_NET.sln +- +- eval "dotnet publish -f $TFM --self-contained false $(build_args_helper "${PARAMS[@]}") $TARGET" +- export RID TFM +- $ROOT_PATH/tools/packaging/make_linux_dotnet_package.sh $params ++ # dotnet package on linux uses a separate script ++ if $ON_LINUX ++ then ++ # maxcpucount:1 to avoid an error with multithreaded publish ++ eval "dotnet publish -maxcpucount:1 -f $TFM --self-contained false $(build_args_helper "${PARAMS[@]}") $TARGET" ++ export RID TFM ++ $ROOT_PATH/tools/packaging/make_linux_dotnet_package.sh $params ++ # Source package bundles nuget dependencies required for building the dotnet version of Renode ++ # so it can only be built when using dotnet. The generated package can also be used with Mono/.NETFramework ++ $ROOT_PATH/tools/packaging/make_source_package.sh $params ++ elif $ON_WINDOWS && ! $PORTABLE ++ then ++ # No Non portable dotnet package on windows yet ++ echo "Only portable dotnet packages are supported on windows. Rerun build.sh with -t flag to build portable" ++ exit 1 ++ elif $ON_OSX ++ then ++ echo "dotnet packages not supported on ${DETECTED_OS}" ++ exit 1 ++ fi + else + $ROOT_PATH/tools/packaging/make_${DETECTED_OS}_packages.sh $params +- $ROOT_PATH/tools/packaging/make_source_package.sh $params + fi +@@ -341,16 +514,17 @@ + PARAMS+=(p:PORTABLE=true) +- if $ON_LINUX ++ if $NET + then +- if $NET +- then +- eval "dotnet publish -r $RID -f $TFM --self-contained true $(build_args_helper "${PARAMS[@]}") $TARGET" +- export RID TFM +- $ROOT_PATH/tools/packaging/make_linux_portable_dotnet.sh $params +- else +- $ROOT_PATH/tools/packaging/make_linux_portable.sh $params +- fi ++ # maxcpucount:1 to avoid an error with multithreaded publish ++ eval "dotnet publish -maxcpucount:1 -r $RID -f $TFM --self-contained true $(build_args_helper "${PARAMS[@]}") $TARGET" ++ export RID TFM ++ $ROOT_PATH/tools/packaging/make_${DETECTED_OS}_portable_dotnet.sh $params + else +- echo "Portable packages are only available on Linux. Exiting!" +- exit 1 ++ if $ON_LINUX ++ then ++ $ROOT_PATH/tools/packaging/make_linux_portable.sh $params ++ else ++ echo "Portable packages for Mono are only available on Linux. Exiting!" ++ exit 1 ++ fi + fi +-fi ++fi +\ No newline at end of file diff --git a/recipes/renode-cli/recipe.yaml b/recipes/renode-cli/recipe.yaml new file mode 100644 index 0000000000000..2fdfce160872d --- /dev/null +++ b/recipes/renode-cli/recipe.yaml @@ -0,0 +1,114 @@ +context: + name: renode-cli + version: "1.15.3" + python_min: "3.6" + +package: + name: ${{ name|lower }} + version: ${{ version }} + +source: + - url: https://github.com/renode/renode/archive/refs/tags/v${{ version }}.tar.gz + sha256: 692604eba16476596ddbc91a4cba1bd5da681dbda076d1980b81f1d333edb7c0 + patches: + - if: unix + then: + - patches/update-IronPython-Renode_NET.csproj.patch + - patches/update-for-cmake-build.sh.patch + - patches/resolve-posix-unix.patch + - git: https://github.com/renode/renode-infrastructure.git + # rev: 9736cf57e9e9518fe0e53a58cecdb09aee404a4f # no CMakeLists.txt + rev: 24c2b35b1b7fb46e47961c08c486fd57c2640b8b + target_directory: renode-infrastructure + patches: + - if: unix + then: + - patches/update-IronPython-Unittest_NET.csproj.patch + +build: + number: 0 + noarch: generic + +requirements: + build: + - dotnet + - nuget-license + - git + - if: unix + then: + - ${{ compiler('c') }} + - ${{ stdlib('c') }} + - autoconf + - automake + - cmake + - libtool + - make + - sed + else: + - m2-sed + host: + - dotnet + # - netifaces + # - psutil + # - python ${{ python_min }}.* + # - pyyaml + # - requests + # - if: unix + # then: + # - atk + # - cairo + # - fontconfig + # - gtk3 + # - glib + # - mono + # - pango + # - pcre + run: + - dotnet + # - netifaces + # - psutil + # - python >=${{ python_min }} + # - pyyaml + # - requests + # - robotframework + # - if: unix + # then: + # - atk + # - cairo + # - fontconfig + # - gtk3 + # - glib + # - mono + # - pango + # - pcre + +tests: + - package_contents: + bin: + - renode + - renode.cmd + - renode-test + - script: + - renode --help + - renode-test + +about: + homepage: https://github.com/renode/renode + summary: "Antmicro's open source simulation and virtual development framework for complex embedded systems" + description: | + Renode was created by Antmicro as a virtual development tool for multi-node + embedded networks (both wired and wireless) and is intended to enable a scalable + workflow for creating effective, tested and secure IoT systems. + + With Renode, developing, testing, debugging and simulating unmodified software + for IoT devices is fast, cost-effective and reliable. + license: MIT + license_file: + - LICENSE + - licensefiles/ + documentation: https://renode.io/ + repository: https://github.com/renode/renode + +extra: + recipe-maintainers: + - MementoRC From fca589071b5b993241a722efe99f8836fc4c30ff Mon Sep 17 00:00:00 2001 From: memento Date: Sun, 26 Jan 2025 18:03:05 -0600 Subject: [PATCH 02/26] (fix) remove selectors. fix typos --- recipes/renode-cli/build.sh | 4 +-- recipes/renode-cli/recipe.yaml | 51 ++++++---------------------------- 2 files changed, 10 insertions(+), 45 deletions(-) diff --git a/recipes/renode-cli/build.sh b/recipes/renode-cli/build.sh index 85ff06dd68c42..257ce1fb599cf 100644 --- a/recipes/renode-cli/build.sh +++ b/recipes/renode-cli/build.sh @@ -101,12 +101,12 @@ exec "${DOTNET_ROOT}"/dotnet exec "${CONDA_PREFIX}"/libexec/renode-cli/Renode.dl EOF chmod +x ${PREFIX}/bin/renode -ccat > $PREFIX/bin/renode.cmd <<"EOF" +cat > $PREFIX/bin/renode.cmd <<"EOF" call %DOTNET_ROOT%\dotnet exec %CONDA_PREFIX%\libexec\libexec\renode-cli\Renode.dll %* EOF chmod +x ${PREFIX}/bin/renode -at > $PREFIX/bin/renode-test <<"EOF" +cat > $PREFIX/bin/renode-test <<"EOF" #!/usr/bin/env bash STTY_CONFIG=`stty -g 2>/dev/null` diff --git a/recipes/renode-cli/recipe.yaml b/recipes/renode-cli/recipe.yaml index 2fdfce160872d..8bc03bfda4a46 100644 --- a/recipes/renode-cli/recipe.yaml +++ b/recipes/renode-cli/recipe.yaml @@ -31,56 +31,21 @@ build: requirements: build: + - ${{ compiler('c') }} + - ${{ stdlib('c') }} - dotnet - nuget-license - git - - if: unix - then: - - ${{ compiler('c') }} - - ${{ stdlib('c') }} - - autoconf - - automake - - cmake - - libtool - - make - - sed - else: - - m2-sed + - autoconf + - automake + - cmake + - libtool + - make + - sed host: - dotnet - # - netifaces - # - psutil - # - python ${{ python_min }}.* - # - pyyaml - # - requests - # - if: unix - # then: - # - atk - # - cairo - # - fontconfig - # - gtk3 - # - glib - # - mono - # - pango - # - pcre run: - dotnet - # - netifaces - # - psutil - # - python >=${{ python_min }} - # - pyyaml - # - requests - # - robotframework - # - if: unix - # then: - # - atk - # - cairo - # - fontconfig - # - gtk3 - # - glib - # - mono - # - pango - # - pcre tests: - package_contents: From b29216e2eac7fbdf74736913c4bb004531c265ee Mon Sep 17 00:00:00 2001 From: memento Date: Sun, 26 Jan 2025 20:36:18 -0600 Subject: [PATCH 03/26] (fix) add tests requirements --- recipes/renode-cli/recipe.yaml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/recipes/renode-cli/recipe.yaml b/recipes/renode-cli/recipe.yaml index 8bc03bfda4a46..147d5a600e231 100644 --- a/recipes/renode-cli/recipe.yaml +++ b/recipes/renode-cli/recipe.yaml @@ -56,6 +56,12 @@ tests: - script: - renode --help - renode-test + requirements: + run: + - robotframework 6.1 + - robotframework-retryfailed 0.2.0 + - psutil 5.9.3 + - pyyaml 6.0 about: homepage: https://github.com/renode/renode From 9e65189e67ffc23b44e68e8b74bd3f0205d35257 Mon Sep 17 00:00:00 2001 From: memento Date: Mon, 27 Jan 2025 21:45:10 -0600 Subject: [PATCH 04/26] (fix) separate arch/noarch --- recipes/renode-cli/build.sh | 51 +-- .../renode-cli/helpers/build-with-cmake.sh | 107 ----- .../renode-cli/patches/Cores-CMakeLists.txt | 39 ++ ...pdate-IronPython-Unittest_NET.csproj.patch | 19 +- .../update-cores.template_NET.csproj.patch | 46 +++ recipes/renode-cli/recipe.yaml | 25 +- recipes/renode-cli/variants.yaml | 7 + recipes/renode-cores/build.bat | 44 +++ recipes/renode-cores/build.sh | 25 ++ .../renode-cores/patches/Cores-CMakeLists.txt | 39 ++ .../renode-cores/patches/tlib-CMakeLists.txt | 232 +++++++++++ .../patches/update-for-cmake-build.sh.patch | 367 ++++++++++++++++++ recipes/renode-cores/recipe.yaml | 73 ++++ recipes/renode-cores/scripts/activate.bat | 2 + recipes/renode-cores/variants.yaml | 7 + 15 files changed, 908 insertions(+), 175 deletions(-) delete mode 100644 recipes/renode-cli/helpers/build-with-cmake.sh create mode 100644 recipes/renode-cli/patches/Cores-CMakeLists.txt create mode 100644 recipes/renode-cli/patches/update-cores.template_NET.csproj.patch create mode 100644 recipes/renode-cli/variants.yaml create mode 100644 recipes/renode-cores/build.bat create mode 100644 recipes/renode-cores/build.sh create mode 100644 recipes/renode-cores/patches/Cores-CMakeLists.txt create mode 100644 recipes/renode-cores/patches/tlib-CMakeLists.txt create mode 100644 recipes/renode-cores/patches/update-for-cmake-build.sh.patch create mode 100644 recipes/renode-cores/recipe.yaml create mode 100755 recipes/renode-cores/scripts/activate.bat create mode 100644 recipes/renode-cores/variants.yaml diff --git a/recipes/renode-cli/build.sh b/recipes/renode-cli/build.sh index 257ce1fb599cf..abc7dfbfb8113 100644 --- a/recipes/renode-cli/build.sh +++ b/recipes/renode-cli/build.sh @@ -2,17 +2,6 @@ set -o xtrace -o nounset -o pipefail -o errexit -update_antmicro_submodule() { - local commit=$1 - local module=$2 - - git clone https://github.com/antmicro/${module}.git - pushd ${module} - git fetch origin ${commit} - git submodule update --init --recursive - popd -} - mkdir -p ${PREFIX}/bin mkdir -p ${PREFIX}/libexec/${PKG_NAME} export PATH="${DOTNET_ROOT}/dotnet:${PATH}" @@ -22,29 +11,8 @@ install_prefix="${PREFIX}/opt/${PKG_NAME}" dotnet_version=$(dotnet --version) framework_version=${dotnet_version%.*} -mkdir -p ${SRC_DIR}/src/Infrastructure/ -mv renode-infrastructure/* ${SRC_DIR}/src/Infrastructure/ && rm -rf renode-infrastructure - -mkdir -p ${SRC_DIR}/lib -pushd ${SRC_DIR}/lib - git clone https://github.com/renode/renode-resources.git - pushd renode-resources && git submodule update --init --recursive && popd - mv renode-resources resources - - update_antmicro_submodule b1d3d03d602581fc2bed6db586b5e5c3388456c7 AntShell - update_antmicro_submodule e7bfa5873f2300e6e87c185f466e227762dbf4b2 BigGustave - update_antmicro_submodule b0c2a820f28a7bdedb85575bfca6447c9e7fa955 CxxDemangler - update_antmicro_submodule de4e4f6ffab555771285cb810f17f61cfd38ef39 ELFsharp - rm -rf ELFSharp && mv ELFsharp ELFSharp - update_antmicro_submodule e379e8ae696676afffed2f33dd8083855af00f2f FdtSharp - update_antmicro_submodule 33e5ab24eaaab488e9a94f1a40d5d6ae2f7f02f1 InpliTftpServer - update_antmicro_submodule c6514e99f2c35afec083b9f4a7eec3408c0081d1 Migrant - update_antmicro_submodule 2fe74fd257f6d6f86076c100952178f347098b3d Packet.Net - update_antmicro_submodule 33d24f1307d267c34b7f1439bc159a8825c5aa3d bc-csharp - update_antmicro_submodule bde21d04fbfc540989b7a0ac13a54eae8b756994 cctask - update_antmicro_submodule e8c2051dec56c5ccd3a4927b07a5740f34eed8c8 options-parser - update_antmicro_submodule 71af57ef4fec29e416f48160b8918057a58548a9 termsharp -popd +# Update the submodule to the latest commit CMakeLists.txt +cp ${RECIPE_DIR}/patches/Cores-CMakeLists.txt ${SRC_DIR}/src/Infrastructure/src/Emulator/Cores/CMakeLists.txt find lib src tests -name "*.csproj" -exec sed -i -E \ -e "s/([>;])net6.0([<;])/\1net${framework_version}\2/" \ @@ -55,19 +23,26 @@ find . -type d -name "obj" -exec rm -rf {} + find . -type d -name "bin" -exec rm -rf {} + sed -i -E 's/(ReleaseHeadless\|Any .+ = )Debug/\1Release/' Renode_NET.sln -export CC=${CC} -export CFLAGS="${CFLAGS} -fPIC" +# export CC=${CC} +# export CFLAGS="${CFLAGS} -fPIC" + +# Prevent CMake build since we provide the binaries +sed -i -E 's;^(\s*)(cmake|\./check_weak_implementations|cp\s+(\-u\s+)?\-v\s+tlib/\*\.so);\1true \|\| \2;' build.sh +mkdir -p ${SRC_DIR}/src/Infrastructure/src/Emulator/Cores/bin/Release/lib +cp ${BUILD_PREFIX}/lib/renode-cores/* ${SRC_DIR}/src/Infrastructure/src/Emulator/Cores/bin/Release/lib +rm -f ${SRC_DIR}/src/Infrastructure/src/Emulator/Cores/translate*.cproj if [[ "${target_platform}" == linux-* ]] || [[ "${target_platform}" == osx-* ]]; then _os_name=${target_platform%-*} - + chmod +x build.sh tools/{building,packaging}/*.sh ./build.sh --net --no-gui --force-net-framework-version ${framework_version} else _os_name=windows + chmod +x build.sh tools/{building,packaging}/*.sh ./build.sh --net --no-gui --force-net-framework-version ${framework_version} fi - +# Install procedure mkdir -p $PREFIX/libexec/${PKG_NAME} cp -r output/bin/Release/net${framework_version}/* $PREFIX/libexec/${PKG_NAME}/ diff --git a/recipes/renode-cli/helpers/build-with-cmake.sh b/recipes/renode-cli/helpers/build-with-cmake.sh deleted file mode 100644 index 6da064642842d..0000000000000 --- a/recipes/renode-cli/helpers/build-with-cmake.sh +++ /dev/null @@ -1,107 +0,0 @@ -HOST_ARCH="i386" -CMAKE_COMMON="" -CORES_PATH="$ROOT_PATH/src/Infrastructure/src/Emulator/Cores" -OUT_BIN_DIR="$(get_path "output/bin/${CONFIGURATION}")" -BUILD_TYPE_FILE=$(get_path "${OUT_BIN_DIR}/build_type") - -# clean instead of building -if $CLEAN -then - for project_dir in $(find "$(get_path "${ROOT_PATH}/src")" -iname '*.csproj' -exec dirname '{}' \;) - do - for dir in {bin,obj}/{Debug,Release} - do - output_dir="$(get_path "${project_dir}/${dir}")" - if [[ -d "${output_dir}" ]] - then - echo "Removing: ${output_dir}" - rm -rf "${output_dir}" - fi - done - done - - # Manually clean the main output directory as it's location is non-standard - main_output_dir="$(get_path "${OUTPUT_DIRECTORY}/bin")" - if [[ -d "${main_output_dir}" ]] - then - echo "Removing: ${main_output_dir}" - rm -rf "${main_output_dir}" - fi - exit 0 -fi - -# Check if a full rebuild is needed -if [[ -f "$BUILD_TYPE_FILE" ]] -then - if [[ "$(cat "$BUILD_TYPE_FILE")" != "$BUILD_TYPE" ]] - then - echo "Attempted to build Renode in a different configuration than the previous build" - echo "Please run '$0 -c' to clean the previous build before continuing" - exit 1 - fi -fi - -# Paths for tlib -CORES_BUILD_PATH="$CORES_PATH/obj/$CONFIGURATION" -CORES_BIN_PATH="$CORES_PATH/bin/$CONFIGURATION" - -# Cmake generator, handled in their own variable since the names contain spaces -if $ON_WINDOWS -then - CMAKE_GEN="-GMinGW Makefiles" -else - CMAKE_GEN="-GUnix Makefiles" -fi - -# Macos architecture flags, to make rosetta work properly -if $ON_OSX -then - CMAKE_COMMON+=" -DCMAKE_OSX_ARCHITECTURES=x86_64" - if [ $HOST_ARCH == "aarch64" ]; then - CMAKE_COMMON+=" -DCMAKE_OSX_ARCHITECTURES=arm64" - fi -fi - -# This list contains all cores that will be built. -# If you are adding a new core or endianness add it here to have the correct tlib built -CORES=(arm.le arm.be arm64.le arm-m.le arm-m.be ppc.le ppc.be ppc64.le ppc64.be i386.le x86_64.le riscv.le riscv64.le sparc.le sparc.be xtensa.le) - -# build tlib -for core_config in "${CORES[@]}" -do - CORE="$(echo $core_config | cut -d '.' -f 1)" - ENDIAN="$(echo $core_config | cut -d '.' -f 2)" - BITS=32 - # Check if core is 64-bit - if [[ $CORE =~ "64" ]]; then - BITS=64 - fi - # Core specific flags to cmake - CMAKE_CONF_FLAGS="-DTARGET_ARCH=$CORE -DTARGET_WORD_SIZE=$BITS -DCMAKE_BUILD_TYPE=$CONFIGURATION" - CORE_DIR=$CORES_BUILD_PATH/$CORE/$ENDIAN - mkdir -p $CORE_DIR - pushd "$CORE_DIR" > /dev/null - if [[ $ENDIAN == "be" ]]; then - CMAKE_CONF_FLAGS+=" -DTARGET_BIG_ENDIAN=1" - fi - cmake "$CMAKE_GEN" $CMAKE_COMMON $CMAKE_CONF_FLAGS -DHOST_ARCH=$HOST_ARCH $CORES_PATH - cmake --build . -j$(nproc) - CORE_BIN_DIR=$CORES_BIN_PATH/lib - mkdir -p $CORE_BIN_DIR - if $ON_OSX; then - # macos `cp` does not have the -u flag - cp -v tlib/*.so $CORE_BIN_DIR/ - else - cp -u -v tlib/*.so $CORE_BIN_DIR/ - fi - # copy compile_commands.json to tlib directory - if [[ "$TLIB_EXPORT_COMPILE_COMMANDS" = true ]]; then - command cp -v -f $CORE_DIR/compile_commands.json $CORES_PATH/tlib/ - fi - popd > /dev/null -done - -if $TLIB_ONLY -then - exit 0 -fi diff --git a/recipes/renode-cli/patches/Cores-CMakeLists.txt b/recipes/renode-cli/patches/Cores-CMakeLists.txt new file mode 100644 index 0000000000000..6570fa08b1d85 --- /dev/null +++ b/recipes/renode-cli/patches/Cores-CMakeLists.txt @@ -0,0 +1,39 @@ +cmake_minimum_required(VERSION 3.12) + +project (renode-cores LANGUAGES C) + +add_subdirectory(tlib) + +# Add Renode sources to tlib target so that they get built as part of it + +if(NOT TARGET_ACTUAL_ARCH) + message(FATAL_ERROR "TARGET_ACTUAL_ARCH has to be set by tlib CMakeLists.txt!") +endif() + +file (GLOB RENODE_SOURCES + "renode/*.c" + "renode/arch/${TARGET_ACTUAL_ARCH}/*.c" +) + +target_sources(tlib PRIVATE + ${RENODE_SOURCES} +) + +# Include directories with Renode headers when building tlib + +target_include_directories(tlib PRIVATE + renode/include +) + +# Set tlib output filename + +set (ENDIAN_STR "le") +if (TARGET_BIG_ENDIAN) + set (ENDIAN_STR "be") +endif() + +set_target_properties(tlib PROPERTIES + PREFIX "" + OUTPUT_NAME "translate-${TARGET_ARCH}-${ENDIAN_STR}" + SUFFIX ".so" +) \ No newline at end of file diff --git a/recipes/renode-cli/patches/update-IronPython-Unittest_NET.csproj.patch b/recipes/renode-cli/patches/update-IronPython-Unittest_NET.csproj.patch index b7509c25637e2..cfb34811a916d 100644 --- a/recipes/renode-cli/patches/update-IronPython-Unittest_NET.csproj.patch +++ b/recipes/renode-cli/patches/update-IronPython-Unittest_NET.csproj.patch @@ -1,18 +1,15 @@ ---- a/src/Emulator/Main/Tests/UnitTests/UnitTests_NET.csproj -+++ b/src/Emulator/Main/Tests/UnitTests/UnitTests_NET.csproj +--- a/src/Infrastructure/src/Emulator/Main/Tests/UnitTests/UnitTests_NET.csproj ++++ b/src/Infrastructure/src/Emulator/Main/Tests/UnitTests/UnitTests_NET.csproj @@ -18,5 +18,4 @@ - -- ..\..\..\..\..\..\..\lib\resources\libraries\ironpython-netcore\IronPython.dll +- ..\..\..\..\..\..\..\lib\resources\libraries\IronPython.dll - + + ---- a/src/Emulator/Main/Foreign/Player.cs -+++ b/src/Emulator/Main/Foreign/Player.cs -@@ -26,3 +26,4 @@ - this.stream = stream; -+ byte[] metadataBytes = null; -- deserializer = new Serializer(new Settings(useBuffering: false, disableTypeStamping: true)).ObtainOpenStreamDeserializer(stream); -+ deserializer = new Serializer(new Settings(useBuffering: false, disableTypeStamping: true)).ObtainOpenStreamDeserializer(stream, out metadataBytes); - handlersCache = new Dictionary(); +--- a/src/Infrastructure/src/Emulator/Peripherals/Peripherals/Sensors/PAC1934.cs ++++ b/src/Infrastructure/src/Emulator/Peripherals/Peripherals/Sensors/PAC1934.cs +@@ -131,1 +131,1 @@ +- return BitConverter.GetBytes(registers.Read(offset)); ++ return BitConverter.GetBytes((short)registers.Read(offset)); diff --git a/recipes/renode-cli/patches/update-cores.template_NET.csproj.patch b/recipes/renode-cli/patches/update-cores.template_NET.csproj.patch new file mode 100644 index 0000000000000..184654dd4bf06 --- /dev/null +++ b/recipes/renode-cli/patches/update-cores.template_NET.csproj.patch @@ -0,0 +1,46 @@ +--- a/src/Infrastructure/src/Emulator/Cores/cores.template_NET.csproj 2024-09-17 05:29:16.000000000 -0500 ++++ b/src/Infrastructure/src/Emulator/Cores/cores.template_NET.csproj 2025-01-27 21:35:32.396468884 -0600 +@@ -1,4 +1,2 @@ + +- +- + +@@ -17,18 +15,9 @@ + +- +- +- +- 32 +- 0 +- +- +- +- +- +- +- ++ + +- +- Antmicro.Renode.%(Filename)%(Extension) ++ ++ Antmicro.Renode.translate-$(Architecture)-le.so ++ ++ ++ Antmicro.Renode.translate-$(Architecture)-be.so + +@@ -36,11 +25,2 @@ + +- +- +- +- +- +- +- +- ++ +\ No newline at end of file diff --git a/recipes/renode-cli/recipe.yaml b/recipes/renode-cli/recipe.yaml index 147d5a600e231..167ffc1f774dc 100644 --- a/recipes/renode-cli/recipe.yaml +++ b/recipes/renode-cli/recipe.yaml @@ -8,22 +8,16 @@ package: version: ${{ version }} source: - - url: https://github.com/renode/renode/archive/refs/tags/v${{ version }}.tar.gz - sha256: 692604eba16476596ddbc91a4cba1bd5da681dbda076d1980b81f1d333edb7c0 + - url: https://github.com/renode/renode/releases/download/v${{ version }}/renode_${{ version }}_source.tar.xz + sha256: 40c50afe8db86a9c63f4a86b93116a6babd43bf241cfaac47b2c0d2cbc2b15a8 patches: - if: unix then: - patches/update-IronPython-Renode_NET.csproj.patch - patches/update-for-cmake-build.sh.patch - - patches/resolve-posix-unix.patch - - git: https://github.com/renode/renode-infrastructure.git - # rev: 9736cf57e9e9518fe0e53a58cecdb09aee404a4f # no CMakeLists.txt - rev: 24c2b35b1b7fb46e47961c08c486fd57c2640b8b - target_directory: renode-infrastructure - patches: - - if: unix - then: + - patches/update-cores.template_NET.csproj.patch - patches/update-IronPython-Unittest_NET.csproj.patch + - patches/resolve-posix-unix.patch build: number: 0 @@ -31,16 +25,9 @@ build: requirements: build: - - ${{ compiler('c') }} - - ${{ stdlib('c') }} - dotnet - nuget-license - - git - - autoconf - - automake - - cmake - - libtool - - make + - renode-cores - sed host: - dotnet @@ -59,7 +46,6 @@ tests: requirements: run: - robotframework 6.1 - - robotframework-retryfailed 0.2.0 - psutil 5.9.3 - pyyaml 6.0 @@ -83,3 +69,4 @@ about: extra: recipe-maintainers: - MementoRC + - danielnachun diff --git a/recipes/renode-cli/variants.yaml b/recipes/renode-cli/variants.yaml new file mode 100644 index 0000000000000..3fdfa2f172c02 --- /dev/null +++ b/recipes/renode-cli/variants.yaml @@ -0,0 +1,7 @@ +c_stdlib: + - if: linux + then: sysroot + - if: osx + then: macosx_deployment_target + - if: not unix + then: vs diff --git a/recipes/renode-cores/build.bat b/recipes/renode-cores/build.bat new file mode 100644 index 0000000000000..1a11cbfbb7e31 --- /dev/null +++ b/recipes/renode-cores/build.bat @@ -0,0 +1,44 @@ +setlocal EnableDelayedExpansion +set PATH=C:\cygwin64\bin\;%PATH% +set PLATFORM=Any CPU +for /r %%i in (*.sh) do CALL :convert_to_unix_newline %%i + +call bash -lc build.sh +if %errorlevel% neq 0 exit /b %errorlevel% + +REM Need to use call for all functions outside of script, otherwise label handling go crazy +call mkdir %LIBRARY_PREFIX%\renode\exec +call mkdir %LIBRARY_PREFIX%\renode\tests +call mkdir %LIBRARY_PREFIX%\renode\scripts +call mkdir %LIBRARY_PREFIX%\renode\platforms +call mkdir %LIBRARY_PREFIX%\renode\licenses +call robocopy output\bin\Release\ %LIBRARY_PREFIX%\renode\exec\ /njh /njs /ndl /S +call robocopy tests\ %LIBRARY_PREFIX%\renode\tests /njh /njs /ndl /S +call robocopy scripts\ %LIBRARY_PREFIX%\renode\scripts /njh /njs /ndl /S +call robocopy platforms\ %LIBRARY_PREFIX%\renode\platforms /njh /njs /ndl /S +call robocopy .\ %LIBRARY_PREFIX%\renode\ .renode-root +call robocopy .\ %LIBRARY_PREFIX%\renode\ LICENSE + +REM Copy all licenses. LIBRARY_PREFIX has to be converted to the Unix format first. +FOR /F "delims=" %%i IN ('cygpath.exe -u "%LIBRARY_PREFIX%"') DO set "UNIX_LIBRARY_PREFIX=%%i" +call bash -lc "tools/packaging/common_copy_licenses.sh $UNIX_LIBRARY_PREFIX/renode/licenses windows" +if %errorlevel% neq 0 exit /b %errorlevel% + + +REM Add activation script to append renode dir to PATH +if not exist %PREFIX%\etc\conda\activate.d call mkdir %PREFIX%\etc\conda\activate.d +call copy %RECIPE_DIR%\activate.bat %PREFIX%\etc\conda\activate.d\%PKG_NAME%_activate.bat +call copy %RECIPE_DIR%\activate-win.sh %PREFIX%\etc\conda\activate.d\%PKG_NAME%_activate.sh + +if not exist %PREFIX%\etc\conda\deactivate.d call mkdir %PREFIX%\etc\conda\deactivate.d +call copy %RECIPE_DIR%\deactivate-win.sh %PREFIX%\etc\conda\deactivate.d\%PKG_NAME%_deactivate.sh + +REM PS1 scripts can't modify PATH so put a PowerShell script running Renode in PATH. +if not exist %PREFIX%\Library\bin call mkdir %PREFIX%\Library\bin +call copy %RECIPE_DIR%\Renode.ps1 %PREFIX%\Library\bin\Renode.ps1 + +EXIT /B 0 + +:convert_to_unix_newline +powershell -Command "(Get-Content %~1 -Raw).Replace(\"`r\",\"\") |Set-Content -NoNewLine %~1 -Force" +EXIT /B 0 diff --git a/recipes/renode-cores/build.sh b/recipes/renode-cores/build.sh new file mode 100644 index 0000000000000..d5c2b63a6c1a9 --- /dev/null +++ b/recipes/renode-cores/build.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash + +set -o xtrace -o nounset -o pipefail -o errexit + +# Update the submodule to the latest commit CMakeLists.txt +cp ${RECIPE_DIR}/patches/Cores-CMakeLists.txt ${SRC_DIR}/src/Infrastructure/src/Emulator/Cores/CMakeLists.txt +cp ${RECIPE_DIR}/patches/tlib-CMakeLists.txt ${SRC_DIR}/src/Infrastructure/src/Emulator/Cores/tlib/CMakeLists.txt + +if [[ "${target_platform}" == linux-* ]] || [[ "${target_platform}" == osx-* ]]; then + _os_name=${target_platform%-*} + chmod +x build.sh tools/building/check_weak_implementations.sh + ./build.sh --tlib-only --net --no-gui +else + _os_name=windows + chmod +x build.sh tools/building/check_weak_implementations.sh + ./build.sh --tlib-only --net --no-gui +fi + +# Install procedure into a conda path that renode-cli can retrieve +ROOT_PATH="$(cd $(dirname $0); echo $PWD)" +CONFIGURATION="Release" +CORES_PATH="$ROOT_PATH/src/Infrastructure/src/Emulator/Cores" +CORES_BIN_PATH="$CORES_PATH/bin/$CONFIGURATION" +mkdir -p "${PREFIX}/lib/${PKG_NAME}" +tar -c -C "${CORES_BIN_PATH}/lib" . | tar -x -C "${PREFIX}/lib/${PKG_NAME}" diff --git a/recipes/renode-cores/patches/Cores-CMakeLists.txt b/recipes/renode-cores/patches/Cores-CMakeLists.txt new file mode 100644 index 0000000000000..6570fa08b1d85 --- /dev/null +++ b/recipes/renode-cores/patches/Cores-CMakeLists.txt @@ -0,0 +1,39 @@ +cmake_minimum_required(VERSION 3.12) + +project (renode-cores LANGUAGES C) + +add_subdirectory(tlib) + +# Add Renode sources to tlib target so that they get built as part of it + +if(NOT TARGET_ACTUAL_ARCH) + message(FATAL_ERROR "TARGET_ACTUAL_ARCH has to be set by tlib CMakeLists.txt!") +endif() + +file (GLOB RENODE_SOURCES + "renode/*.c" + "renode/arch/${TARGET_ACTUAL_ARCH}/*.c" +) + +target_sources(tlib PRIVATE + ${RENODE_SOURCES} +) + +# Include directories with Renode headers when building tlib + +target_include_directories(tlib PRIVATE + renode/include +) + +# Set tlib output filename + +set (ENDIAN_STR "le") +if (TARGET_BIG_ENDIAN) + set (ENDIAN_STR "be") +endif() + +set_target_properties(tlib PROPERTIES + PREFIX "" + OUTPUT_NAME "translate-${TARGET_ARCH}-${ENDIAN_STR}" + SUFFIX ".so" +) \ No newline at end of file diff --git a/recipes/renode-cores/patches/tlib-CMakeLists.txt b/recipes/renode-cores/patches/tlib-CMakeLists.txt new file mode 100644 index 0000000000000..c8218360e8360 --- /dev/null +++ b/recipes/renode-cores/patches/tlib-CMakeLists.txt @@ -0,0 +1,232 @@ +cmake_minimum_required(VERSION 3.12) + +project (tlib LANGUAGES C) + +if(CMAKE_BUILD_TYPE STREQUAL "Debug") + set(DEBUG_DEFS "-DDEBUG -DDEBUG_ON") +endif() + +option (HOST_BIG_ENDIAN "Host big endian" OFF) + +if(NOT DEFINED HOST_ARCH) + message(STATUS "'HOST_ARCH' isn't set; analyzing the CPU (${CMAKE_SYSTEM_PROCESSOR})...") + if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "(AMD64|amd64|86)") + set (HOST_ARCH "i386" CACHE STRING "Host architecture") + elseif(${CMAKE_SYSTEM_PROCESSOR} MATCHES "(aarch64|arm64)") + set (HOST_ARCH "aarch64" CACHE STRING "Host architecture") + # Has to come last to not match arm macs arm64, while still matching a cpu like armv7l + elseif(${CMAKE_SYSTEM_PROCESSOR} MATCHES "(arm)") + set (HOST_ARCH "arm" CACHE STRING "Host architecture") + else() + message(FATAL_ERROR "CMAKE_SYSTEM_PROCESSOR '${CMAKE_SYSTEM_PROCESSOR}' doesn't seem to be supported. Supported host architectures are: 'arm', 'i386', 'aarch64/arm64'. Please set 'HOST_ARCH' manually.") + endif() +endif() +message(VERBOSE "Using HOST_ARCH: ${HOST_ARCH}") + +# Detect whether the host is 32- or 64-bit +math (EXPR WORD_SIZE_FOUND "${CMAKE_SIZEOF_VOID_P} * 8") +set (HOST_WORD_SIZE "${WORD_SIZE_FOUND}" CACHE STRING "Host word size") +message(VERBOSE "Using HOST_WORD_SIZE: ${HOST_WORD_SIZE}") + +if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) + set(CMAKE_BUILD_TYPE "Release" CACHE + STRING "Choose the type of build." FORCE) + set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS + "Debug" "Release" "RelWithDebInfo") +endif() + +option (PROFILING_BUILD "Build optimized for profiling" OFF) +if(PROFILING_BUILD) + message(STATUS "Profiling enhancements are enabled") + add_definitions ( + # Forcing not to omit frame pointer can have negative impact on performance, + # so the end profiling result will not exactly be equal to running on live system. + # Unfortunately without frame pointers perf might have problem with unwinding stack + # and call traces in reports will become less readable if using frame pointers for stack unwinding. + -fno-omit-frame-pointer + -DGENERATE_PERF_MAP + -g3 + ) +elseif(CMAKE_BUILD_TYPE STREQUAL "Release") + add_definitions(-fomit-frame-pointer) +endif() + +if (HOST_ARCH MATCHES "(arm|aarch64)" AND CMAKE_BUILD_TYPE STREQUAL "Release" AND NOT CMAKE_C_COMPILER_ID STREQUAL "AppleClang") + # gcc emits a clobber error for unwind.h DECLARE_ENV_PTR() in release mode on arm targets + # so demote it to a warning in this case, but not on arm mac clang, because this flag does not exsist + add_definitions(-Wno-error=clobbered) + add_definitions(-Wno-clobbered) +endif() + +option (TARGET_BIG_ENDIAN "Target big endian" OFF) +set (TARGET_ARCH "" CACHE STRING "Target architecture") +set (TARGET_WORD_SIZE "32" CACHE STRING "Target word size") +message(VERBOSE "Target is: ${TARGET_WORD_SIZE}-bit ${TARGET_ARCH}") + +set_property (CACHE HOST_ARCH PROPERTY STRINGS i386 arm aarch64) +set_property (CACHE TARGET_ARCH PROPERTY STRINGS i386 x86_64 arm arm-m arm64 sparc ppc ppc64 riscv riscv64 xtensa) + +if(NOT HOST_ARCH) + message (FATAL_ERROR "Host architecture not set") +endif() + +if(NOT TARGET_ARCH) + message (FATAL_ERROR "Target architecture not set") +endif() + +if(TARGET_BIG_ENDIAN) + set (BIG_ENDIAN_DEF -DTARGET_WORDS_BIGENDIAN=1) +endif() + +# Let's make 'TARGET_ACTUAL_ARCH' a lowercase 'TARGET_ARCH'. +string (TOLOWER "${TARGET_ARCH}" TARGET_ACTUAL_ARCH) + +if("${TARGET_ACTUAL_ARCH}" STREQUAL "arm-m") + set (TARGET_ACTUAL_ARCH "arm") + set (ARM_M_DEF -DTARGET_PROTO_ARM_M=1) +elseif("${TARGET_ACTUAL_ARCH}" STREQUAL "ppc64") + set (TARGET_ACTUAL_ARCH "ppc") +elseif("${TARGET_ACTUAL_ARCH}" STREQUAL "riscv64") + set (TARGET_ACTUAL_ARCH "riscv") +elseif("${TARGET_ACTUAL_ARCH}" STREQUAL "x86_64") + set (TARGET_ACTUAL_ARCH "i386") +endif() + +# Let's make TARGET_ACTUAL_ARCH available in CMakes adding tlib subdirectory. Using PARENT_SCOPE +# in the top project triggers warnings though so the if below prevents them in tlib built directly. +if(NOT ${CMAKE_PROJECT_NAME} STREQUAL tlib) + set (TARGET_ACTUAL_ARCH "${TARGET_ACTUAL_ARCH}" PARENT_SCOPE) +endif() + +set(TARGET_INSN_START_EXTRA_WORDS 0) +if("${TARGET_ACTUAL_ARCH}" MATCHES "^(arm|i386|sparc)$") + set(TARGET_INSN_START_EXTRA_WORDS 1) +elseif("${TARGET_ACTUAL_ARCH}" STREQUAL "arm64") + set(TARGET_INSN_START_EXTRA_WORDS 2) +endif() + +if("${TARGET_ACTUAL_ARCH}" STREQUAL "arm64" AND NOT "${TARGET_WORD_SIZE}" STREQUAL "64") + message (FATAL_ERROR "ERROR: arm64 target has to be built with TARGET_WORD_SIZE=64") +endif() + +string (TOUPPER "${HOST_ARCH}" HOST_ARCH_U) +string (TOUPPER "${TARGET_ACTUAL_ARCH}" TARGET_ACTUAL_ARCH_U) + +set(TLIB_COMMIT_SHA "" CACHE STRING "Current tlib commit SHA") +if(NOT TLIB_COMMIT_SHA) + execute_process(COMMAND git rev-parse --short HEAD RESULT_VARIABLE GIT_RESULT OUTPUT_VARIABLE GIT_OUTPUT OUTPUT_STRIP_TRAILING_WHITESPACE WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}) + if(NOT GIT_RESULT EQUAL 0) + set(GIT_OUTPUT "undefined") + endif() + + set(TLIB_COMMIT_SHA "${GIT_OUTPUT}" CACHE STRING "Current tlib commit SHA" FORCE) +endif() + +add_subdirectory(tcg) + +if("${TARGET_ACTUAL_ARCH}" STREQUAL "riscv" OR "${TARGET_ACTUAL_ARCH}" STREQUAL "riscv64") + set(SOFTFLOAT_SPECIALIZED_ARCHITECTURE "RISCV") + add_subdirectory(softfloat-3) + set(SOFTFLOAT3 softfloat-3) + + if(CMAKE_BUILD_TYPE STREQUAL "Release" AND NOT PROFILING_BUILD) + target_compile_definitions(softfloat-3 PRIVATE + INLINE_LEVEL=5 + ) + endif() +endif() + +if (NOT CMAKE_C_COMPILER_ID MATCHES "(clang)" AND NOT "${TARGET_ACTUAL_ARCH}" STREQUAL "arm64") + # Clang throws warnings from the arm64 target's function stubs + # so do not enable -Werror in that case until that is fixed + add_definitions(-Werror) +endif() + + +add_definitions ( + -fPIC + -Wall + -Wextra + -Wno-unused-parameter + -Wno-sign-compare + + -DHOST_BITS_${HOST_WORD_SIZE} + -DHOST_${HOST_ARCH_U}=1 + -DHOST_LONG_BITS=${HOST_WORD_SIZE} + + -DTARGET_${TARGET_ACTUAL_ARCH_U}=1 + + -DTARGET_SHORT_ALIGNMENT=2 + -DTARGET_INT_ALIGNMENT=4 + -DTARGET_LONG_ALIGNMENT=4 + -DTARGET_LLONG_ALIGNMENT=4 + + -DTARGET_LONG_BITS=${TARGET_WORD_SIZE} + -DTARGET_INSN_START_EXTRA_WORDS=${TARGET_INSN_START_EXTRA_WORDS} + ${ARM_M_DEF} + + -DTCG_TARGET_${HOST_ARCH_U} + -DTLIB_COMMIT=${TLIB_COMMIT_SHA} + ${BIG_ENDIAN_DEF} + ${DEBUG_DEFS} + ) + +if("${TARGET_ACTUAL_ARCH}" STREQUAL "arm" OR "${TARGET_ACTUAL_ARCH}" STREQUAL "arm64") + file (GLOB ARM_COMMON_SRC "arch/arm_common/*.c") + set (ARM_COMMON_INCL "arch/arm_common") +endif() + +include_directories ( + tcg + softfloat-2 + include + tcg/${HOST_ARCH} + arch/${TARGET_ACTUAL_ARCH} + ${ARM_COMMON_INCL} + ) + +file (GLOB SOURCES + "*.c" + "softfloat-2/*.c" + "arch/*.c" + "external/*.c" + "arch/${TARGET_ACTUAL_ARCH}/*.c" + ${ARM_COMMON_SRC} + ) + +add_library (tlib SHARED ${SOURCES}) +add_dependencies (tlib tcg) + +if("${TARGET_ACTUAL_ARCH}" STREQUAL "i386") + set (MATH_LIB_LINK_ARG "-lm" CACHE STRING + "Argument pointing linker to a math functions library. It's required to translate i386 code.") +endif() + +# On windows, make sure the winpthread gets linked statically +if(${CMAKE_HOST_SYSTEM_NAME} MATCHES "(Windows|CYGWIN)") + set(PTREAD_OPT -static winpthread -dynamic) +else() + set(PTREAD_OPT pthread) +endif() + +# On x86_64 Linux, the memcpy function was modified in GNU libc v2.14. +# It'd be impossible to run tlib without this wrapping with older libc. +if(${CMAKE_HOST_SYSTEM_NAME} STREQUAL Linux AND ${HOST_ARCH} STREQUAL i386 AND ${HOST_WORD_SIZE} EQUAL 64) + set(WRAP_MEMCPY_OPT -Wl,--wrap=memcpy) +endif() + +# -z flag does not work on Windows +if ((NOT (${CMAKE_HOST_SYSTEM_NAME} MATCHES "(Windows|CYGWIN)" )) AND ("${C_COMPILER_ID}" STREQUAL "GNU")) + set (Z_OPTS -zdefs) +endif() + +target_link_libraries (tlib + ${WRAP_MEMCPY_OPT} + -fPIC + ${Z_OPTS} + + ${MATH_LIB_LINK_ARG} + ${PTREAD_OPT} + ${SOFTFLOAT3} + tcg + ) diff --git a/recipes/renode-cores/patches/update-for-cmake-build.sh.patch b/recipes/renode-cores/patches/update-for-cmake-build.sh.patch new file mode 100644 index 0000000000000..a9f480f68bc3d --- /dev/null +++ b/recipes/renode-cores/patches/update-for-cmake-build.sh.patch @@ -0,0 +1,367 @@ +--- /home/memento/PycharmProjects/staged-recipes-2/build_artifacts/src_cache/v1_15_3_692604eb/build.sh 2024-09-17 03:09:19.000000000 -0500 ++++ build.new.sh 2025-01-24 15:30:24.984659038 -0600 +@@ -18,4 +18,8 @@ + SKIP_FETCH=false ++TLIB_ONLY=false ++TLIB_EXPORT_COMPILE_COMMANDS=false ++TLIB_ARCH="" + NET=false +-TFM="net6.0" ++TFM="net8.0" ++GENERATE_DOTNET_BUILD_TARGET=true + PARAMS=() +@@ -24,5 +28,8 @@ + RID="linux-x64" ++HOST_ARCH="i386" ++# Common cmake flags ++CMAKE_COMMON="" + + function print_help() { +- echo "Usage: $0 [-cdvspnt] [-b properties-file.csproj] [--no-gui] [--skip-fetch] [--profile-build] [-- ]" ++ echo "Usage: $0 [-cdvspnt] [-b properties-file.csproj] [--no-gui] [--skip-fetch] [--profile-build] [--tlib-only] [--tlib-export-compile-commands] [--tlib-arch ] [--host-arch i386|aarch64] [-- ]" + echo +@@ -42,3 +49,9 @@ + echo "-B bundle target runtime (default value: $RID, requires --net, -t)" +- echo "--profile-build build optimized for tlib profiling" ++ echo "-F select the target framework for which Renode should be built (default value: $TFM)" ++ echo "--profile-build build optimized for profiling" ++ echo "--tlib-only only build tlib" ++ echo "--tlib-arch build only single arch (implies --tlib-only)" ++ echo "--tlib-export-compile-commands build tlibs with 'compile_commands.json' (requires --tlib-arch)" ++ echo "--host-arch build with a specific tcg host architecture (default: i386)" ++ echo "--skip-dotnet-target-generation don't generate 'Directory.Build.targets' file, useful when experimenting with different build settings" + echo " arguments to pass to the build system" +@@ -46,3 +59,3 @@ + +-while getopts "cdvpnstb:o:B:-:" opt ++while getopts "cdvpnstb:o:B:F:a:-:" opt + do +@@ -81,2 +94,9 @@ + ;; ++ F) ++ if ! $NET; then ++ echo "-F requires --net being set" ++ exit 1 ++ fi ++ TFM=$OPTARG ++ ;; + -) +@@ -100,3 +120,28 @@ + "profile-build") +- PARAMS+=('p:TlibProfilingBuild=true') ++ CMAKE_COMMON="-DPROFILING_BUILD=ON" ++ ;; ++ "tlib-only") ++ TLIB_ONLY=true ++ ;; ++ "tlib-arch") ++ # This only makes sense with '--tlib-only' set; it might as well imply it ++ TLIB_ONLY=true ++ shift $((OPTIND-1)) ++ TLIB_ARCH=$1 ++ OPTIND=2 ++ ;; ++ "tlib-export-compile-commands") ++ if [ -z $TLIB_ARCH ]; then ++ echo "--tlib-export-compile-commands requires --tlib-arch begin set" ++ exit 1 ++ fi ++ TLIB_EXPORT_COMPILE_COMMANDS=true ++ ;; ++ "host-arch") ++ shift $((OPTIND-1)) ++ HOST_ARCH=$1 ++ OPTIND=2 ++ ;; ++ "skip-dotnet-target-generation") ++ GENERATE_DOTNET_BUILD_TARGET=false + ;; +@@ -184,3 +229,4 @@ + BUILD_TARGET=Windows +- TFM="net6.0-windows10.0.17763.0" ++ TFM="$TFM-windows10.0.17763.0" ++ RID="win-x64" + else +@@ -189,10 +235,34 @@ + ++if [[ $GENERATE_DOTNET_BUILD_TARGET = true ]]; then ++ if $ON_WINDOWS; then ++ # CsWinRTAotOptimizerEnabled is disabled due to a bug in dotnet-sdk. ++ # See: https://github.com/dotnet/sdk/issues/44026 ++ OS_SPECIFIC_TARGET_OPTS='false' ++ fi ++ ++cat < "$(get_path "$PWD/Directory.Build.targets")" ++ ++ ++ $TFM ++ ${OS_SPECIFIC_TARGET_OPTS:+${OS_SPECIFIC_TARGET_OPTS}} ++ ++ ++EOF ++ ++fi ++ + if $NET + then ++ export DOTNET_CLI_TELEMETRY_OPTOUT=1 + CS_COMPILER="dotnet build" + TARGET="`get_path \"$PWD/Renode_NET.sln\"`" ++ BUILD_TYPE="dotnet" + else + TARGET="`get_path \"$PWD/Renode.sln\"`" ++ BUILD_TYPE="mono" + fi + ++OUT_BIN_DIR="$(get_path "output/bin/${CONFIGURATION}")" ++BUILD_TYPE_FILE=$(get_path "${OUT_BIN_DIR}/build_type") ++ + # Verify Mono and mcs version on Linux and macOS +@@ -203,3 +273,3 @@ + MINIMUM_MONO=`get_min_mono_version` +- echo "mcs not found. Renode requries Mono $MINIMUM_MONO or newer. Please refer to documentation for installation instructions. Exiting!" ++ echo "mcs not found. Renode requires Mono $MINIMUM_MONO or newer. Please refer to documentation for installation instructions. Exiting!" + exit 1 +@@ -237,20 +307,3 @@ + +-# Build CCTask in Release configuration +-CCTASK_OUTPUT=`mktemp` +-CCTASK_BUILD_ARGS=($NET_FRAMEWORK_VER p:Configuration=Release p:Platform="\"$BUILD_PLATFORM\"") +-set +e +-CCTASK_SLN=CCTask.sln +-if $NET +-then +- CCTASK_SLN=CCTask_NET.sln +-fi +-eval "$CS_COMPILER $(build_args_helper "${CCTASK_BUILD_ARGS[@]}") $(get_path $ROOT_PATH/lib/cctask/$CCTASK_SLN)" 2>&1 > $CCTASK_OUTPUT +- +-if [ $? -ne 0 ]; then +- cat $CCTASK_OUTPUT +- rm $CCTASK_OUTPUT +- exit 1 +-fi +-rm $CCTASK_OUTPUT +-set -e ++CORES_PATH="$ROOT_PATH/src/Infrastructure/src/Emulator/Cores" + +@@ -259,19 +312,22 @@ + then +- if ! $NET +- then +- PARAMS+=(t:Clean) +- fi +- for conf in Debug Release ++ for project_dir in $(find "$(get_path "${ROOT_PATH}/src")" -iname '*.csproj' -exec dirname '{}' \;) + do +- for build_target in Windows Mono Headless ++ for dir in {bin,obj}/{Debug,Release} + do +- if $NET ++ output_dir="$(get_path "${project_dir}/${dir}")" ++ if [[ -d "${output_dir}" ]] + then +- dotnet clean $(build_args_helper ${PARAMS[@]}) $(build_args_helper p:Configuration=${conf}${build_target}) "$TARGET" +- else +- $CS_COMPILER $(build_args_helper ${PARAMS[@]}) $(build_args_helper p:Configuration=${conf}${build_target}) "$TARGET" ++ echo "Removing: ${output_dir}" ++ rm -rf "${output_dir}" + fi + done +- rm -fr $OUTPUT_DIRECTORY/bin/$conf + done ++ ++ # Manually clean the main output directory as it's location is non-standard ++ main_output_dir="$(get_path "${OUTPUT_DIRECTORY}/bin")" ++ if [[ -d "${main_output_dir}" ]] ++ then ++ echo "Removing: ${main_output_dir}" ++ rm -rf "${main_output_dir}" ++ fi + exit 0 +@@ -279,2 +335,13 @@ + ++# Check if a full rebuild is needed ++if [[ -f "$BUILD_TYPE_FILE" ]] ++then ++ if [[ "$(cat "$BUILD_TYPE_FILE")" != "$BUILD_TYPE" ]] ++ then ++ echo "Attempted to build Renode in a different configuration than the previous build" ++ echo "Please run '$0 -c' to clean the previous build before continuing" ++ exit 1 ++ fi ++fi ++ + # check weak implementations of core libraries +@@ -286,12 +353,105 @@ + ++# Paths for tlib ++CORES_BUILD_PATH="$CORES_PATH/obj/$CONFIGURATION" ++CORES_BIN_PATH="$CORES_PATH/bin/$CONFIGURATION" ++ ++# Cmake generator, handled in their own variable since the names contain spaces ++if $ON_WINDOWS ++then ++ CMAKE_GEN="-GMinGW Makefiles" ++else ++ CMAKE_GEN="-GUnix Makefiles" ++fi ++ ++# Macos architecture flags, to make rosetta work properly ++if $ON_OSX ++then ++ CMAKE_COMMON+=" -DCMAKE_OSX_ARCHITECTURES=x86_64" ++ if [ $HOST_ARCH == "aarch64" ]; then ++ CMAKE_COMMON+=" -DCMAKE_OSX_ARCHITECTURES=arm64" ++ fi ++fi ++ ++# This list contains all cores that will be built. ++# If you are adding a new core or endianness add it here to have the correct tlib built ++CORES=(arm.le arm.be arm64.le arm-m.le arm-m.be ppc.le ppc.be ppc64.le ppc64.be i386.le x86_64.le riscv.le riscv64.le sparc.le sparc.be xtensa.le) ++ ++# if '--tlib-arch' was used - pick the first matching one ++if [[ ! -z $TLIB_ARCH ]]; then ++ NONE_MATCHED=true ++ for potential_match in "${CORES[@]}"; do ++ if [[ $potential_match == "$TLIB_ARCH"* ]]; then ++ CORES=($potential_match) ++ echo "Compiling tlib for $potential_match" ++ NONE_MATCHED=false ++ break ++ fi ++ done ++ if $NONE_MATCHED ; then ++ echo "Failed to match any tlib arch" ++ exit 1 ++ fi ++fi ++ ++# build tlib ++for core_config in "${CORES[@]}" ++do ++ CORE="$(echo $core_config | cut -d '.' -f 1)" ++ ENDIAN="$(echo $core_config | cut -d '.' -f 2)" ++ BITS=32 ++ # Check if core is 64-bit ++ if [[ $CORE =~ "64" ]]; then ++ BITS=64 ++ fi ++ # Core specific flags to cmake ++ CMAKE_CONF_FLAGS="-DTARGET_ARCH=$CORE -DTARGET_WORD_SIZE=$BITS -DCMAKE_BUILD_TYPE=$CONFIGURATION" ++ CORE_DIR=$CORES_BUILD_PATH/$CORE/$ENDIAN ++ mkdir -p $CORE_DIR ++ pushd "$CORE_DIR" > /dev/null ++ if [[ $ENDIAN == "be" ]]; then ++ CMAKE_CONF_FLAGS+=" -DTARGET_BIG_ENDIAN=1" ++ fi ++ if [[ "$TLIB_EXPORT_COMPILE_COMMANDS" = true ]]; then ++ CMAKE_CONF_FLAGS+=" -DCMAKE_EXPORT_COMPILE_COMMANDS=1" ++ fi ++ cmake "$CMAKE_GEN" $CMAKE_COMMON $CMAKE_CONF_FLAGS -DHOST_ARCH=$HOST_ARCH $CORES_PATH ++ cmake --build . ++ CORE_BIN_DIR=$CORES_BIN_PATH/lib ++ mkdir -p $CORE_BIN_DIR ++ if $ON_OSX; then ++ # macos `cp` does not have the -u flag ++ cp -v tlib/*.so $CORE_BIN_DIR/ ++ else ++ cp -u -v tlib/*.so $CORE_BIN_DIR/ ++ fi ++ # copy compile_commands.json to tlib directory ++ if [[ "$TLIB_EXPORT_COMPILE_COMMANDS" = true ]]; then ++ command cp -v -f $CORE_DIR/compile_commands.json $CORES_PATH/tlib/ ++ fi ++ popd > /dev/null ++done ++ ++if $TLIB_ONLY ++then ++ exit 0 ++fi ++ + # build + eval "$CS_COMPILER $(build_args_helper "${PARAMS[@]}") $TARGET" ++echo -n "$BUILD_TYPE" > "$BUILD_TYPE_FILE" + + # copy llvm library +-if $NET +-then +- cp src/Infrastructure/src/Emulator/Peripherals/bin/$CONFIGURATION/$TFM/libllvm-disas.* output/bin/$CONFIGURATION/$TFM ++LLVM_LIB="libllvm-disas" ++if [[ $HOST_ARCH == "aarch64" ]]; then ++ # aarch64 host binaries have a different name ++ LLVM_LIB="libllvm-disas-aarch64" ++fi ++if [[ "${DETECTED_OS}" == "windows" ]]; then ++ LIB_EXT="dll" ++elif [[ "${DETECTED_OS}" == "osx" ]]; then ++ LIB_EXT="dylib" + else +- cp src/Infrastructure/src/Emulator/Peripherals/bin/$CONFIGURATION/libllvm-disas.* output/bin/$CONFIGURATION ++ LIB_EXT="so" + fi ++cp lib/resources/llvm/$LLVM_LIB.$LIB_EXT $OUT_BIN_DIR/libllvm-disas.$LIB_EXT + +@@ -326,11 +486,24 @@ + then +- # Restore dependecies for linux-x64 runtime. It prevents error NETSDK1112 during publish. +- dotnet restore --runtime linux-x64 Renode_NET.sln +- +- eval "dotnet publish -f $TFM --self-contained false $(build_args_helper "${PARAMS[@]}") $TARGET" +- export RID TFM +- $ROOT_PATH/tools/packaging/make_linux_dotnet_package.sh $params ++ # dotnet package on linux uses a separate script ++ if $ON_LINUX ++ then ++ # maxcpucount:1 to avoid an error with multithreaded publish ++ eval "dotnet publish -maxcpucount:1 -f $TFM --self-contained false $(build_args_helper "${PARAMS[@]}") $TARGET" ++ export RID TFM ++ $ROOT_PATH/tools/packaging/make_linux_dotnet_package.sh $params ++ # Source package bundles nuget dependencies required for building the dotnet version of Renode ++ # so it can only be built when using dotnet. The generated package can also be used with Mono/.NETFramework ++ $ROOT_PATH/tools/packaging/make_source_package.sh $params ++ elif $ON_WINDOWS && ! $PORTABLE ++ then ++ # No Non portable dotnet package on windows yet ++ echo "Only portable dotnet packages are supported on windows. Rerun build.sh with -t flag to build portable" ++ exit 1 ++ elif $ON_OSX ++ then ++ echo "dotnet packages not supported on ${DETECTED_OS}" ++ exit 1 ++ fi + else + $ROOT_PATH/tools/packaging/make_${DETECTED_OS}_packages.sh $params +- $ROOT_PATH/tools/packaging/make_source_package.sh $params + fi +@@ -341,16 +514,17 @@ + PARAMS+=(p:PORTABLE=true) +- if $ON_LINUX ++ if $NET + then +- if $NET +- then +- eval "dotnet publish -r $RID -f $TFM --self-contained true $(build_args_helper "${PARAMS[@]}") $TARGET" +- export RID TFM +- $ROOT_PATH/tools/packaging/make_linux_portable_dotnet.sh $params +- else +- $ROOT_PATH/tools/packaging/make_linux_portable.sh $params +- fi ++ # maxcpucount:1 to avoid an error with multithreaded publish ++ eval "dotnet publish -maxcpucount:1 -r $RID -f $TFM --self-contained true $(build_args_helper "${PARAMS[@]}") $TARGET" ++ export RID TFM ++ $ROOT_PATH/tools/packaging/make_${DETECTED_OS}_portable_dotnet.sh $params + else +- echo "Portable packages are only available on Linux. Exiting!" +- exit 1 ++ if $ON_LINUX ++ then ++ $ROOT_PATH/tools/packaging/make_linux_portable.sh $params ++ else ++ echo "Portable packages for Mono are only available on Linux. Exiting!" ++ exit 1 ++ fi + fi +-fi ++fi +\ No newline at end of file diff --git a/recipes/renode-cores/recipe.yaml b/recipes/renode-cores/recipe.yaml new file mode 100644 index 0000000000000..a87b81cd6cf91 --- /dev/null +++ b/recipes/renode-cores/recipe.yaml @@ -0,0 +1,73 @@ +context: + name: renode-cores + version: "1.15.3" + python_min: "3.6" + +package: + name: ${{ name|lower }} + version: ${{ version }} + +source: + - url: https://github.com/renode/renode/releases/download/v${{ version }}/renode_${{ version }}_source.tar.xz + sha256: 40c50afe8db86a9c63f4a86b93116a6babd43bf241cfaac47b2c0d2cbc2b15a8 + #- url: https://github.com/renode/renode/archive/refs/tags/v${{ version }}.tar.gz + # sha256: 692604eba16476596ddbc91a4cba1bd5da681dbda076d1980b81f1d333edb7c0 + patches: + - if: unix + then: + - patches/update-for-cmake-build.sh.patch + +build: + number: 0 + +requirements: + build: + - ${{ compiler('c') }} + - ${{ compiler('cxx') }} + - ${{ stdlib('c') }} + - cmake + - make + - sed + +tests: + - package_contents: + files: + - ${{ "LIBRARY/" if not unix }}lib/renode-cores/translate-xtensa-le.so + - ${{ "LIBRARY/" if not unix }}lib/renode-cores/translate-arm-be.so + - ${{ "LIBRARY/" if not unix }}lib/renode-cores/translate-arm-le.so + - ${{ "LIBRARY/" if not unix }}lib/renode-cores/translate-arm-m-be.so + - ${{ "LIBRARY/" if not unix }}lib/renode-cores/translate-arm-m-le.so + - ${{ "LIBRARY/" if not unix }}lib/renode-cores/translate-arm64-le.so + - ${{ "LIBRARY/" if not unix }}lib/renode-cores/translate-i386-le.so + - ${{ "LIBRARY/" if not unix }}lib/renode-cores/translate-ppc-be.so + - ${{ "LIBRARY/" if not unix }}lib/renode-cores/translate-ppc-le.so + - ${{ "LIBRARY/" if not unix }}lib/renode-cores/translate-ppc64-be.so + - ${{ "LIBRARY/" if not unix }}lib/renode-cores/translate-ppc64-le.so + - ${{ "LIBRARY/" if not unix }}lib/renode-cores/translate-riscv-le.so + - ${{ "LIBRARY/" if not unix }}lib/renode-cores/translate-riscv64-le.so + - ${{ "LIBRARY/" if not unix }}lib/renode-cores/translate-sparc-be.so + - ${{ "LIBRARY/" if not unix }}lib/renode-cores/translate-sparc-le.so + - ${{ "LIBRARY/" if not unix }}lib/renode-cores/translate-x86_64-le.so + - ${{ "LIBRARY/" if not unix }}lib/renode-cores/translate-xtensa-le.so + +about: + homepage: https://github.com/renode/renode + summary: "Antmicro's open source simulation and virtual development framework for complex embedded systems" + description: | + Renode was created by Antmicro as a virtual development tool for multi-node + embedded networks (both wired and wireless) and is intended to enable a scalable + workflow for creating effective, tested and secure IoT systems. + + With Renode, developing, testing, debugging and simulating unmodified software + for IoT devices is fast, cost-effective and reliable. + license: MIT + license_file: + - LICENSE + - licensefiles/ + documentation: https://renode.io/ + repository: https://github.com/renode/renode + +extra: + recipe-maintainers: + - MementoRC + - danielnachun diff --git a/recipes/renode-cores/scripts/activate.bat b/recipes/renode-cores/scripts/activate.bat new file mode 100755 index 0000000000000..7fd79e749862a --- /dev/null +++ b/recipes/renode-cores/scripts/activate.bat @@ -0,0 +1,2 @@ +@echo off +set PATH=%PATH%;%CONDA_PREFIX%\Library\renode\exec \ No newline at end of file diff --git a/recipes/renode-cores/variants.yaml b/recipes/renode-cores/variants.yaml new file mode 100644 index 0000000000000..3fdfa2f172c02 --- /dev/null +++ b/recipes/renode-cores/variants.yaml @@ -0,0 +1,7 @@ +c_stdlib: + - if: linux + then: sysroot + - if: osx + then: macosx_deployment_target + - if: not unix + then: vs From bded9e687d52df52c2422f85ee79e7cc3f239a47 Mon Sep 17 00:00:00 2001 From: memento Date: Tue, 28 Jan 2025 09:26:30 -0600 Subject: [PATCH 05/26] (fix) update renode-cores for non-unix --- recipes/renode-cores/build.bat | 62 ++++++++++---------------------- recipes/renode-cores/build.sh | 21 ++++++----- recipes/renode-cores/recipe.yaml | 6 +++- 3 files changed, 33 insertions(+), 56 deletions(-) diff --git a/recipes/renode-cores/build.bat b/recipes/renode-cores/build.bat index 1a11cbfbb7e31..a923156f996fe 100644 --- a/recipes/renode-cores/build.bat +++ b/recipes/renode-cores/build.bat @@ -1,44 +1,18 @@ -setlocal EnableDelayedExpansion -set PATH=C:\cygwin64\bin\;%PATH% -set PLATFORM=Any CPU -for /r %%i in (*.sh) do CALL :convert_to_unix_newline %%i - -call bash -lc build.sh -if %errorlevel% neq 0 exit /b %errorlevel% - -REM Need to use call for all functions outside of script, otherwise label handling go crazy -call mkdir %LIBRARY_PREFIX%\renode\exec -call mkdir %LIBRARY_PREFIX%\renode\tests -call mkdir %LIBRARY_PREFIX%\renode\scripts -call mkdir %LIBRARY_PREFIX%\renode\platforms -call mkdir %LIBRARY_PREFIX%\renode\licenses -call robocopy output\bin\Release\ %LIBRARY_PREFIX%\renode\exec\ /njh /njs /ndl /S -call robocopy tests\ %LIBRARY_PREFIX%\renode\tests /njh /njs /ndl /S -call robocopy scripts\ %LIBRARY_PREFIX%\renode\scripts /njh /njs /ndl /S -call robocopy platforms\ %LIBRARY_PREFIX%\renode\platforms /njh /njs /ndl /S -call robocopy .\ %LIBRARY_PREFIX%\renode\ .renode-root -call robocopy .\ %LIBRARY_PREFIX%\renode\ LICENSE - -REM Copy all licenses. LIBRARY_PREFIX has to be converted to the Unix format first. -FOR /F "delims=" %%i IN ('cygpath.exe -u "%LIBRARY_PREFIX%"') DO set "UNIX_LIBRARY_PREFIX=%%i" -call bash -lc "tools/packaging/common_copy_licenses.sh $UNIX_LIBRARY_PREFIX/renode/licenses windows" -if %errorlevel% neq 0 exit /b %errorlevel% - - -REM Add activation script to append renode dir to PATH -if not exist %PREFIX%\etc\conda\activate.d call mkdir %PREFIX%\etc\conda\activate.d -call copy %RECIPE_DIR%\activate.bat %PREFIX%\etc\conda\activate.d\%PKG_NAME%_activate.bat -call copy %RECIPE_DIR%\activate-win.sh %PREFIX%\etc\conda\activate.d\%PKG_NAME%_activate.sh - -if not exist %PREFIX%\etc\conda\deactivate.d call mkdir %PREFIX%\etc\conda\deactivate.d -call copy %RECIPE_DIR%\deactivate-win.sh %PREFIX%\etc\conda\deactivate.d\%PKG_NAME%_deactivate.sh - -REM PS1 scripts can't modify PATH so put a PowerShell script running Renode in PATH. -if not exist %PREFIX%\Library\bin call mkdir %PREFIX%\Library\bin -call copy %RECIPE_DIR%\Renode.ps1 %PREFIX%\Library\bin\Renode.ps1 - -EXIT /B 0 - -:convert_to_unix_newline -powershell -Command "(Get-Content %~1 -Raw).Replace(\"`r\",\"\") |Set-Content -NoNewLine %~1 -Force" -EXIT /B 0 +echo source ${SYS_PREFIX:-${MINIFORGE_HOME}}/etc/profile.d/conda.sh > conda_build.sh +echo conda activate "${PREFIX}" >> conda_build.sh +echo conda activate --stack "${BUILD_PREFIX}" >> conda_build.sh +echo CONDA_PREFIX=${CONDA_PREFIX//\\//} >> conda_build.sh +type "%RECIPE_DIR%\build.sh" >> conda_build.sh + +set "PREFIX=%PREFIX:\=/%" +set "BUILD_PREFIX=%BUILD_PREFIX:\=/%" +set "CONDA_PREFIX=%CONDA_PREFIX:\=/%" +set "SRC_DIR=%SRC_DIR:\=/%" +set "RECIPE_DIR=%RECIPE_DIR:\=/%" +:: set PYTHON=%PYTHON:\=/% +set MSYSTEM=UCRT64 +set MSYS2_PATH_TYPE=inherit +set CHERE_INVOKING=1 +set build_platform=win-64 +set target_platform=win-64 +bash -lc "./conda_build.sh" diff --git a/recipes/renode-cores/build.sh b/recipes/renode-cores/build.sh index d5c2b63a6c1a9..c8ad93081e4ba 100644 --- a/recipes/renode-cores/build.sh +++ b/recipes/renode-cores/build.sh @@ -6,20 +6,19 @@ set -o xtrace -o nounset -o pipefail -o errexit cp ${RECIPE_DIR}/patches/Cores-CMakeLists.txt ${SRC_DIR}/src/Infrastructure/src/Emulator/Cores/CMakeLists.txt cp ${RECIPE_DIR}/patches/tlib-CMakeLists.txt ${SRC_DIR}/src/Infrastructure/src/Emulator/Cores/tlib/CMakeLists.txt -if [[ "${target_platform}" == linux-* ]] || [[ "${target_platform}" == osx-* ]]; then - _os_name=${target_platform%-*} - chmod +x build.sh tools/building/check_weak_implementations.sh - ./build.sh --tlib-only --net --no-gui -else - _os_name=windows - chmod +x build.sh tools/building/check_weak_implementations.sh - ./build.sh --tlib-only --net --no-gui -fi +chmod +x build.sh tools/building/check_weak_implementations.sh +./build.sh --tlib-only --net --no-gui # Install procedure into a conda path that renode-cli can retrieve ROOT_PATH="$(cd $(dirname $0); echo $PWD)" CONFIGURATION="Release" CORES_PATH="$ROOT_PATH/src/Infrastructure/src/Emulator/Cores" CORES_BIN_PATH="$CORES_PATH/bin/$CONFIGURATION" -mkdir -p "${PREFIX}/lib/${PKG_NAME}" -tar -c -C "${CORES_BIN_PATH}/lib" . | tar -x -C "${PREFIX}/lib/${PKG_NAME}" + +if [[ "${target_platform}" == linux-* ]] || [[ "${target_platform}" == osx-* ]]; then + mkdir -p "${PREFIX}/lib/${PKG_NAME}" + tar -c -C "${CORES_BIN_PATH}/lib" . | tar -x -C "${PREFIX}/lib/${PKG_NAME}" +else + mkdir -p "${PREFIX}/Library/lib/${PKG_NAME}" + tar -c -C "${CORES_BIN_PATH}/lib" . | tar -x -C "${PREFIX}/Library/lib/${PKG_NAME}" +fi diff --git a/recipes/renode-cores/recipe.yaml b/recipes/renode-cores/recipe.yaml index a87b81cd6cf91..02207d6efd50b 100644 --- a/recipes/renode-cores/recipe.yaml +++ b/recipes/renode-cores/recipe.yaml @@ -27,7 +27,11 @@ requirements: - ${{ stdlib('c') }} - cmake - make - - sed + - if: unix + then: + - sed + else: + - m2-sed tests: - package_contents: From ab99f31f045f584b62fad7cef197d7ffb58ec2ec Mon Sep 17 00:00:00 2001 From: memento Date: Tue, 28 Jan 2025 09:34:27 -0600 Subject: [PATCH 06/26] (fix) update renode-cores for non-unix --- recipes/renode-cores/build.bat | 2 -- 1 file changed, 2 deletions(-) diff --git a/recipes/renode-cores/build.bat b/recipes/renode-cores/build.bat index a923156f996fe..e63ca5dd84cc5 100644 --- a/recipes/renode-cores/build.bat +++ b/recipes/renode-cores/build.bat @@ -13,6 +13,4 @@ set "RECIPE_DIR=%RECIPE_DIR:\=/%" set MSYSTEM=UCRT64 set MSYS2_PATH_TYPE=inherit set CHERE_INVOKING=1 -set build_platform=win-64 -set target_platform=win-64 bash -lc "./conda_build.sh" From c8a4e1b39277e7fb6971f80146bc26c4fe53b374 Mon Sep 17 00:00:00 2001 From: memento Date: Tue, 28 Jan 2025 09:59:21 -0600 Subject: [PATCH 07/26] (fix) use .bat for non-unix --- recipes/renode-cores/build.bat | 38 ++++++++++++++++++++------------ recipes/renode-cores/recipe.yaml | 1 + 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/recipes/renode-cores/build.bat b/recipes/renode-cores/build.bat index e63ca5dd84cc5..c56029fb6c600 100644 --- a/recipes/renode-cores/build.bat +++ b/recipes/renode-cores/build.bat @@ -1,16 +1,26 @@ -echo source ${SYS_PREFIX:-${MINIFORGE_HOME}}/etc/profile.d/conda.sh > conda_build.sh -echo conda activate "${PREFIX}" >> conda_build.sh -echo conda activate --stack "${BUILD_PREFIX}" >> conda_build.sh -echo CONDA_PREFIX=${CONDA_PREFIX//\\//} >> conda_build.sh -type "%RECIPE_DIR%\build.sh" >> conda_build.sh +@echo off -set "PREFIX=%PREFIX:\=/%" -set "BUILD_PREFIX=%BUILD_PREFIX:\=/%" -set "CONDA_PREFIX=%CONDA_PREFIX:\=/%" -set "SRC_DIR=%SRC_DIR:\=/%" -set "RECIPE_DIR=%RECIPE_DIR:\=/%" -:: set PYTHON=%PYTHON:\=/% -set MSYSTEM=UCRT64 -set MSYS2_PATH_TYPE=inherit -set CHERE_INVOKING=1 +setlocal EnableDelayedExpansion + +rem Update the submodule to the latest commit CMakeLists.txt +copy "%RECIPE_DIR%\patches\Cores-CMakeLists.txt" "%SRC_DIR%\src\Infrastructure\src\Emulator\Cores\CMakeLists.txt" +copy "%RECIPE_DIR%\patches\tlib-CMakeLists.txt" "%SRC_DIR%\src\Infrastructure\src\Emulator\Cores\tlib\CMakeLists.txt" + +rem Set execute permissions (not strictly necessary on Windows) +rem but keeping it for consistency with the bash script +attrib +x build.sh tools\building\check_weak_implementations.sh + +rem Build the translation libraries +call bash -lc 'build.sh --tlib-only --net --no-gui' + +rem Install procedure into a conda path that renode-cli can retrieve +set "ROOT_PATH=%~dp0.." +set "CONFIGURATION=Release" +set "CORES_PATH=%ROOT_PATH%src\Infrastructure\src\Emulator\Cores" +set "CORES_BIN_PATH=%CORES_PATH%\bin\%CONFIGURATION%" + +mkdir "%PREFIX%\Library\lib\%PKG_NAME%" +tar -c -C "%CORES_BIN_PATH%\lib" . | tar -x -C "%PREFIX%\Library\lib\%PKG_NAME%" + +endlocal bash -lc "./conda_build.sh" diff --git a/recipes/renode-cores/recipe.yaml b/recipes/renode-cores/recipe.yaml index 02207d6efd50b..ba68341529191 100644 --- a/recipes/renode-cores/recipe.yaml +++ b/recipes/renode-cores/recipe.yaml @@ -27,6 +27,7 @@ requirements: - ${{ stdlib('c') }} - cmake - make + - tar - if: unix then: - sed From 37d1d27e4feafeba70f8c1bfdecffad60a9c8c4d Mon Sep 17 00:00:00 2001 From: MementoRC Date: Tue, 28 Jan 2025 13:53:17 -0800 Subject: [PATCH 08/26] (wip) damn working with win is like pulling teeth --- recipes/renode-cores/build.bat | 17 +- recipes/renode-cores/build.sh | 9 +- .../helpers/renode_build_with_cmake.sh | 204 ++++++++++++++++++ recipes/renode-cores/recipe.yaml | 23 +- recipes/renode-cores/variants.yaml | 9 +- 5 files changed, 237 insertions(+), 25 deletions(-) create mode 100644 recipes/renode-cores/helpers/renode_build_with_cmake.sh diff --git a/recipes/renode-cores/build.bat b/recipes/renode-cores/build.bat index c56029fb6c600..66222e95b7857 100644 --- a/recipes/renode-cores/build.bat +++ b/recipes/renode-cores/build.bat @@ -5,13 +5,19 @@ setlocal EnableDelayedExpansion rem Update the submodule to the latest commit CMakeLists.txt copy "%RECIPE_DIR%\patches\Cores-CMakeLists.txt" "%SRC_DIR%\src\Infrastructure\src\Emulator\Cores\CMakeLists.txt" copy "%RECIPE_DIR%\patches\tlib-CMakeLists.txt" "%SRC_DIR%\src\Infrastructure\src\Emulator\Cores\tlib\CMakeLists.txt" +if %errorlevel% neq 0 exit /b %errorlevel% -rem Set execute permissions (not strictly necessary on Windows) -rem but keeping it for consistency with the bash script -attrib +x build.sh tools\building\check_weak_implementations.sh +set "PREFIX=%PREFIX:\=/%" +set "BUILD_PREFIX=%BUILD_PREFIX:\=/%" +set "CONDA_PREFIX=%CONDA_PREFIX:\=/%" +set "SRC_DIR=%SRC_DIR:\=/%" +set "RECIPE_DIR=%RECIPE_DIR:\=/%" +set MSYSTEM=UCRT64 +set MSYS2_PATH_TYPE=inherit +set CHERE_INVOKING=1 -rem Build the translation libraries -call bash -lc 'build.sh --tlib-only --net --no-gui' +call bash -lc "${RECIPE_DIR}/helpers/renode_build_with_cmake.sh --tlib-only --net --no-gui" +if %errorlevel% neq 0 exit /b %errorlevel% rem Install procedure into a conda path that renode-cli can retrieve set "ROOT_PATH=%~dp0.." @@ -23,4 +29,3 @@ mkdir "%PREFIX%\Library\lib\%PKG_NAME%" tar -c -C "%CORES_BIN_PATH%\lib" . | tar -x -C "%PREFIX%\Library\lib\%PKG_NAME%" endlocal -bash -lc "./conda_build.sh" diff --git a/recipes/renode-cores/build.sh b/recipes/renode-cores/build.sh index c8ad93081e4ba..fd8cba6306769 100644 --- a/recipes/renode-cores/build.sh +++ b/recipes/renode-cores/build.sh @@ -15,10 +15,5 @@ CONFIGURATION="Release" CORES_PATH="$ROOT_PATH/src/Infrastructure/src/Emulator/Cores" CORES_BIN_PATH="$CORES_PATH/bin/$CONFIGURATION" -if [[ "${target_platform}" == linux-* ]] || [[ "${target_platform}" == osx-* ]]; then - mkdir -p "${PREFIX}/lib/${PKG_NAME}" - tar -c -C "${CORES_BIN_PATH}/lib" . | tar -x -C "${PREFIX}/lib/${PKG_NAME}" -else - mkdir -p "${PREFIX}/Library/lib/${PKG_NAME}" - tar -c -C "${CORES_BIN_PATH}/lib" . | tar -x -C "${PREFIX}/Library/lib/${PKG_NAME}" -fi +mkdir -p "${PREFIX}/lib/${PKG_NAME}" +tar -c -C "${CORES_BIN_PATH}/lib" . | tar -x -C "${PREFIX}/lib/${PKG_NAME}" diff --git a/recipes/renode-cores/helpers/renode_build_with_cmake.sh b/recipes/renode-cores/helpers/renode_build_with_cmake.sh new file mode 100644 index 0000000000000..60cf163c3d47a --- /dev/null +++ b/recipes/renode-cores/helpers/renode_build_with_cmake.sh @@ -0,0 +1,204 @@ +#!/usr/bin/env bash + +set -u +set -e + +export PATH="${BUILD_PREFIX}/Library/mingw-w64/bin:${BUILD_PREFIX}/Library/bin:${PREFIX}/Library/bin:${PREFIX}/bin:${PATH}" +export ROOT_PATH="$SRC_DIR" + +CMAKE=$(which cmake) + +OUTPUT_DIRECTORY="$ROOT_PATH/output" +EXPORT_DIRECTORY="" + +UPDATE_SUBMODULES=false +CONFIGURATION="Release" +BUILD_PLATFORM="Any CPU" +CLEAN=false +PACKAGES=false +NIGHTLY=false +PORTABLE=false +HEADLESS=false +SKIP_FETCH=false +TLIB_ONLY=false +TLIB_EXPORT_COMPILE_COMMANDS=false +TLIB_ARCH="" +NET=false +TFM="net8.0" +GENERATE_DOTNET_BUILD_TARGET=true +PARAMS=() +CUSTOM_PROP= +NET_FRAMEWORK_VER= +RID="linux-x64" +HOST_ARCH="i386" +# Common cmake flags +CMAKE_COMMON="" + +function print_help() { + echo "Usage: $0 [-cdvspnt] [-b properties-file.csproj] [--no-gui] [--skip-fetch] [--profile-build] [--tlib-only] [--tlib-export-compile-commands] [--tlib-arch ] [--host-arch i386|aarch64] [-- ]" + echo + echo "-v verbose output" + echo "--no-gui build with GUI disabled" + echo "--force-net-framework-version build against different version of .NET Framework than specified in the solution" + echo "--net build with dotnet" + echo "-F select the target framework for which Renode should be built (default value: $TFM)" + echo "--profile-build build optimized for profiling" + echo "--tlib-only only build tlib" + echo " arguments to pass to the build system" +} + +while getopts "v::-:" opt +do + case $opt in + v) + PARAMS+=(verbosity:detailed) + ;; + -) + case $OPTARG in + "no-gui") + HEADLESS=true + ;; + "force-net-framework-version") + shift $((OPTIND-1)) + NET_FRAMEWORK_VER=p:TargetFrameworkVersion=v$1 + PARAMS+=($NET_FRAMEWORK_VER) + OPTIND=2 + ;; + "net") + NET=true + PARAMS+=(p:NET=true) + ;; + "tlib-only") + TLIB_ONLY=true + ;; + *) + print_help + exit 1 + ;; + esac + ;; + \?) + print_help + exit 1 + ;; + esac +done +shift "$((OPTIND-1))" +PARAMS+=( + # By default use CC as Compiler- and LinkerPath, and AR as ArPath + ${CC:+"p:CompilerPath=$CC"} + ${CC:+"p:LinkerPath=$CC"} + ${AR:+"p:ArPath=$AR"} + # But allow users to override it + "$@" +) + +if [ -n "${PLATFORM:-}" ] +then + echo "PLATFORM environment variable is currently set to: >>$PLATFORM<<" + echo "This might cause problems during the build." + echo "Please clear it with:" + echo "" + echo " unset PLATFORM" + echo "" + echo " and run the build script again." + + exit 1 +fi + +# We can only update parts of this repository if Renode is built from within the git tree +if [ ! -e .git ] +then + SKIP_FETCH=true + UPDATE_SUBMODULES=false +fi + +if $SKIP_FETCH +then + echo "Skipping init/update of submodules" +fi + +. "${ROOT_PATH}/tools/common.sh" + +if $SKIP_FETCH +then + echo "Skipping library fetch" +fi + +if $HEADLESS +then + BUILD_TARGET=Headless + PARAMS+=(p:GUI_DISABLED=true) +fi + +if [[ $GENERATE_DOTNET_BUILD_TARGET = true ]]; then + if $ON_WINDOWS; then + # CsWinRTAotOptimizerEnabled is disabled due to a bug in dotnet-sdk. + # See: https://github.com/dotnet/sdk/issues/44026 + OS_SPECIFIC_TARGET_OPTS='false' + fi +fi + +OUT_BIN_DIR="$(get_path "output/bin/${CONFIGURATION}")" +BUILD_TYPE_FILE=$(get_path "${OUT_BIN_DIR}/build_type") + +CORES_PATH="$ROOT_PATH/src/Infrastructure/src/Emulator/Cores" + +# check weak implementations of core libraries +pushd "$ROOT_PATH/tools/building" > /dev/null + ./check_weak_implementations.sh +popd > /dev/null + +PARAMS+=(p:Configuration=${CONFIGURATION}${BUILD_TARGET} p:GenerateFullPaths=true p:Platform="\"$BUILD_PLATFORM\"") + +# Paths for tlib +CORES_BUILD_PATH="$CORES_PATH/obj/$CONFIGURATION" +CORES_BIN_PATH="$CORES_PATH/bin/$CONFIGURATION" + +# Cmake generator, handled in their own variable since the names contain spaces +CMAKE_GEN="-GNinja" + +# This list contains all cores that will be built. +# If you are adding a new core or endianness add it here to have the correct tlib built +CORES=(arm.le arm.be arm64.le arm-m.le arm-m.be ppc.le ppc.be ppc64.le ppc64.be i386.le x86_64.le riscv.le riscv64.le sparc.le sparc.be xtensa.le) + +# build tlib +for core_config in "${CORES[@]}" +do + echo Building $core_config + CORE="$(echo $core_config | cut -d '.' -f 1)" + ENDIAN="$(echo $core_config | cut -d '.' -f 2)" + BITS=32 + # Check if core is 64-bit + if [[ $CORE =~ "64" ]]; then + BITS=64 + fi + # Core specific flags to cmake + CMAKE_CONF_FLAGS="-DTARGET_ARCH=$CORE -DTARGET_WORD_SIZE=$BITS -DCMAKE_BUILD_TYPE=$CONFIGURATION" + CORE_DIR=$CORES_BUILD_PATH/$CORE/$ENDIAN + mkdir -p $CORE_DIR + pushd "$CORE_DIR" > /dev/null + if [[ $ENDIAN == "be" ]]; then + CMAKE_CONF_FLAGS+=" -DTARGET_BIG_ENDIAN=1" + fi + if [[ "$TLIB_EXPORT_COMPILE_COMMANDS" = true ]]; then + CMAKE_CONF_FLAGS+=" -DCMAKE_EXPORT_COMPILE_COMMANDS=1" + fi + "${CMAKE}" "$CMAKE_GEN" $CMAKE_COMMON $CMAKE_CONF_FLAGS -DHOST_ARCH=$HOST_ARCH $CORES_PATH + "${CMAKE}" --build . -j$(nproc) + CORE_BIN_DIR=$CORES_BIN_PATH/lib + mkdir -p $CORE_BIN_DIR + if $ON_OSX; then + # macos `cp` does not have the -u flag + cp -v tlib/*.so $CORE_BIN_DIR/ + else + cp -u -v tlib/*.so $CORE_BIN_DIR/ + fi + # copy compile_commands.json to tlib directory + if [[ "$TLIB_EXPORT_COMPILE_COMMANDS" = true ]]; then + command cp -v -f $CORE_DIR/compile_commands.json $CORES_PATH/tlib/ + fi + popd > /dev/null +done + +exit 0 diff --git a/recipes/renode-cores/recipe.yaml b/recipes/renode-cores/recipe.yaml index ba68341529191..2a6003090f2e5 100644 --- a/recipes/renode-cores/recipe.yaml +++ b/recipes/renode-cores/recipe.yaml @@ -10,29 +10,32 @@ package: source: - url: https://github.com/renode/renode/releases/download/v${{ version }}/renode_${{ version }}_source.tar.xz sha256: 40c50afe8db86a9c63f4a86b93116a6babd43bf241cfaac47b2c0d2cbc2b15a8 - #- url: https://github.com/renode/renode/archive/refs/tags/v${{ version }}.tar.gz - # sha256: 692604eba16476596ddbc91a4cba1bd5da681dbda076d1980b81f1d333edb7c0 patches: - - if: unix - then: - - patches/update-for-cmake-build.sh.patch + - patches/update-for-cmake-build.sh.patch build: number: 0 requirements: build: - - ${{ compiler('c') }} - - ${{ compiler('cxx') }} - - ${{ stdlib('c') }} - cmake - - make - - tar - if: unix then: + - ${{ compiler('c') }} + - ${{ compiler('cxx') }} + - ${{ stdlib('c') }} + - make - sed + - tar else: + - ${{ compiler('m2w64_c') }} + - ${{ compiler('m2w64_cxx') }} + - ${{ stdlib('m2w64_c') }} + - m2-base + - m2-bash - m2-sed + - m2-tar + - ninja tests: - package_contents: diff --git a/recipes/renode-cores/variants.yaml b/recipes/renode-cores/variants.yaml index 3fdfa2f172c02..342fc500c7ec6 100644 --- a/recipes/renode-cores/variants.yaml +++ b/recipes/renode-cores/variants.yaml @@ -3,5 +3,10 @@ c_stdlib: then: sysroot - if: osx then: macosx_deployment_target - - if: not unix - then: vs + +m2w64_c_compiler: + - m2w64-toolchain +m2w64_cxx_compiler: + - m2w64-toolchain +m2w64_c_stdlib: + - m2w64-toolchain From 3388248af98615c94fa80af89d91ec720f4ae0b4 Mon Sep 17 00:00:00 2001 From: memento Date: Tue, 28 Jan 2025 15:59:58 -0600 Subject: [PATCH 09/26] (fix) use PS1 --- recipes/renode-cores/build.bat | 11 +- .../helpers/renode_build_with_cmake.ps1 | 170 +++++++++++++++ .../helpers/renode_build_with_cmake.sh | 204 ------------------ 3 files changed, 172 insertions(+), 213 deletions(-) create mode 100644 recipes/renode-cores/helpers/renode_build_with_cmake.ps1 delete mode 100644 recipes/renode-cores/helpers/renode_build_with_cmake.sh diff --git a/recipes/renode-cores/build.bat b/recipes/renode-cores/build.bat index 66222e95b7857..92dd2280bb43b 100644 --- a/recipes/renode-cores/build.bat +++ b/recipes/renode-cores/build.bat @@ -7,16 +7,8 @@ copy "%RECIPE_DIR%\patches\Cores-CMakeLists.txt" "%SRC_DIR%\src\Infrastructure\s copy "%RECIPE_DIR%\patches\tlib-CMakeLists.txt" "%SRC_DIR%\src\Infrastructure\src\Emulator\Cores\tlib\CMakeLists.txt" if %errorlevel% neq 0 exit /b %errorlevel% -set "PREFIX=%PREFIX:\=/%" -set "BUILD_PREFIX=%BUILD_PREFIX:\=/%" -set "CONDA_PREFIX=%CONDA_PREFIX:\=/%" -set "SRC_DIR=%SRC_DIR:\=/%" -set "RECIPE_DIR=%RECIPE_DIR:\=/%" -set MSYSTEM=UCRT64 -set MSYS2_PATH_TYPE=inherit -set CHERE_INVOKING=1 -call bash -lc "${RECIPE_DIR}/helpers/renode_build_with_cmake.sh --tlib-only --net --no-gui" +powershell -ExecutionPolicy Bypass -File "${env:RECIPE_DIR}/helpers/renode_build_with_cmake.ps1" --tlib-only --net --no-gui if %errorlevel% neq 0 exit /b %errorlevel% rem Install procedure into a conda path that renode-cli can retrieve @@ -27,5 +19,6 @@ set "CORES_BIN_PATH=%CORES_PATH%\bin\%CONFIGURATION%" mkdir "%PREFIX%\Library\lib\%PKG_NAME%" tar -c -C "%CORES_BIN_PATH%\lib" . | tar -x -C "%PREFIX%\Library\lib\%PKG_NAME%" +if %errorlevel% neq 0 exit /b %errorlevel% endlocal diff --git a/recipes/renode-cores/helpers/renode_build_with_cmake.ps1 b/recipes/renode-cores/helpers/renode_build_with_cmake.ps1 new file mode 100644 index 0000000000000..4e6be2295f5e8 --- /dev/null +++ b/recipes/renode-cores/helpers/renode_build_with_cmake.ps1 @@ -0,0 +1,170 @@ +$ErrorActionPreference = "Stop" + +$env:PATH = "${env:BUILD_PREFIX}/Library/mingw-w64/bin;${env:BUILD_PREFIX}/Library/bin;${env:PREFIX}/Library/bin;${env:PREFIX}/bin;${env:PATH}" +$env:ROOT_PATH = $env:SRC_DIR + +$CMAKE = (Get-Command cmake).Source + +$OUTPUT_DIRECTORY = "$env:ROOT_PATH/output" +$EXPORT_DIRECTORY = "" + +$UPDATE_SUBMODULES = $false +$CONFIGURATION = "Release" +$BUILD_PLATFORM = "Any CPU" +$CLEAN = $false +$PACKAGES = $false +$NIGHTLY = $false +$PORTABLE = $false +$HEADLESS = $false +$SKIP_FETCH = $false +$TLIB_ONLY = $false +$TLIB_EXPORT_COMPILE_COMMANDS = $false +$TLIB_ARCH = "" +$NET = $false +$TFM = "net8.0" +$GENERATE_DOTNET_BUILD_TARGET = $true +$PARAMS = @() +$CUSTOM_PROP = $null +$NET_FRAMEWORK_VER = $null +$RID = "linux-x64" +$HOST_ARCH = "i386" +$CMAKE_COMMON = "" + +function print_help { + Write-Host "Usage: $0 [-cdvspnt] [-b properties-file.csproj] [--no-gui] [--skip-fetch] [--profile-build] [--tlib-only] [--tlib-export-compile-commands] [--tlib-arch ] [--host-arch i386|aarch64] [-- ]" + Write-Host + Write-Host "-v verbose output" + Write-Host "--no-gui build with GUI disabled" + Write-Host "--force-net-framework-version build against different version of .NET Framework than specified in the solution" + Write-Host "--net build with dotnet" + Write-Host "-F select the target framework for which Renode should be built (default value: $TFM)" + Write-Host "--profile-build build optimized for profiling" + Write-Host "--tlib-only only build tlib" + Write-Host " arguments to pass to the build system" +} + +$opts = Get-CommandLineArgs +while ($opts.Count -gt 0) { + $opt = $opts[0] + switch -regex ($opt) { + "-v" { + $PARAMS += "verbosity:detailed" + $opts = $opts[1..$($opts.Count - 1)] + } + "--no-gui" { + $HEADLESS = $true + $opts = $opts[1..$($opts.Count - 1)] + } + "--force-net-framework-version" { + $NET_FRAMEWORK_VER = "p:TargetFrameworkVersion=v$($opts[1])" + $PARAMS += $NET_FRAMEWORK_VER + $opts = $opts[2..$($opts.Count - 1)] + } + "--net" { + $NET = $true + $PARAMS += "p:NET=true" + $opts = $opts[1..$($opts.Count - 1)] + } + "--tlib-only" { + $TLIB_ONLY = $true + $opts = $opts[1..$($opts.Count - 1)] + } + default { + print_help + exit 1 + } + } +} + +$PARAMS += @( + ${env:CC} ? "p:CompilerPath=$env:CC" : $null, + ${env:CC} ? "p:LinkerPath=$env:CC" : $null, + ${env:AR} ? "p:ArPath=$env:AR" : $null +) + $opts + +if ($env:PLATFORM) { + Write-Host "PLATFORM environment variable is currently set to: >>$env:PLATFORM<<" + Write-Host "This might cause problems during the build." + Write-Host "Please clear it with:" + Write-Host + Write-Host " unset PLATFORM" + Write-Host + Write-Host " and run the build script again." + exit 1 +} + +if (-not (Test-Path .git)) { + $SKIP_FETCH = $true + $UPDATE_SUBMODULES = $false +} + +if ($SKIP_FETCH) { + Write-Host "Skipping init/update of submodules" +} + +. "${env:ROOT_PATH}/tools/common.ps1" + +if ($SKIP_FETCH) { + Write-Host "Skipping library fetch" +} + +if ($HEADLESS) { + $BUILD_TARGET = "Headless" + $PARAMS += "p:GUI_DISABLED=true" +} + +if ($GENERATE_DOTNET_BUILD_TARGET) { + if ($env:ON_WINDOWS) { + $OS_SPECIFIC_TARGET_OPTS = 'false' + } +} + +$OUT_BIN_DIR = Join-Path -Path "output/bin" -ChildPath $CONFIGURATION +$BUILD_TYPE_FILE = Join-Path -Path $OUT_BIN_DIR -ChildPath "build_type" + +$CORES_PATH = Join-Path -Path $env:ROOT_PATH -ChildPath "src/Infrastructure/src/Emulator/Cores" + +Push-Location "$env:ROOT_PATH/tools/building" +./check_weak_implementations.ps1 +Pop-Location + +$PARAMS += "p:Configuration=${CONFIGURATION}${BUILD_TARGET}" "p:GenerateFullPaths=true" "p:Platform=`"$BUILD_PLATFORM`"" + +$CORES_BUILD_PATH = Join-Path -Path $CORES_PATH -ChildPath "obj/$CONFIGURATION" +$CORES_BIN_PATH = Join-Path -Path $CORES_PATH -ChildPath "bin/$CONFIGURATION" + +$CMAKE_GEN = "-GNinja" + +$CORES = @("arm.le", "arm.be", "arm64.le", "arm-m.le", "arm-m.be", "ppc.le", "ppc.be", "ppc64.le", "ppc64.be", "i386.le", "x86_64.le", "riscv.le", "riscv64.le", "sparc.le", "sparc.be", "xtensa.le") + +foreach ($core_config in $CORES) { + Write-Host "Building $core_config" + $CORE = $core_config.Split('.')[0] + $ENDIAN = $core_config.Split('.')[1] + $BITS = if ($CORE -match "64") { 64 } else { 32 } + $CMAKE_CONF_FLAGS = "-DTARGET_ARCH=$CORE -DTARGET_WORD_SIZE=$BITS -DCMAKE_BUILD_TYPE=$CONFIGURATION" + $CORE_DIR = Join-Path -Path $CORES_BUILD_PATH -ChildPath "$CORE/$ENDIAN" + New-Item -ItemType Directory -Path $CORE_DIR -Force | Out-Null + Push-Location $CORE_DIR + if ($ENDIAN -eq "be") { + $CMAKE_CONF_FLAGS += " -DTARGET_BIG_ENDIAN=1" + } + if ($TLIB_EXPORT_COMPILE_COMMANDS) { + $CMAKE_CONF_FLAGS += " -DCMAKE_EXPORT_COMPILE_COMMANDS=1" + } + & $CMAKE $CMAKE_GEN $CMAKE_COMMON $CMAKE_CONF_FLAGS -DHOST_ARCH=$HOST_ARCH $CORES_PATH + & $CMAKE --build . -j (Get-ProcessorCount) + $CORE_BIN_DIR = Join-Path -Path $CORES_BIN_PATH -ChildPath "lib" + New-Item -ItemType Directory -Path $CORE_BIN_DIR -Force | Out-Null + if ($env:ON_OSX) { + Copy-Item -Path "tlib/*.so" -Destination $CORE_BIN_DIR -Verbose + } else { + Copy-Item -Path "tlib/*.so" -Destination $CORE_BIN_DIR -Force -Verbose + } + if ($TLIB_EXPORT_COMPILE_COMMANDS) { + Copy-Item -Path "$CORE_DIR/compile_commands.json" -Destination "$CORES_PATH/tlib/" -Force -Verbose + } + Pop-Location +} + +exit 0 \ No newline at end of file diff --git a/recipes/renode-cores/helpers/renode_build_with_cmake.sh b/recipes/renode-cores/helpers/renode_build_with_cmake.sh deleted file mode 100644 index 60cf163c3d47a..0000000000000 --- a/recipes/renode-cores/helpers/renode_build_with_cmake.sh +++ /dev/null @@ -1,204 +0,0 @@ -#!/usr/bin/env bash - -set -u -set -e - -export PATH="${BUILD_PREFIX}/Library/mingw-w64/bin:${BUILD_PREFIX}/Library/bin:${PREFIX}/Library/bin:${PREFIX}/bin:${PATH}" -export ROOT_PATH="$SRC_DIR" - -CMAKE=$(which cmake) - -OUTPUT_DIRECTORY="$ROOT_PATH/output" -EXPORT_DIRECTORY="" - -UPDATE_SUBMODULES=false -CONFIGURATION="Release" -BUILD_PLATFORM="Any CPU" -CLEAN=false -PACKAGES=false -NIGHTLY=false -PORTABLE=false -HEADLESS=false -SKIP_FETCH=false -TLIB_ONLY=false -TLIB_EXPORT_COMPILE_COMMANDS=false -TLIB_ARCH="" -NET=false -TFM="net8.0" -GENERATE_DOTNET_BUILD_TARGET=true -PARAMS=() -CUSTOM_PROP= -NET_FRAMEWORK_VER= -RID="linux-x64" -HOST_ARCH="i386" -# Common cmake flags -CMAKE_COMMON="" - -function print_help() { - echo "Usage: $0 [-cdvspnt] [-b properties-file.csproj] [--no-gui] [--skip-fetch] [--profile-build] [--tlib-only] [--tlib-export-compile-commands] [--tlib-arch ] [--host-arch i386|aarch64] [-- ]" - echo - echo "-v verbose output" - echo "--no-gui build with GUI disabled" - echo "--force-net-framework-version build against different version of .NET Framework than specified in the solution" - echo "--net build with dotnet" - echo "-F select the target framework for which Renode should be built (default value: $TFM)" - echo "--profile-build build optimized for profiling" - echo "--tlib-only only build tlib" - echo " arguments to pass to the build system" -} - -while getopts "v::-:" opt -do - case $opt in - v) - PARAMS+=(verbosity:detailed) - ;; - -) - case $OPTARG in - "no-gui") - HEADLESS=true - ;; - "force-net-framework-version") - shift $((OPTIND-1)) - NET_FRAMEWORK_VER=p:TargetFrameworkVersion=v$1 - PARAMS+=($NET_FRAMEWORK_VER) - OPTIND=2 - ;; - "net") - NET=true - PARAMS+=(p:NET=true) - ;; - "tlib-only") - TLIB_ONLY=true - ;; - *) - print_help - exit 1 - ;; - esac - ;; - \?) - print_help - exit 1 - ;; - esac -done -shift "$((OPTIND-1))" -PARAMS+=( - # By default use CC as Compiler- and LinkerPath, and AR as ArPath - ${CC:+"p:CompilerPath=$CC"} - ${CC:+"p:LinkerPath=$CC"} - ${AR:+"p:ArPath=$AR"} - # But allow users to override it - "$@" -) - -if [ -n "${PLATFORM:-}" ] -then - echo "PLATFORM environment variable is currently set to: >>$PLATFORM<<" - echo "This might cause problems during the build." - echo "Please clear it with:" - echo "" - echo " unset PLATFORM" - echo "" - echo " and run the build script again." - - exit 1 -fi - -# We can only update parts of this repository if Renode is built from within the git tree -if [ ! -e .git ] -then - SKIP_FETCH=true - UPDATE_SUBMODULES=false -fi - -if $SKIP_FETCH -then - echo "Skipping init/update of submodules" -fi - -. "${ROOT_PATH}/tools/common.sh" - -if $SKIP_FETCH -then - echo "Skipping library fetch" -fi - -if $HEADLESS -then - BUILD_TARGET=Headless - PARAMS+=(p:GUI_DISABLED=true) -fi - -if [[ $GENERATE_DOTNET_BUILD_TARGET = true ]]; then - if $ON_WINDOWS; then - # CsWinRTAotOptimizerEnabled is disabled due to a bug in dotnet-sdk. - # See: https://github.com/dotnet/sdk/issues/44026 - OS_SPECIFIC_TARGET_OPTS='false' - fi -fi - -OUT_BIN_DIR="$(get_path "output/bin/${CONFIGURATION}")" -BUILD_TYPE_FILE=$(get_path "${OUT_BIN_DIR}/build_type") - -CORES_PATH="$ROOT_PATH/src/Infrastructure/src/Emulator/Cores" - -# check weak implementations of core libraries -pushd "$ROOT_PATH/tools/building" > /dev/null - ./check_weak_implementations.sh -popd > /dev/null - -PARAMS+=(p:Configuration=${CONFIGURATION}${BUILD_TARGET} p:GenerateFullPaths=true p:Platform="\"$BUILD_PLATFORM\"") - -# Paths for tlib -CORES_BUILD_PATH="$CORES_PATH/obj/$CONFIGURATION" -CORES_BIN_PATH="$CORES_PATH/bin/$CONFIGURATION" - -# Cmake generator, handled in their own variable since the names contain spaces -CMAKE_GEN="-GNinja" - -# This list contains all cores that will be built. -# If you are adding a new core or endianness add it here to have the correct tlib built -CORES=(arm.le arm.be arm64.le arm-m.le arm-m.be ppc.le ppc.be ppc64.le ppc64.be i386.le x86_64.le riscv.le riscv64.le sparc.le sparc.be xtensa.le) - -# build tlib -for core_config in "${CORES[@]}" -do - echo Building $core_config - CORE="$(echo $core_config | cut -d '.' -f 1)" - ENDIAN="$(echo $core_config | cut -d '.' -f 2)" - BITS=32 - # Check if core is 64-bit - if [[ $CORE =~ "64" ]]; then - BITS=64 - fi - # Core specific flags to cmake - CMAKE_CONF_FLAGS="-DTARGET_ARCH=$CORE -DTARGET_WORD_SIZE=$BITS -DCMAKE_BUILD_TYPE=$CONFIGURATION" - CORE_DIR=$CORES_BUILD_PATH/$CORE/$ENDIAN - mkdir -p $CORE_DIR - pushd "$CORE_DIR" > /dev/null - if [[ $ENDIAN == "be" ]]; then - CMAKE_CONF_FLAGS+=" -DTARGET_BIG_ENDIAN=1" - fi - if [[ "$TLIB_EXPORT_COMPILE_COMMANDS" = true ]]; then - CMAKE_CONF_FLAGS+=" -DCMAKE_EXPORT_COMPILE_COMMANDS=1" - fi - "${CMAKE}" "$CMAKE_GEN" $CMAKE_COMMON $CMAKE_CONF_FLAGS -DHOST_ARCH=$HOST_ARCH $CORES_PATH - "${CMAKE}" --build . -j$(nproc) - CORE_BIN_DIR=$CORES_BIN_PATH/lib - mkdir -p $CORE_BIN_DIR - if $ON_OSX; then - # macos `cp` does not have the -u flag - cp -v tlib/*.so $CORE_BIN_DIR/ - else - cp -u -v tlib/*.so $CORE_BIN_DIR/ - fi - # copy compile_commands.json to tlib directory - if [[ "$TLIB_EXPORT_COMPILE_COMMANDS" = true ]]; then - command cp -v -f $CORE_DIR/compile_commands.json $CORES_PATH/tlib/ - fi - popd > /dev/null -done - -exit 0 From 51bc4e66604c69146e66afe780f0956baed49138 Mon Sep 17 00:00:00 2001 From: MementoRC Date: Wed, 29 Jan 2025 09:46:24 -0800 Subject: [PATCH 10/26] (wip) built non-unix till tests --- recipes/renode-cores/build.bat | 5 +- .../helpers/renode_build_with_cmake.ps1 | 125 +++++++++--------- 2 files changed, 63 insertions(+), 67 deletions(-) diff --git a/recipes/renode-cores/build.bat b/recipes/renode-cores/build.bat index 92dd2280bb43b..8f402f3846b9f 100644 --- a/recipes/renode-cores/build.bat +++ b/recipes/renode-cores/build.bat @@ -7,8 +7,7 @@ copy "%RECIPE_DIR%\patches\Cores-CMakeLists.txt" "%SRC_DIR%\src\Infrastructure\s copy "%RECIPE_DIR%\patches\tlib-CMakeLists.txt" "%SRC_DIR%\src\Infrastructure\src\Emulator\Cores\tlib\CMakeLists.txt" if %errorlevel% neq 0 exit /b %errorlevel% - -powershell -ExecutionPolicy Bypass -File "${env:RECIPE_DIR}/helpers/renode_build_with_cmake.ps1" --tlib-only --net --no-gui +powershell -ExecutionPolicy Bypass -File "%RECIPE_DIR%\helpers\renode_build_with_cmake.ps1" --tlib-only --net --no-gui if %errorlevel% neq 0 exit /b %errorlevel% rem Install procedure into a conda path that renode-cli can retrieve @@ -18,7 +17,7 @@ set "CORES_PATH=%ROOT_PATH%src\Infrastructure\src\Emulator\Cores" set "CORES_BIN_PATH=%CORES_PATH%\bin\%CONFIGURATION%" mkdir "%PREFIX%\Library\lib\%PKG_NAME%" -tar -c -C "%CORES_BIN_PATH%\lib" . | tar -x -C "%PREFIX%\Library\lib\%PKG_NAME%" +robocopy "%CORES_BIN_PATH%\lib" "%PREFIX%\Library\lib\%PKG_NAME%" /E /COPY:DATSO if %errorlevel% neq 0 exit /b %errorlevel% endlocal diff --git a/recipes/renode-cores/helpers/renode_build_with_cmake.ps1 b/recipes/renode-cores/helpers/renode_build_with_cmake.ps1 index 4e6be2295f5e8..e14420b7fed74 100644 --- a/recipes/renode-cores/helpers/renode_build_with_cmake.ps1 +++ b/recipes/renode-cores/helpers/renode_build_with_cmake.ps1 @@ -1,5 +1,37 @@ $ErrorActionPreference = "Stop" +function Get-CommandLineArgs { + param ( + [string[]]$args = $null + ) + if ($args -eq $null) { + $args = $global:args + } + return $args +} + +function Get-CpuCount { + $cpuCount = (Get-WmiObject -Class Win32_Processor).NumberOfCores + return $cpuCount +} + +function Remove-fPICFlag { + param ( + [string]$filePath + ) + + if (-Not (Test-Path $filePath)) { + Write-Host "File not found: $filePath" + return + } + + $fileContent = Get-Content -Path $filePath + $updatedContent = $fileContent -replace "-fPIC","-Wno-unused-function" + Set-Content -Path $filePath -Value $updatedContent + + Write-Host "Removed '-fPIC' from $filePath" +} + $env:PATH = "${env:BUILD_PREFIX}/Library/mingw-w64/bin;${env:BUILD_PREFIX}/Library/bin;${env:PREFIX}/Library/bin;${env:PREFIX}/bin;${env:PATH}" $env:ROOT_PATH = $env:SRC_DIR @@ -23,7 +55,6 @@ $TLIB_ARCH = "" $NET = $false $TFM = "net8.0" $GENERATE_DOTNET_BUILD_TARGET = $true -$PARAMS = @() $CUSTOM_PROP = $null $NET_FRAMEWORK_VER = $null $RID = "linux-x64" @@ -48,21 +79,14 @@ while ($opts.Count -gt 0) { $opt = $opts[0] switch -regex ($opt) { "-v" { - $PARAMS += "verbosity:detailed" $opts = $opts[1..$($opts.Count - 1)] } "--no-gui" { $HEADLESS = $true $opts = $opts[1..$($opts.Count - 1)] } - "--force-net-framework-version" { - $NET_FRAMEWORK_VER = "p:TargetFrameworkVersion=v$($opts[1])" - $PARAMS += $NET_FRAMEWORK_VER - $opts = $opts[2..$($opts.Count - 1)] - } "--net" { $NET = $true - $PARAMS += "p:NET=true" $opts = $opts[1..$($opts.Count - 1)] } "--tlib-only" { @@ -76,12 +100,6 @@ while ($opts.Count -gt 0) { } } -$PARAMS += @( - ${env:CC} ? "p:CompilerPath=$env:CC" : $null, - ${env:CC} ? "p:LinkerPath=$env:CC" : $null, - ${env:AR} ? "p:ArPath=$env:AR" : $null -) + $opts - if ($env:PLATFORM) { Write-Host "PLATFORM environment variable is currently set to: >>$env:PLATFORM<<" Write-Host "This might cause problems during the build." @@ -93,77 +111,56 @@ if ($env:PLATFORM) { exit 1 } -if (-not (Test-Path .git)) { - $SKIP_FETCH = $true - $UPDATE_SUBMODULES = $false -} - -if ($SKIP_FETCH) { - Write-Host "Skipping init/update of submodules" -} - -. "${env:ROOT_PATH}/tools/common.ps1" - -if ($SKIP_FETCH) { - Write-Host "Skipping library fetch" -} - if ($HEADLESS) { + Write-Host "Headless build" $BUILD_TARGET = "Headless" - $PARAMS += "p:GUI_DISABLED=true" } -if ($GENERATE_DOTNET_BUILD_TARGET) { - if ($env:ON_WINDOWS) { - $OS_SPECIFIC_TARGET_OPTS = 'false' - } -} - -$OUT_BIN_DIR = Join-Path -Path "output/bin" -ChildPath $CONFIGURATION +$OUT_BIN_DIR = Join-Path -Path "output\bin" -ChildPath $CONFIGURATION $BUILD_TYPE_FILE = Join-Path -Path $OUT_BIN_DIR -ChildPath "build_type" -$CORES_PATH = Join-Path -Path $env:ROOT_PATH -ChildPath "src/Infrastructure/src/Emulator/Cores" +$CORES_PATH = Join-Path -Path $env:ROOT_PATH -ChildPath "src\Infrastructure\src\Emulator\Cores" -Push-Location "$env:ROOT_PATH/tools/building" -./check_weak_implementations.ps1 +Push-Location "$env:ROOT_PATH\tools\building" + bash .\check_weak_implementations.sh Pop-Location -$PARAMS += "p:Configuration=${CONFIGURATION}${BUILD_TARGET}" "p:GenerateFullPaths=true" "p:Platform=`"$BUILD_PLATFORM`"" - -$CORES_BUILD_PATH = Join-Path -Path $CORES_PATH -ChildPath "obj/$CONFIGURATION" -$CORES_BIN_PATH = Join-Path -Path $CORES_PATH -ChildPath "bin/$CONFIGURATION" +$CORES_BUILD_PATH = Join-Path -Path $CORES_PATH -ChildPath "obj\$CONFIGURATION" +$CORES_BIN_PATH = Join-Path -Path $CORES_PATH -ChildPath "bin\$CONFIGURATION" $CMAKE_GEN = "-GNinja" $CORES = @("arm.le", "arm.be", "arm64.le", "arm-m.le", "arm-m.be", "ppc.le", "ppc.be", "ppc64.le", "ppc64.be", "i386.le", "x86_64.le", "riscv.le", "riscv64.le", "sparc.le", "sparc.be", "xtensa.le") +Remove-fPICFlag -filePath "$CORES_PATH\tlib\CMakeLists.txt" +Remove-fPICFlag -filePath "$CORES_PATH\tlib\tcg\CMakeLists.txt" foreach ($core_config in $CORES) { Write-Host "Building $core_config" + $CORE = $core_config.Split('.')[0] $ENDIAN = $core_config.Split('.')[1] $BITS = if ($CORE -match "64") { 64 } else { 32 } - $CMAKE_CONF_FLAGS = "-DTARGET_ARCH=$CORE -DTARGET_WORD_SIZE=$BITS -DCMAKE_BUILD_TYPE=$CONFIGURATION" - $CORE_DIR = Join-Path -Path $CORES_BUILD_PATH -ChildPath "$CORE/$ENDIAN" + + $CMAKE_CONF_FLAGS = @( + "-DTARGET_ARCH=$CORE" + "-DTARGET_WORD_SIZE=$BITS" + "-DCMAKE_BUILD_TYPE=$CONFIGURATION" + ) + + $CORE_DIR = Join-Path -Path $CORES_BUILD_PATH -ChildPath "$CORE\$ENDIAN" New-Item -ItemType Directory -Path $CORE_DIR -Force | Out-Null Push-Location $CORE_DIR - if ($ENDIAN -eq "be") { - $CMAKE_CONF_FLAGS += " -DTARGET_BIG_ENDIAN=1" - } - if ($TLIB_EXPORT_COMPILE_COMMANDS) { - $CMAKE_CONF_FLAGS += " -DCMAKE_EXPORT_COMPILE_COMMANDS=1" - } - & $CMAKE $CMAKE_GEN $CMAKE_COMMON $CMAKE_CONF_FLAGS -DHOST_ARCH=$HOST_ARCH $CORES_PATH - & $CMAKE --build . -j (Get-ProcessorCount) - $CORE_BIN_DIR = Join-Path -Path $CORES_BIN_PATH -ChildPath "lib" - New-Item -ItemType Directory -Path $CORE_BIN_DIR -Force | Out-Null - if ($env:ON_OSX) { - Copy-Item -Path "tlib/*.so" -Destination $CORE_BIN_DIR -Verbose - } else { - Copy-Item -Path "tlib/*.so" -Destination $CORE_BIN_DIR -Force -Verbose - } - if ($TLIB_EXPORT_COMPILE_COMMANDS) { - Copy-Item -Path "$CORE_DIR/compile_commands.json" -Destination "$CORES_PATH/tlib/" -Force -Verbose - } + if ($ENDIAN -eq "be") { + $CMAKE_CONF_FLAGS += @("-DTARGET_BIG_ENDIAN=1") + } + + # Remove-fPICFlag -filePath "CMakeLists.txt" + & $CMAKE $CMAKE_GEN $CMAKE_COMMON @CMAKE_CONF_FLAGS -DHOST_ARCH="$HOST_ARCH" $CORES_PATH -DCMAKE_VERBOSE_MAKEFILE=ON + & $CMAKE --build . -j (Get-CpuCount) + + $CORE_BIN_DIR = Join-Path -Path $CORES_BIN_PATH -ChildPath "lib" + New-Item -ItemType Directory -Path $CORE_BIN_DIR -Force | Out-Null + Copy-Item -Path "tlib\*.so" -Destination $CORE_BIN_DIR -Force -Verbose Pop-Location } From 37927b8751d65f70c7b196d549827c25fa1e395f Mon Sep 17 00:00:00 2001 From: memento Date: Wed, 29 Jan 2025 10:11:52 -0600 Subject: [PATCH 11/26] (ref) clean non-unix --- recipes/renode-cores/build.bat | 3 +- recipes/renode-cores/build.sh | 5 +- .../helpers/renode_build_with_cmake.ps1 | 76 +-- .../helpers/renode_build_with_cmake.sh | 530 ++++++++++++++++++ 4 files changed, 557 insertions(+), 57 deletions(-) create mode 100755 recipes/renode-cores/helpers/renode_build_with_cmake.sh diff --git a/recipes/renode-cores/build.bat b/recipes/renode-cores/build.bat index 8f402f3846b9f..cdc1a3828113e 100644 --- a/recipes/renode-cores/build.bat +++ b/recipes/renode-cores/build.bat @@ -11,9 +11,8 @@ powershell -ExecutionPolicy Bypass -File "%RECIPE_DIR%\helpers\renode_build_with if %errorlevel% neq 0 exit /b %errorlevel% rem Install procedure into a conda path that renode-cli can retrieve -set "ROOT_PATH=%~dp0.." set "CONFIGURATION=Release" -set "CORES_PATH=%ROOT_PATH%src\Infrastructure\src\Emulator\Cores" +set "CORES_PATH=%SRC_DIR%\src\Infrastructure\src\Emulator\Cores" set "CORES_BIN_PATH=%CORES_PATH%\bin\%CONFIGURATION%" mkdir "%PREFIX%\Library\lib\%PKG_NAME%" diff --git a/recipes/renode-cores/build.sh b/recipes/renode-cores/build.sh index fd8cba6306769..eeb5b57ff3fbc 100644 --- a/recipes/renode-cores/build.sh +++ b/recipes/renode-cores/build.sh @@ -7,12 +7,11 @@ cp ${RECIPE_DIR}/patches/Cores-CMakeLists.txt ${SRC_DIR}/src/Infrastructure/src/ cp ${RECIPE_DIR}/patches/tlib-CMakeLists.txt ${SRC_DIR}/src/Infrastructure/src/Emulator/Cores/tlib/CMakeLists.txt chmod +x build.sh tools/building/check_weak_implementations.sh -./build.sh --tlib-only --net --no-gui +${RECIPE_DIR}/helpers/renode_build_with_cmake.sh --tlib-only --net --no-gui # Install procedure into a conda path that renode-cli can retrieve -ROOT_PATH="$(cd $(dirname $0); echo $PWD)" CONFIGURATION="Release" -CORES_PATH="$ROOT_PATH/src/Infrastructure/src/Emulator/Cores" +CORES_PATH="${SRC_DIR}/src/Infrastructure/src/Emulator/Cores" CORES_BIN_PATH="$CORES_PATH/bin/$CONFIGURATION" mkdir -p "${PREFIX}/lib/${PKG_NAME}" diff --git a/recipes/renode-cores/helpers/renode_build_with_cmake.ps1 b/recipes/renode-cores/helpers/renode_build_with_cmake.ps1 index e14420b7fed74..27bce34554522 100644 --- a/recipes/renode-cores/helpers/renode_build_with_cmake.ps1 +++ b/recipes/renode-cores/helpers/renode_build_with_cmake.ps1 @@ -1,63 +1,28 @@ $ErrorActionPreference = "Stop" -function Get-CommandLineArgs { - param ( - [string[]]$args = $null - ) - if ($args -eq $null) { - $args = $global:args +$opts, $remainingArgs = $global:args | ForEach-Object { + switch -regex ($_) { + "-v"|"--no-gui"|"--net"|"--tlib-only" { + $_ + } + default { + Write-Host "Invalid argument: $_" + exit 1 + } } - return $args } -function Get-CpuCount { - $cpuCount = (Get-WmiObject -Class Win32_Processor).NumberOfCores - return $cpuCount -} - -function Remove-fPICFlag { - param ( - [string]$filePath - ) - - if (-Not (Test-Path $filePath)) { - Write-Host "File not found: $filePath" - return - } - - $fileContent = Get-Content -Path $filePath - $updatedContent = $fileContent -replace "-fPIC","-Wno-unused-function" - Set-Content -Path $filePath -Value $updatedContent - - Write-Host "Removed '-fPIC' from $filePath" -} +$cpuCount = (Get-CimInstance Win32_Processor).NumberOfLogicalProcessors $env:PATH = "${env:BUILD_PREFIX}/Library/mingw-w64/bin;${env:BUILD_PREFIX}/Library/bin;${env:PREFIX}/Library/bin;${env:PREFIX}/bin;${env:PATH}" $env:ROOT_PATH = $env:SRC_DIR $CMAKE = (Get-Command cmake).Source -$OUTPUT_DIRECTORY = "$env:ROOT_PATH/output" -$EXPORT_DIRECTORY = "" - -$UPDATE_SUBMODULES = $false $CONFIGURATION = "Release" -$BUILD_PLATFORM = "Any CPU" -$CLEAN = $false -$PACKAGES = $false -$NIGHTLY = $false -$PORTABLE = $false $HEADLESS = $false -$SKIP_FETCH = $false $TLIB_ONLY = $false -$TLIB_EXPORT_COMPILE_COMMANDS = $false -$TLIB_ARCH = "" $NET = $false -$TFM = "net8.0" -$GENERATE_DOTNET_BUILD_TARGET = $true -$CUSTOM_PROP = $null -$NET_FRAMEWORK_VER = $null -$RID = "linux-x64" $HOST_ARCH = "i386" $CMAKE_COMMON = "" @@ -66,10 +31,7 @@ function print_help { Write-Host Write-Host "-v verbose output" Write-Host "--no-gui build with GUI disabled" - Write-Host "--force-net-framework-version build against different version of .NET Framework than specified in the solution" Write-Host "--net build with dotnet" - Write-Host "-F select the target framework for which Renode should be built (default value: $TFM)" - Write-Host "--profile-build build optimized for profiling" Write-Host "--tlib-only only build tlib" Write-Host " arguments to pass to the build system" } @@ -132,8 +94,19 @@ $CMAKE_GEN = "-GNinja" $CORES = @("arm.le", "arm.be", "arm64.le", "arm-m.le", "arm-m.be", "ppc.le", "ppc.be", "ppc64.le", "ppc64.be", "i386.le", "x86_64.le", "riscv.le", "riscv64.le", "sparc.le", "sparc.be", "xtensa.le") -Remove-fPICFlag -filePath "$CORES_PATH\tlib\CMakeLists.txt" -Remove-fPICFlag -filePath "$CORES_PATH\tlib\tcg\CMakeLists.txt" +function Update-CMakeLists { + param ( + [string]$filePath, + [string]$flagToRemove, + [string]$flagToAdd + ) + (gc $filePath) -replace $flagToRemove,$flagToAdd | sc $filePath +} + +Update-CMakeLists "$CORES_PATH\tlib\CMakeLists.txt" "-fPIC" "-Wno-unused-function" +Update-CMakeLists "$CORES_PATH\tlib\softload-3\CMakeLists.txt" "-fPIC" "" +Update-CMakeLists "$CORES_PATH\tlib\tcg\CMakeLists.txt" "-fPIC" "-Wno-unused-function" + foreach ($core_config in $CORES) { Write-Host "Building $core_config" @@ -154,9 +127,8 @@ foreach ($core_config in $CORES) { $CMAKE_CONF_FLAGS += @("-DTARGET_BIG_ENDIAN=1") } - # Remove-fPICFlag -filePath "CMakeLists.txt" & $CMAKE $CMAKE_GEN $CMAKE_COMMON @CMAKE_CONF_FLAGS -DHOST_ARCH="$HOST_ARCH" $CORES_PATH -DCMAKE_VERBOSE_MAKEFILE=ON - & $CMAKE --build . -j (Get-CpuCount) + & $CMAKE --build . -j $cpuCount $CORE_BIN_DIR = Join-Path -Path $CORES_BIN_PATH -ChildPath "lib" New-Item -ItemType Directory -Path $CORE_BIN_DIR -Force | Out-Null diff --git a/recipes/renode-cores/helpers/renode_build_with_cmake.sh b/recipes/renode-cores/helpers/renode_build_with_cmake.sh new file mode 100755 index 0000000000000..e8b4c4954cb06 --- /dev/null +++ b/recipes/renode-cores/helpers/renode_build_with_cmake.sh @@ -0,0 +1,530 @@ +#!/usr/bin/env bash + +set -u +set -e + +export ROOT_PATH="$(cd $(dirname $0); echo $PWD)" +OUTPUT_DIRECTORY="$ROOT_PATH/output" +EXPORT_DIRECTORY="" + +UPDATE_SUBMODULES=false +CONFIGURATION="Release" +BUILD_PLATFORM="Any CPU" +CLEAN=false +PACKAGES=false +NIGHTLY=false +PORTABLE=false +HEADLESS=false +SKIP_FETCH=false +TLIB_ONLY=false +TLIB_EXPORT_COMPILE_COMMANDS=false +TLIB_ARCH="" +NET=false +TFM="net8.0" +GENERATE_DOTNET_BUILD_TARGET=true +PARAMS=() +CUSTOM_PROP= +NET_FRAMEWORK_VER= +RID="linux-x64" +HOST_ARCH="i386" +# Common cmake flags +CMAKE_COMMON="" + +function print_help() { + echo "Usage: $0 [-cdvspnt] [-b properties-file.csproj] [--no-gui] [--skip-fetch] [--profile-build] [--tlib-only] [--tlib-export-compile-commands] [--tlib-arch ] [--host-arch i386|aarch64] [-- ]" + echo + echo "-c clean instead of building" + echo "-d build Debug configuration" + echo "-v verbose output" + echo "-p create packages after building" + echo "-n create nightly packages after building" + echo "-t create a portable package (experimental, Linux only)" + echo "-s update submodules" + echo "-b custom build properties file" + echo "-o custom output directory" + echo "--skip-fetch skip fetching submodules and additional resources" + echo "--no-gui build with GUI disabled" + echo "--force-net-framework-version build against different version of .NET Framework than specified in the solution" + echo "--net build with dotnet" + echo "-B bundle target runtime (default value: $RID, requires --net, -t)" + echo "-F select the target framework for which Renode should be built (default value: $TFM)" + echo "--profile-build build optimized for profiling" + echo "--tlib-only only build tlib" + echo "--tlib-arch build only single arch (implies --tlib-only)" + echo "--tlib-export-compile-commands build tlibs with 'compile_commands.json' (requires --tlib-arch)" + echo "--host-arch build with a specific tcg host architecture (default: i386)" + echo "--skip-dotnet-target-generation don't generate 'Directory.Build.targets' file, useful when experimenting with different build settings" + echo " arguments to pass to the build system" +} + +while getopts "cdvpnstb:o:B:F:a:-:" opt +do + case $opt in + c) + CLEAN=true + ;; + d) + CONFIGURATION="Debug" + ;; + v) + PARAMS+=(verbosity:detailed) + ;; + p) + PACKAGES=true + ;; + n) + NIGHTLY=true + PACKAGES=true + ;; + t) + PORTABLE=true + ;; + s) + UPDATE_SUBMODULES=true + ;; + b) + CUSTOM_PROP=$OPTARG + ;; + o) + EXPORT_DIRECTORY=$OPTARG + echo "Setting the output directory to $EXPORT_DIRECTORY" + ;; + B) + RID=$OPTARG + ;; + F) + if ! $NET; then + echo "-F requires --net being set" + exit 1 + fi + TFM=$OPTARG + ;; + -) + case $OPTARG in + "no-gui") + HEADLESS=true + ;; + "skip-fetch") + SKIP_FETCH=true + ;; + "force-net-framework-version") + shift $((OPTIND-1)) + NET_FRAMEWORK_VER=p:TargetFrameworkVersion=v$1 + PARAMS+=($NET_FRAMEWORK_VER) + OPTIND=2 + ;; + "net") + NET=true + PARAMS+=(p:NET=true) + ;; + "profile-build") + CMAKE_COMMON="-DPROFILING_BUILD=ON" + ;; + "tlib-only") + TLIB_ONLY=true + ;; + "tlib-arch") + # This only makes sense with '--tlib-only' set; it might as well imply it + TLIB_ONLY=true + shift $((OPTIND-1)) + TLIB_ARCH=$1 + OPTIND=2 + ;; + "tlib-export-compile-commands") + if [ -z $TLIB_ARCH ]; then + echo "--tlib-export-compile-commands requires --tlib-arch begin set" + exit 1 + fi + TLIB_EXPORT_COMPILE_COMMANDS=true + ;; + "host-arch") + shift $((OPTIND-1)) + HOST_ARCH=$1 + OPTIND=2 + ;; + "skip-dotnet-target-generation") + GENERATE_DOTNET_BUILD_TARGET=false + ;; + *) + print_help + exit 1 + ;; + esac + ;; + \?) + print_help + exit 1 + ;; + esac +done +shift "$((OPTIND-1))" +PARAMS+=( + # By default use CC as Compiler- and LinkerPath, and AR as ArPath + ${CC:+"p:CompilerPath=$CC"} + ${CC:+"p:LinkerPath=$CC"} + ${AR:+"p:ArPath=$AR"} + # But allow users to override it + "$@" +) + +if [ -n "${PLATFORM:-}" ] +then + echo "PLATFORM environment variable is currently set to: >>$PLATFORM<<" + echo "This might cause problems during the build." + echo "Please clear it with:" + echo "" + echo " unset PLATFORM" + echo "" + echo " and run the build script again." + + exit 1 +fi + +# We can only update parts of this repository if Renode is built from within the git tree +if [ ! -e .git ] +then + SKIP_FETCH=true + UPDATE_SUBMODULES=false +fi + +if $SKIP_FETCH +then + echo "Skipping init/update of submodules" +else + # Update submodules if not initialized or if requested by the user + # Warn if not updating, but unclean + # Disabling -e to allow grep to fail + set +e + git submodule status --recursive | grep -q "^-" + SUBMODULES_NOT_INITED=$? + + git submodule status --recursive | grep -q "^+" + SUBMODULES_NOT_CLEAN=$? + set -e + if $UPDATE_SUBMODULES || [ $SUBMODULES_NOT_INITED -eq 0 ] + then + echo "Updating submodules..." + git submodule update --init --recursive + elif [ $SUBMODULES_NOT_CLEAN -eq 0 ] + then + echo "Submodules are not updated. Use -s to force update." + fi +fi + +. "${ROOT_PATH}/tools/common.sh" + +if $SKIP_FETCH +then + echo "Skipping library fetch" +else + "${ROOT_PATH}"/tools/building/fetch_libraries.sh +fi + +if $HEADLESS +then + BUILD_TARGET=Headless + PARAMS+=(p:GUI_DISABLED=true) +elif $ON_WINDOWS +then + BUILD_TARGET=Windows + TFM="$TFM-windows10.0.17763.0" + RID="win-x64" +else + BUILD_TARGET=Mono +fi + +if [[ $GENERATE_DOTNET_BUILD_TARGET = true ]]; then + if $ON_WINDOWS; then + # CsWinRTAotOptimizerEnabled is disabled due to a bug in dotnet-sdk. + # See: https://github.com/dotnet/sdk/issues/44026 + OS_SPECIFIC_TARGET_OPTS='false' + fi + +cat < "$(get_path "$PWD/Directory.Build.targets")" + + + $TFM + ${OS_SPECIFIC_TARGET_OPTS:+${OS_SPECIFIC_TARGET_OPTS}} + + +EOF + +fi + +if $NET +then + export DOTNET_CLI_TELEMETRY_OPTOUT=1 + CS_COMPILER="dotnet build" + TARGET="`get_path \"$PWD/Renode_NET.sln\"`" + BUILD_TYPE="dotnet" +else + TARGET="`get_path \"$PWD/Renode.sln\"`" + BUILD_TYPE="mono" +fi + +OUT_BIN_DIR="$(get_path "output/bin/${CONFIGURATION}")" +BUILD_TYPE_FILE=$(get_path "${OUT_BIN_DIR}/build_type") + +# Verify Mono and mcs version on Linux and macOS +if ! $ON_WINDOWS && ! $NET +then + if ! [ -x "$(command -v mcs)" ] + then + MINIMUM_MONO=`get_min_mono_version` + echo "mcs not found. Renode requires Mono $MINIMUM_MONO or newer. Please refer to documentation for installation instructions. Exiting!" + exit 1 + fi + + verify_mono_version +fi + +# Copy properties file according to the running OS +mkdir -p "$OUTPUT_DIRECTORY" +if [ -n "${CUSTOM_PROP}" ]; then + PROP_FILE=$CUSTOM_PROP +else + if $ON_OSX + then + PROP_FILE="${CURRENT_PATH:=.}/src/Infrastructure/src/Emulator/Cores/osx-properties.csproj" + elif $ON_LINUX + then + PROP_FILE="${CURRENT_PATH:=.}/src/Infrastructure/src/Emulator/Cores/linux-properties.csproj" + else + PROP_FILE="${CURRENT_PATH:=.}/src/Infrastructure/src/Emulator/Cores/windows-properties.csproj" + fi +fi +cp "$PROP_FILE" "$OUTPUT_DIRECTORY/properties.csproj" + +if ! $NET +then + # Assets files are not deleted during `dotnet clean`, as it would confuse intellisense per comment in https://github.com/NuGet/Home/issues/7368#issuecomment-457411014, + # but we need to delete them to build Renode again for .NETFramework since `project.assets.json` doesn't play well if project files share the same directory. + # If `Renode_NET.sln` is picked for OmniSharp, it will trigger reanalysis of the project after removing assets files. + # We don't remove these files as part of `clean` target, because other intermediate files are well separated between .NET and .NETFramework + # and enforcing `clean` every time before rebuilding would slow down the build process on both frameworks. + find $ROOT_PATH -type f -name 'project.assets.json' -delete +fi + +CORES_PATH="$ROOT_PATH/src/Infrastructure/src/Emulator/Cores" + +# clean instead of building +if $CLEAN +then + for project_dir in $(find "$(get_path "${ROOT_PATH}/src")" -iname '*.csproj' -exec dirname '{}' \;) + do + for dir in {bin,obj}/{Debug,Release} + do + output_dir="$(get_path "${project_dir}/${dir}")" + if [[ -d "${output_dir}" ]] + then + echo "Removing: ${output_dir}" + rm -rf "${output_dir}" + fi + done + done + + # Manually clean the main output directory as it's location is non-standard + main_output_dir="$(get_path "${OUTPUT_DIRECTORY}/bin")" + if [[ -d "${main_output_dir}" ]] + then + echo "Removing: ${main_output_dir}" + rm -rf "${main_output_dir}" + fi + exit 0 +fi + +# Check if a full rebuild is needed +if [[ -f "$BUILD_TYPE_FILE" ]] +then + if [[ "$(cat "$BUILD_TYPE_FILE")" != "$BUILD_TYPE" ]] + then + echo "Attempted to build Renode in a different configuration than the previous build" + echo "Please run '$0 -c' to clean the previous build before continuing" + exit 1 + fi +fi + +# check weak implementations of core libraries +pushd "$ROOT_PATH/tools/building" > /dev/null +./check_weak_implementations.sh +popd > /dev/null + +PARAMS+=(p:Configuration=${CONFIGURATION}${BUILD_TARGET} p:GenerateFullPaths=true p:Platform="\"$BUILD_PLATFORM\"") + +# Paths for tlib +CORES_BUILD_PATH="$CORES_PATH/obj/$CONFIGURATION" +CORES_BIN_PATH="$CORES_PATH/bin/$CONFIGURATION" + +# Cmake generator, handled in their own variable since the names contain spaces +if $ON_WINDOWS +then + CMAKE_GEN="-GMinGW Makefiles" +else + CMAKE_GEN="-GUnix Makefiles" +fi + +# Macos architecture flags, to make rosetta work properly +if $ON_OSX +then + CMAKE_COMMON+=" -DCMAKE_OSX_ARCHITECTURES=x86_64" + if [ $HOST_ARCH == "aarch64" ]; then + CMAKE_COMMON+=" -DCMAKE_OSX_ARCHITECTURES=arm64" + fi +fi + +# This list contains all cores that will be built. +# If you are adding a new core or endianness add it here to have the correct tlib built +CORES=(arm.le arm.be arm64.le arm-m.le arm-m.be ppc.le ppc.be ppc64.le ppc64.be i386.le x86_64.le riscv.le riscv64.le sparc.le sparc.be xtensa.le) + +# if '--tlib-arch' was used - pick the first matching one +if [[ ! -z $TLIB_ARCH ]]; then + NONE_MATCHED=true + for potential_match in "${CORES[@]}"; do + if [[ $potential_match == "$TLIB_ARCH"* ]]; then + CORES=($potential_match) + echo "Compiling tlib for $potential_match" + NONE_MATCHED=false + break + fi + done + if $NONE_MATCHED ; then + echo "Failed to match any tlib arch" + exit 1 + fi +fi + +# build tlib +for core_config in "${CORES[@]}" +do + CORE="$(echo $core_config | cut -d '.' -f 1)" + ENDIAN="$(echo $core_config | cut -d '.' -f 2)" + BITS=32 + # Check if core is 64-bit + if [[ $CORE =~ "64" ]]; then + BITS=64 + fi + # Core specific flags to cmake + CMAKE_CONF_FLAGS="-DTARGET_ARCH=$CORE -DTARGET_WORD_SIZE=$BITS -DCMAKE_BUILD_TYPE=$CONFIGURATION" + CORE_DIR=$CORES_BUILD_PATH/$CORE/$ENDIAN + mkdir -p $CORE_DIR + pushd "$CORE_DIR" > /dev/null + if [[ $ENDIAN == "be" ]]; then + CMAKE_CONF_FLAGS+=" -DTARGET_BIG_ENDIAN=1" + fi + if [[ "$TLIB_EXPORT_COMPILE_COMMANDS" = true ]]; then + CMAKE_CONF_FLAGS+=" -DCMAKE_EXPORT_COMPILE_COMMANDS=1" + fi + cmake "$CMAKE_GEN" $CMAKE_COMMON $CMAKE_CONF_FLAGS -DHOST_ARCH=$HOST_ARCH $CORES_PATH + cmake --build . + CORE_BIN_DIR=$CORES_BIN_PATH/lib + mkdir -p $CORE_BIN_DIR + if $ON_OSX; then + # macos `cp` does not have the -u flag + cp -v tlib/*.so $CORE_BIN_DIR/ + else + cp -u -v tlib/*.so $CORE_BIN_DIR/ + fi + # copy compile_commands.json to tlib directory + if [[ "$TLIB_EXPORT_COMPILE_COMMANDS" = true ]]; then + command cp -v -f $CORE_DIR/compile_commands.json $CORES_PATH/tlib/ + fi + popd > /dev/null +done + +if $TLIB_ONLY +then + exit 0 +fi + +# build +eval "$CS_COMPILER $(build_args_helper "${PARAMS[@]}") $TARGET" +echo -n "$BUILD_TYPE" > "$BUILD_TYPE_FILE" + +# copy llvm library +LLVM_LIB="libllvm-disas" +if [[ $HOST_ARCH == "aarch64" ]]; then + # aarch64 host binaries have a different name + LLVM_LIB="libllvm-disas-aarch64" +fi +if [[ "${DETECTED_OS}" == "windows" ]]; then + LIB_EXT="dll" +elif [[ "${DETECTED_OS}" == "osx" ]]; then + LIB_EXT="dylib" +else + LIB_EXT="so" +fi +cp lib/resources/llvm/$LLVM_LIB.$LIB_EXT $OUT_BIN_DIR/libllvm-disas.$LIB_EXT + +# build packages after successful compilation +params="" + +if [ $CONFIGURATION == "Debug" ] +then + params="$params -d" +fi + +if [ -n "$EXPORT_DIRECTORY" ] +then + if [ "${DETECTED_OS}" != "linux" ] + then + echo "Custom output directory is currently available on Linux only" + exit 1 + fi + + $ROOT_PATH/tools/packaging/export_${DETECTED_OS}_workdir.sh $EXPORT_DIRECTORY $params + echo "Renode built to $EXPORT_DIRECTORY" +fi + +if $PACKAGES && $NIGHTLY +then + params="$params -n" +fi + +if $PACKAGES +then + if $NET + then + # dotnet package on linux uses a separate script + if $ON_LINUX + then + # maxcpucount:1 to avoid an error with multithreaded publish + eval "dotnet publish -maxcpucount:1 -f $TFM --self-contained false $(build_args_helper "${PARAMS[@]}") $TARGET" + export RID TFM + $ROOT_PATH/tools/packaging/make_linux_dotnet_package.sh $params + # Source package bundles nuget dependencies required for building the dotnet version of Renode + # so it can only be built when using dotnet. The generated package can also be used with Mono/.NETFramework + $ROOT_PATH/tools/packaging/make_source_package.sh $params + elif $ON_WINDOWS && ! $PORTABLE + then + # No Non portable dotnet package on windows yet + echo "Only portable dotnet packages are supported on windows. Rerun build.sh with -t flag to build portable" + exit 1 + elif $ON_OSX + then + echo "dotnet packages not supported on ${DETECTED_OS}" + exit 1 + fi + else + $ROOT_PATH/tools/packaging/make_${DETECTED_OS}_packages.sh $params + fi +fi + +if $PORTABLE +then + PARAMS+=(p:PORTABLE=true) + if $NET + then + # maxcpucount:1 to avoid an error with multithreaded publish + eval "dotnet publish -maxcpucount:1 -r $RID -f $TFM --self-contained true $(build_args_helper "${PARAMS[@]}") $TARGET" + export RID TFM + $ROOT_PATH/tools/packaging/make_${DETECTED_OS}_portable_dotnet.sh $params + else + if $ON_LINUX + then + $ROOT_PATH/tools/packaging/make_linux_portable.sh $params + else + echo "Portable packages for Mono are only available on Linux. Exiting!" + exit 1 + fi + fi +fi \ No newline at end of file From e66d7d72e01aee5bf900aa2ee5d7609d9f9654d6 Mon Sep 17 00:00:00 2001 From: memento Date: Wed, 29 Jan 2025 10:23:42 -0600 Subject: [PATCH 12/26] (ref) clean unix --- .../helpers/renode_build_with_cmake.ps1 | 13 +- .../helpers/renode_build_with_cmake.sh | 421 +----------------- 2 files changed, 25 insertions(+), 409 deletions(-) diff --git a/recipes/renode-cores/helpers/renode_build_with_cmake.ps1 b/recipes/renode-cores/helpers/renode_build_with_cmake.ps1 index 27bce34554522..a797c1d416db9 100644 --- a/recipes/renode-cores/helpers/renode_build_with_cmake.ps1 +++ b/recipes/renode-cores/helpers/renode_build_with_cmake.ps1 @@ -1,16 +1,7 @@ $ErrorActionPreference = "Stop" -$opts, $remainingArgs = $global:args | ForEach-Object { - switch -regex ($_) { - "-v"|"--no-gui"|"--net"|"--tlib-only" { - $_ - } - default { - Write-Host "Invalid argument: $_" - exit 1 - } - } -} +$ValidArgs = @("-v", "--no-gui", "--net", "--tlib-only") +$PassedArgs = $args.Where({$ValidArgs -contains $_}) $cpuCount = (Get-CimInstance Win32_Processor).NumberOfLogicalProcessors diff --git a/recipes/renode-cores/helpers/renode_build_with_cmake.sh b/recipes/renode-cores/helpers/renode_build_with_cmake.sh index e8b4c4954cb06..39358661546f8 100755 --- a/recipes/renode-cores/helpers/renode_build_with_cmake.sh +++ b/recipes/renode-cores/helpers/renode_build_with_cmake.sh @@ -4,147 +4,39 @@ set -u set -e export ROOT_PATH="$(cd $(dirname $0); echo $PWD)" -OUTPUT_DIRECTORY="$ROOT_PATH/output" -EXPORT_DIRECTORY="" -UPDATE_SUBMODULES=false CONFIGURATION="Release" -BUILD_PLATFORM="Any CPU" -CLEAN=false -PACKAGES=false -NIGHTLY=false -PORTABLE=false HEADLESS=false -SKIP_FETCH=false TLIB_ONLY=false -TLIB_EXPORT_COMPILE_COMMANDS=false -TLIB_ARCH="" NET=false -TFM="net8.0" -GENERATE_DOTNET_BUILD_TARGET=true -PARAMS=() -CUSTOM_PROP= -NET_FRAMEWORK_VER= -RID="linux-x64" HOST_ARCH="i386" -# Common cmake flags CMAKE_COMMON="" function print_help() { echo "Usage: $0 [-cdvspnt] [-b properties-file.csproj] [--no-gui] [--skip-fetch] [--profile-build] [--tlib-only] [--tlib-export-compile-commands] [--tlib-arch ] [--host-arch i386|aarch64] [-- ]" echo - echo "-c clean instead of building" - echo "-d build Debug configuration" - echo "-v verbose output" - echo "-p create packages after building" - echo "-n create nightly packages after building" - echo "-t create a portable package (experimental, Linux only)" - echo "-s update submodules" - echo "-b custom build properties file" - echo "-o custom output directory" - echo "--skip-fetch skip fetching submodules and additional resources" echo "--no-gui build with GUI disabled" - echo "--force-net-framework-version build against different version of .NET Framework than specified in the solution" echo "--net build with dotnet" - echo "-B bundle target runtime (default value: $RID, requires --net, -t)" - echo "-F select the target framework for which Renode should be built (default value: $TFM)" - echo "--profile-build build optimized for profiling" echo "--tlib-only only build tlib" - echo "--tlib-arch build only single arch (implies --tlib-only)" - echo "--tlib-export-compile-commands build tlibs with 'compile_commands.json' (requires --tlib-arch)" - echo "--host-arch build with a specific tcg host architecture (default: i386)" - echo "--skip-dotnet-target-generation don't generate 'Directory.Build.targets' file, useful when experimenting with different build settings" echo " arguments to pass to the build system" } -while getopts "cdvpnstb:o:B:F:a:-:" opt +while getopts "vnstb:o:B:F:a:-:" opt do case $opt in - c) - CLEAN=true - ;; - d) - CONFIGURATION="Debug" - ;; - v) - PARAMS+=(verbosity:detailed) - ;; - p) - PACKAGES=true - ;; - n) - NIGHTLY=true - PACKAGES=true - ;; - t) - PORTABLE=true - ;; - s) - UPDATE_SUBMODULES=true - ;; - b) - CUSTOM_PROP=$OPTARG - ;; - o) - EXPORT_DIRECTORY=$OPTARG - echo "Setting the output directory to $EXPORT_DIRECTORY" - ;; - B) - RID=$OPTARG - ;; - F) - if ! $NET; then - echo "-F requires --net being set" - exit 1 - fi - TFM=$OPTARG - ;; -) case $OPTARG in "no-gui") HEADLESS=true ;; - "skip-fetch") - SKIP_FETCH=true - ;; - "force-net-framework-version") - shift $((OPTIND-1)) - NET_FRAMEWORK_VER=p:TargetFrameworkVersion=v$1 - PARAMS+=($NET_FRAMEWORK_VER) - OPTIND=2 - ;; "net") NET=true - PARAMS+=(p:NET=true) - ;; - "profile-build") - CMAKE_COMMON="-DPROFILING_BUILD=ON" - ;; - "tlib-only") - TLIB_ONLY=true - ;; - "tlib-arch") - # This only makes sense with '--tlib-only' set; it might as well imply it - TLIB_ONLY=true - shift $((OPTIND-1)) - TLIB_ARCH=$1 - OPTIND=2 - ;; - "tlib-export-compile-commands") - if [ -z $TLIB_ARCH ]; then - echo "--tlib-export-compile-commands requires --tlib-arch begin set" - exit 1 - fi - TLIB_EXPORT_COMPILE_COMMANDS=true ;; "host-arch") shift $((OPTIND-1)) HOST_ARCH=$1 OPTIND=2 ;; - "skip-dotnet-target-generation") - GENERATE_DOTNET_BUILD_TARGET=false - ;; *) print_help exit 1 @@ -158,14 +50,6 @@ do esac done shift "$((OPTIND-1))" -PARAMS+=( - # By default use CC as Compiler- and LinkerPath, and AR as ArPath - ${CC:+"p:CompilerPath=$CC"} - ${CC:+"p:LinkerPath=$CC"} - ${AR:+"p:ArPath=$AR"} - # But allow users to override it - "$@" -) if [ -n "${PLATFORM:-}" ] then @@ -180,188 +64,26 @@ then exit 1 fi -# We can only update parts of this repository if Renode is built from within the git tree -if [ ! -e .git ] -then - SKIP_FETCH=true - UPDATE_SUBMODULES=false -fi - -if $SKIP_FETCH -then - echo "Skipping init/update of submodules" -else - # Update submodules if not initialized or if requested by the user - # Warn if not updating, but unclean - # Disabling -e to allow grep to fail - set +e - git submodule status --recursive | grep -q "^-" - SUBMODULES_NOT_INITED=$? - - git submodule status --recursive | grep -q "^+" - SUBMODULES_NOT_CLEAN=$? - set -e - if $UPDATE_SUBMODULES || [ $SUBMODULES_NOT_INITED -eq 0 ] - then - echo "Updating submodules..." - git submodule update --init --recursive - elif [ $SUBMODULES_NOT_CLEAN -eq 0 ] - then - echo "Submodules are not updated. Use -s to force update." - fi -fi - -. "${ROOT_PATH}/tools/common.sh" - -if $SKIP_FETCH -then - echo "Skipping library fetch" -else - "${ROOT_PATH}"/tools/building/fetch_libraries.sh -fi - if $HEADLESS then BUILD_TARGET=Headless - PARAMS+=(p:GUI_DISABLED=true) -elif $ON_WINDOWS -then - BUILD_TARGET=Windows - TFM="$TFM-windows10.0.17763.0" - RID="win-x64" -else - BUILD_TARGET=Mono -fi - -if [[ $GENERATE_DOTNET_BUILD_TARGET = true ]]; then - if $ON_WINDOWS; then - # CsWinRTAotOptimizerEnabled is disabled due to a bug in dotnet-sdk. - # See: https://github.com/dotnet/sdk/issues/44026 - OS_SPECIFIC_TARGET_OPTS='false' - fi - -cat < "$(get_path "$PWD/Directory.Build.targets")" - - - $TFM - ${OS_SPECIFIC_TARGET_OPTS:+${OS_SPECIFIC_TARGET_OPTS}} - - -EOF - -fi - -if $NET -then - export DOTNET_CLI_TELEMETRY_OPTOUT=1 - CS_COMPILER="dotnet build" - TARGET="`get_path \"$PWD/Renode_NET.sln\"`" - BUILD_TYPE="dotnet" -else - TARGET="`get_path \"$PWD/Renode.sln\"`" - BUILD_TYPE="mono" fi OUT_BIN_DIR="$(get_path "output/bin/${CONFIGURATION}")" BUILD_TYPE_FILE=$(get_path "${OUT_BIN_DIR}/build_type") -# Verify Mono and mcs version on Linux and macOS -if ! $ON_WINDOWS && ! $NET -then - if ! [ -x "$(command -v mcs)" ] - then - MINIMUM_MONO=`get_min_mono_version` - echo "mcs not found. Renode requires Mono $MINIMUM_MONO or newer. Please refer to documentation for installation instructions. Exiting!" - exit 1 - fi - - verify_mono_version -fi - -# Copy properties file according to the running OS -mkdir -p "$OUTPUT_DIRECTORY" -if [ -n "${CUSTOM_PROP}" ]; then - PROP_FILE=$CUSTOM_PROP -else - if $ON_OSX - then - PROP_FILE="${CURRENT_PATH:=.}/src/Infrastructure/src/Emulator/Cores/osx-properties.csproj" - elif $ON_LINUX - then - PROP_FILE="${CURRENT_PATH:=.}/src/Infrastructure/src/Emulator/Cores/linux-properties.csproj" - else - PROP_FILE="${CURRENT_PATH:=.}/src/Infrastructure/src/Emulator/Cores/windows-properties.csproj" - fi -fi -cp "$PROP_FILE" "$OUTPUT_DIRECTORY/properties.csproj" - -if ! $NET -then - # Assets files are not deleted during `dotnet clean`, as it would confuse intellisense per comment in https://github.com/NuGet/Home/issues/7368#issuecomment-457411014, - # but we need to delete them to build Renode again for .NETFramework since `project.assets.json` doesn't play well if project files share the same directory. - # If `Renode_NET.sln` is picked for OmniSharp, it will trigger reanalysis of the project after removing assets files. - # We don't remove these files as part of `clean` target, because other intermediate files are well separated between .NET and .NETFramework - # and enforcing `clean` every time before rebuilding would slow down the build process on both frameworks. - find $ROOT_PATH -type f -name 'project.assets.json' -delete -fi - CORES_PATH="$ROOT_PATH/src/Infrastructure/src/Emulator/Cores" -# clean instead of building -if $CLEAN -then - for project_dir in $(find "$(get_path "${ROOT_PATH}/src")" -iname '*.csproj' -exec dirname '{}' \;) - do - for dir in {bin,obj}/{Debug,Release} - do - output_dir="$(get_path "${project_dir}/${dir}")" - if [[ -d "${output_dir}" ]] - then - echo "Removing: ${output_dir}" - rm -rf "${output_dir}" - fi - done - done - - # Manually clean the main output directory as it's location is non-standard - main_output_dir="$(get_path "${OUTPUT_DIRECTORY}/bin")" - if [[ -d "${main_output_dir}" ]] - then - echo "Removing: ${main_output_dir}" - rm -rf "${main_output_dir}" - fi - exit 0 -fi - -# Check if a full rebuild is needed -if [[ -f "$BUILD_TYPE_FILE" ]] -then - if [[ "$(cat "$BUILD_TYPE_FILE")" != "$BUILD_TYPE" ]] - then - echo "Attempted to build Renode in a different configuration than the previous build" - echo "Please run '$0 -c' to clean the previous build before continuing" - exit 1 - fi -fi - # check weak implementations of core libraries pushd "$ROOT_PATH/tools/building" > /dev/null -./check_weak_implementations.sh + ./check_weak_implementations.sh popd > /dev/null -PARAMS+=(p:Configuration=${CONFIGURATION}${BUILD_TARGET} p:GenerateFullPaths=true p:Platform="\"$BUILD_PLATFORM\"") - # Paths for tlib CORES_BUILD_PATH="$CORES_PATH/obj/$CONFIGURATION" CORES_BIN_PATH="$CORES_PATH/bin/$CONFIGURATION" -# Cmake generator, handled in their own variable since the names contain spaces -if $ON_WINDOWS -then - CMAKE_GEN="-GMinGW Makefiles" -else - CMAKE_GEN="-GUnix Makefiles" -fi +CMAKE_GEN="-GUnix Makefiles" # Macos architecture flags, to make rosetta work properly if $ON_OSX @@ -406,125 +128,28 @@ do # Core specific flags to cmake CMAKE_CONF_FLAGS="-DTARGET_ARCH=$CORE -DTARGET_WORD_SIZE=$BITS -DCMAKE_BUILD_TYPE=$CONFIGURATION" CORE_DIR=$CORES_BUILD_PATH/$CORE/$ENDIAN + mkdir -p $CORE_DIR pushd "$CORE_DIR" > /dev/null - if [[ $ENDIAN == "be" ]]; then - CMAKE_CONF_FLAGS+=" -DTARGET_BIG_ENDIAN=1" - fi - if [[ "$TLIB_EXPORT_COMPILE_COMMANDS" = true ]]; then - CMAKE_CONF_FLAGS+=" -DCMAKE_EXPORT_COMPILE_COMMANDS=1" - fi - cmake "$CMAKE_GEN" $CMAKE_COMMON $CMAKE_CONF_FLAGS -DHOST_ARCH=$HOST_ARCH $CORES_PATH - cmake --build . - CORE_BIN_DIR=$CORES_BIN_PATH/lib - mkdir -p $CORE_BIN_DIR - if $ON_OSX; then - # macos `cp` does not have the -u flag - cp -v tlib/*.so $CORE_BIN_DIR/ - else - cp -u -v tlib/*.so $CORE_BIN_DIR/ - fi - # copy compile_commands.json to tlib directory - if [[ "$TLIB_EXPORT_COMPILE_COMMANDS" = true ]]; then - command cp -v -f $CORE_DIR/compile_commands.json $CORES_PATH/tlib/ - fi - popd > /dev/null -done - -if $TLIB_ONLY -then - exit 0 -fi - -# build -eval "$CS_COMPILER $(build_args_helper "${PARAMS[@]}") $TARGET" -echo -n "$BUILD_TYPE" > "$BUILD_TYPE_FILE" - -# copy llvm library -LLVM_LIB="libllvm-disas" -if [[ $HOST_ARCH == "aarch64" ]]; then - # aarch64 host binaries have a different name - LLVM_LIB="libllvm-disas-aarch64" -fi -if [[ "${DETECTED_OS}" == "windows" ]]; then - LIB_EXT="dll" -elif [[ "${DETECTED_OS}" == "osx" ]]; then - LIB_EXT="dylib" -else - LIB_EXT="so" -fi -cp lib/resources/llvm/$LLVM_LIB.$LIB_EXT $OUT_BIN_DIR/libllvm-disas.$LIB_EXT - -# build packages after successful compilation -params="" - -if [ $CONFIGURATION == "Debug" ] -then - params="$params -d" -fi - -if [ -n "$EXPORT_DIRECTORY" ] -then - if [ "${DETECTED_OS}" != "linux" ] - then - echo "Custom output directory is currently available on Linux only" - exit 1 - fi - - $ROOT_PATH/tools/packaging/export_${DETECTED_OS}_workdir.sh $EXPORT_DIRECTORY $params - echo "Renode built to $EXPORT_DIRECTORY" -fi + if [[ $ENDIAN == "be" ]]; then + CMAKE_CONF_FLAGS+=" -DTARGET_BIG_ENDIAN=1" + fi + if [[ "$TLIB_EXPORT_COMPILE_COMMANDS" = true ]]; then + CMAKE_CONF_FLAGS+=" -DCMAKE_EXPORT_COMPILE_COMMANDS=1" + fi -if $PACKAGES && $NIGHTLY -then - params="$params -n" -fi + cmake "$CMAKE_GEN" $CMAKE_COMMON $CMAKE_CONF_FLAGS -DHOST_ARCH=$HOST_ARCH $CORES_PATH + cmake --build . -if $PACKAGES -then - if $NET - then - # dotnet package on linux uses a separate script - if $ON_LINUX - then - # maxcpucount:1 to avoid an error with multithreaded publish - eval "dotnet publish -maxcpucount:1 -f $TFM --self-contained false $(build_args_helper "${PARAMS[@]}") $TARGET" - export RID TFM - $ROOT_PATH/tools/packaging/make_linux_dotnet_package.sh $params - # Source package bundles nuget dependencies required for building the dotnet version of Renode - # so it can only be built when using dotnet. The generated package can also be used with Mono/.NETFramework - $ROOT_PATH/tools/packaging/make_source_package.sh $params - elif $ON_WINDOWS && ! $PORTABLE - then - # No Non portable dotnet package on windows yet - echo "Only portable dotnet packages are supported on windows. Rerun build.sh with -t flag to build portable" - exit 1 - elif $ON_OSX - then - echo "dotnet packages not supported on ${DETECTED_OS}" - exit 1 - fi - else - $ROOT_PATH/tools/packaging/make_${DETECTED_OS}_packages.sh $params - fi -fi + CORE_BIN_DIR=$CORES_BIN_PATH/lib + mkdir -p $CORE_BIN_DIR + if $ON_OSX; then + # macos `cp` does not have the -u flag + cp -v tlib/*.so $CORE_BIN_DIR/ + else + cp -u -v tlib/*.so $CORE_BIN_DIR/ + fi + popd > /dev/null +done -if $PORTABLE -then - PARAMS+=(p:PORTABLE=true) - if $NET - then - # maxcpucount:1 to avoid an error with multithreaded publish - eval "dotnet publish -maxcpucount:1 -r $RID -f $TFM --self-contained true $(build_args_helper "${PARAMS[@]}") $TARGET" - export RID TFM - $ROOT_PATH/tools/packaging/make_${DETECTED_OS}_portable_dotnet.sh $params - else - if $ON_LINUX - then - $ROOT_PATH/tools/packaging/make_linux_portable.sh $params - else - echo "Portable packages for Mono are only available on Linux. Exiting!" - exit 1 - fi - fi -fi \ No newline at end of file +exit 0 From 309d872c70c386a9c88c62563870c87d5eaba3ee Mon Sep 17 00:00:00 2001 From: memento Date: Wed, 29 Jan 2025 10:26:46 -0600 Subject: [PATCH 13/26] (fix) call 'cleaned-out' function --- recipes/renode-cores/helpers/renode_build_with_cmake.ps1 | 1 - 1 file changed, 1 deletion(-) diff --git a/recipes/renode-cores/helpers/renode_build_with_cmake.ps1 b/recipes/renode-cores/helpers/renode_build_with_cmake.ps1 index a797c1d416db9..7cb7d15eca272 100644 --- a/recipes/renode-cores/helpers/renode_build_with_cmake.ps1 +++ b/recipes/renode-cores/helpers/renode_build_with_cmake.ps1 @@ -27,7 +27,6 @@ function print_help { Write-Host " arguments to pass to the build system" } -$opts = Get-CommandLineArgs while ($opts.Count -gt 0) { $opt = $opts[0] switch -regex ($opt) { From 35e9924b409a6a250ce8c26837c24a175cc8faf9 Mon Sep 17 00:00:00 2001 From: memento Date: Wed, 29 Jan 2025 10:42:21 -0600 Subject: [PATCH 14/26] (fix) unix script args. permissions on non-unix --- recipes/renode-cores/build.bat | 1 + .../helpers/renode_build_with_cmake.sh | 52 ++++++++++--------- 2 files changed, 29 insertions(+), 24 deletions(-) diff --git a/recipes/renode-cores/build.bat b/recipes/renode-cores/build.bat index cdc1a3828113e..3d20e75e9be92 100644 --- a/recipes/renode-cores/build.bat +++ b/recipes/renode-cores/build.bat @@ -16,6 +16,7 @@ set "CORES_PATH=%SRC_DIR%\src\Infrastructure\src\Emulator\Cores" set "CORES_BIN_PATH=%CORES_PATH%\bin\%CONFIGURATION%" mkdir "%PREFIX%\Library\lib\%PKG_NAME%" +icacls "%PREFIX%\Library\lib\%PKG_NAME%" /grant Users:(OI)(CI)F /T robocopy "%CORES_BIN_PATH%\lib" "%PREFIX%\Library\lib\%PKG_NAME%" /E /COPY:DATSO if %errorlevel% neq 0 exit /b %errorlevel% diff --git a/recipes/renode-cores/helpers/renode_build_with_cmake.sh b/recipes/renode-cores/helpers/renode_build_with_cmake.sh index 39358661546f8..face11ca50647 100755 --- a/recipes/renode-cores/helpers/renode_build_with_cmake.sh +++ b/recipes/renode-cores/helpers/renode_build_with_cmake.sh @@ -13,43 +13,47 @@ HOST_ARCH="i386" CMAKE_COMMON="" function print_help() { - echo "Usage: $0 [-cdvspnt] [-b properties-file.csproj] [--no-gui] [--skip-fetch] [--profile-build] [--tlib-only] [--tlib-export-compile-commands] [--tlib-arch ] [--host-arch i386|aarch64] [-- ]" + echo "Usage: $0 [--no-gui] [--net] [--tlib-only] [--host-arch i386|aarch64] [-- ]" echo echo "--no-gui build with GUI disabled" echo "--net build with dotnet" echo "--tlib-only only build tlib" + echo "--host-arch specify host architecture (i386 or aarch64)" echo " arguments to pass to the build system" } -while getopts "vnstb:o:B:F:a:-:" opt -do - case $opt in - -) - case $OPTARG in - "no-gui") - HEADLESS=true - ;; - "net") - NET=true - ;; - "host-arch") - shift $((OPTIND-1)) - HOST_ARCH=$1 - OPTIND=2 - ;; - *) - print_help - exit 1 - ;; - esac +OPTIONS=$(getopt -o vhnt: -l "no-gui,net,tlib-only,host-arch:" -n "$0" -- "$@") +eval set -- "$OPTIONS" + +while true; do + case $1 in + --no-gui) + HEADLESS=true + shift + ;; + --net) + NET=true + shift + ;; + --tlib-only) + TLIB_ONLY=true + shift + ;; + --host-arch) + shift + HOST_ARCH=$1 + shift + ;; + --) + shift + break ;; - \?) + *) print_help exit 1 ;; esac done -shift "$((OPTIND-1))" if [ -n "${PLATFORM:-}" ] then From 4606fb7da8f8575e5fab6e6fa102a29a578d2bff Mon Sep 17 00:00:00 2001 From: memento Date: Wed, 29 Jan 2025 11:24:37 -0600 Subject: [PATCH 15/26] (fix) unix typos. ppc64 not on win? --- recipes/renode-cores/build.bat | 1 - .../helpers/renode_build_with_cmake.ps1 | 12 +++--- .../helpers/renode_build_with_cmake.sh | 41 ++++--------------- recipes/renode-cores/recipe.yaml | 35 ++++++++-------- 4 files changed, 30 insertions(+), 59 deletions(-) diff --git a/recipes/renode-cores/build.bat b/recipes/renode-cores/build.bat index 3d20e75e9be92..97c39cc5adf4c 100644 --- a/recipes/renode-cores/build.bat +++ b/recipes/renode-cores/build.bat @@ -18,6 +18,5 @@ set "CORES_BIN_PATH=%CORES_PATH%\bin\%CONFIGURATION%" mkdir "%PREFIX%\Library\lib\%PKG_NAME%" icacls "%PREFIX%\Library\lib\%PKG_NAME%" /grant Users:(OI)(CI)F /T robocopy "%CORES_BIN_PATH%\lib" "%PREFIX%\Library\lib\%PKG_NAME%" /E /COPY:DATSO -if %errorlevel% neq 0 exit /b %errorlevel% endlocal diff --git a/recipes/renode-cores/helpers/renode_build_with_cmake.ps1 b/recipes/renode-cores/helpers/renode_build_with_cmake.ps1 index 7cb7d15eca272..4e9781940b794 100644 --- a/recipes/renode-cores/helpers/renode_build_with_cmake.ps1 +++ b/recipes/renode-cores/helpers/renode_build_with_cmake.ps1 @@ -6,7 +6,7 @@ $PassedArgs = $args.Where({$ValidArgs -contains $_}) $cpuCount = (Get-CimInstance Win32_Processor).NumberOfLogicalProcessors $env:PATH = "${env:BUILD_PREFIX}/Library/mingw-w64/bin;${env:BUILD_PREFIX}/Library/bin;${env:PREFIX}/Library/bin;${env:PREFIX}/bin;${env:PATH}" -$env:ROOT_PATH = $env:SRC_DIR +$env:SRC_DIR = $env:SRC_DIR $CMAKE = (Get-Command cmake).Source @@ -68,12 +68,9 @@ if ($HEADLESS) { $BUILD_TARGET = "Headless" } -$OUT_BIN_DIR = Join-Path -Path "output\bin" -ChildPath $CONFIGURATION -$BUILD_TYPE_FILE = Join-Path -Path $OUT_BIN_DIR -ChildPath "build_type" +$CORES_PATH = Join-Path -Path $env:SRC_DIR -ChildPath "src\Infrastructure\src\Emulator\Cores" -$CORES_PATH = Join-Path -Path $env:ROOT_PATH -ChildPath "src\Infrastructure\src\Emulator\Cores" - -Push-Location "$env:ROOT_PATH\tools\building" +Push-Location "$env:SRC_DIR\tools\building" bash .\check_weak_implementations.sh Pop-Location @@ -94,7 +91,8 @@ function Update-CMakeLists { } Update-CMakeLists "$CORES_PATH\tlib\CMakeLists.txt" "-fPIC" "-Wno-unused-function" -Update-CMakeLists "$CORES_PATH\tlib\softload-3\CMakeLists.txt" "-fPIC" "" +# Not in this older 1.15.3 version (in master) +# Update-CMakeLists "$CORES_PATH\tlib\softload-3\CMakeLists.txt" "-fPIC" "" Update-CMakeLists "$CORES_PATH\tlib\tcg\CMakeLists.txt" "-fPIC" "-Wno-unused-function" foreach ($core_config in $CORES) { diff --git a/recipes/renode-cores/helpers/renode_build_with_cmake.sh b/recipes/renode-cores/helpers/renode_build_with_cmake.sh index face11ca50647..7bc46311260f4 100755 --- a/recipes/renode-cores/helpers/renode_build_with_cmake.sh +++ b/recipes/renode-cores/helpers/renode_build_with_cmake.sh @@ -3,8 +3,6 @@ set -u set -e -export ROOT_PATH="$(cd $(dirname $0); echo $PWD)" - CONFIGURATION="Release" HEADLESS=false TLIB_ONLY=false @@ -73,52 +71,30 @@ then BUILD_TARGET=Headless fi -OUT_BIN_DIR="$(get_path "output/bin/${CONFIGURATION}")" -BUILD_TYPE_FILE=$(get_path "${OUT_BIN_DIR}/build_type") - -CORES_PATH="$ROOT_PATH/src/Infrastructure/src/Emulator/Cores" - # check weak implementations of core libraries -pushd "$ROOT_PATH/tools/building" > /dev/null +pushd "${SRC_DIR}/tools/building" > /dev/null ./check_weak_implementations.sh popd > /dev/null # Paths for tlib +CORES_PATH="${SRC_DIR}/src/Infrastructure/src/Emulator/Cores" CORES_BUILD_PATH="$CORES_PATH/obj/$CONFIGURATION" CORES_BIN_PATH="$CORES_PATH/bin/$CONFIGURATION" CMAKE_GEN="-GUnix Makefiles" # Macos architecture flags, to make rosetta work properly -if $ON_OSX -then +if [[ "${target_platform}" == "osx-64" ]]; then CMAKE_COMMON+=" -DCMAKE_OSX_ARCHITECTURES=x86_64" - if [ $HOST_ARCH == "aarch64" ]; then - CMAKE_COMMON+=" -DCMAKE_OSX_ARCHITECTURES=arm64" - fi +fi +if [[ "${target_platform}" == "osx-arm64" ]]; then + CMAKE_COMMON+=" -DCMAKE_OSX_ARCHITECTURES=arm64" fi # This list contains all cores that will be built. # If you are adding a new core or endianness add it here to have the correct tlib built CORES=(arm.le arm.be arm64.le arm-m.le arm-m.be ppc.le ppc.be ppc64.le ppc64.be i386.le x86_64.le riscv.le riscv64.le sparc.le sparc.be xtensa.le) -# if '--tlib-arch' was used - pick the first matching one -if [[ ! -z $TLIB_ARCH ]]; then - NONE_MATCHED=true - for potential_match in "${CORES[@]}"; do - if [[ $potential_match == "$TLIB_ARCH"* ]]; then - CORES=($potential_match) - echo "Compiling tlib for $potential_match" - NONE_MATCHED=false - break - fi - done - if $NONE_MATCHED ; then - echo "Failed to match any tlib arch" - exit 1 - fi -fi - # build tlib for core_config in "${CORES[@]}" do @@ -138,16 +114,13 @@ do if [[ $ENDIAN == "be" ]]; then CMAKE_CONF_FLAGS+=" -DTARGET_BIG_ENDIAN=1" fi - if [[ "$TLIB_EXPORT_COMPILE_COMMANDS" = true ]]; then - CMAKE_CONF_FLAGS+=" -DCMAKE_EXPORT_COMPILE_COMMANDS=1" - fi cmake "$CMAKE_GEN" $CMAKE_COMMON $CMAKE_CONF_FLAGS -DHOST_ARCH=$HOST_ARCH $CORES_PATH cmake --build . CORE_BIN_DIR=$CORES_BIN_PATH/lib mkdir -p $CORE_BIN_DIR - if $ON_OSX; then + if [[ "${target_platform}" == "osx-"* ]]; then # macos `cp` does not have the -u flag cp -v tlib/*.so $CORE_BIN_DIR/ else diff --git a/recipes/renode-cores/recipe.yaml b/recipes/renode-cores/recipe.yaml index 2a6003090f2e5..5d96d64f3280b 100644 --- a/recipes/renode-cores/recipe.yaml +++ b/recipes/renode-cores/recipe.yaml @@ -40,23 +40,24 @@ requirements: tests: - package_contents: files: - - ${{ "LIBRARY/" if not unix }}lib/renode-cores/translate-xtensa-le.so - - ${{ "LIBRARY/" if not unix }}lib/renode-cores/translate-arm-be.so - - ${{ "LIBRARY/" if not unix }}lib/renode-cores/translate-arm-le.so - - ${{ "LIBRARY/" if not unix }}lib/renode-cores/translate-arm-m-be.so - - ${{ "LIBRARY/" if not unix }}lib/renode-cores/translate-arm-m-le.so - - ${{ "LIBRARY/" if not unix }}lib/renode-cores/translate-arm64-le.so - - ${{ "LIBRARY/" if not unix }}lib/renode-cores/translate-i386-le.so - - ${{ "LIBRARY/" if not unix }}lib/renode-cores/translate-ppc-be.so - - ${{ "LIBRARY/" if not unix }}lib/renode-cores/translate-ppc-le.so - - ${{ "LIBRARY/" if not unix }}lib/renode-cores/translate-ppc64-be.so - - ${{ "LIBRARY/" if not unix }}lib/renode-cores/translate-ppc64-le.so - - ${{ "LIBRARY/" if not unix }}lib/renode-cores/translate-riscv-le.so - - ${{ "LIBRARY/" if not unix }}lib/renode-cores/translate-riscv64-le.so - - ${{ "LIBRARY/" if not unix }}lib/renode-cores/translate-sparc-be.so - - ${{ "LIBRARY/" if not unix }}lib/renode-cores/translate-sparc-le.so - - ${{ "LIBRARY/" if not unix }}lib/renode-cores/translate-x86_64-le.so - - ${{ "LIBRARY/" if not unix }}lib/renode-cores/translate-xtensa-le.so + - ${{ "Library/" if not unix }}lib/renode-cores/translate-arm-be.so + - ${{ "Library/" if not unix }}lib/renode-cores/translate-arm-le.so + - ${{ "Library/" if not unix }}lib/renode-cores/translate-arm-m-be.so + - ${{ "Library/" if not unix }}lib/renode-cores/translate-arm-m-le.so + - ${{ "Library/" if not unix }}lib/renode-cores/translate-arm64-le.so + - ${{ "Library/" if not unix }}lib/renode-cores/translate-i386-le.so + - ${{ "Library/" if not unix }}lib/renode-cores/translate-ppc-be.so + - ${{ "Library/" if not unix }}lib/renode-cores/translate-ppc-le.so + - ${{ "Library/" if not unix }}lib/renode-cores/translate-riscv-le.so + - ${{ "Library/" if not unix }}lib/renode-cores/translate-riscv64-le.so + - ${{ "Library/" if not unix }}lib/renode-cores/translate-sparc-be.so + - ${{ "Library/" if not unix }}lib/renode-cores/translate-sparc-le.so + - ${{ "Library/" if not unix }}lib/renode-cores/translate-x86_64-le.so + - ${{ "Library/" if not unix }}lib/renode-cores/translate-xtensa-le.so + - if: unix + then: + - ${{ "Library/" if not unix }}lib/renode-cores/translate-ppc64-be.so + - ${{ "Library/" if not unix }}lib/renode-cores/translate-ppc64-le.so about: homepage: https://github.com/renode/renode From 413f1f9c8c2bd022b5575c137c91aa1c58c0a7c7 Mon Sep 17 00:00:00 2001 From: memento Date: Wed, 29 Jan 2025 12:28:28 -0600 Subject: [PATCH 16/26] (fix) tests fail? --- recipes/renode-cli/build.sh | 17 +- .../helpers/renode_build_with_dotnet.sh | 187 ++++++++++++++++++ .../renode-cli/patches/Cores-CMakeLists.txt | 39 ---- recipes/renode-cli/recipe.yaml | 4 +- .../helpers/renode_build_with_cmake.ps1 | 0 5 files changed, 193 insertions(+), 54 deletions(-) create mode 100755 recipes/renode-cli/helpers/renode_build_with_dotnet.sh delete mode 100644 recipes/renode-cli/patches/Cores-CMakeLists.txt mode change 100644 => 100755 recipes/renode-cores/helpers/renode_build_with_cmake.ps1 diff --git a/recipes/renode-cli/build.sh b/recipes/renode-cli/build.sh index abc7dfbfb8113..3a9e095c98956 100644 --- a/recipes/renode-cli/build.sh +++ b/recipes/renode-cli/build.sh @@ -11,9 +11,7 @@ install_prefix="${PREFIX}/opt/${PKG_NAME}" dotnet_version=$(dotnet --version) framework_version=${dotnet_version%.*} -# Update the submodule to the latest commit CMakeLists.txt -cp ${RECIPE_DIR}/patches/Cores-CMakeLists.txt ${SRC_DIR}/src/Infrastructure/src/Emulator/Cores/CMakeLists.txt - +# Patch the project files to use the correct .NET version find lib src tests -name "*.csproj" -exec sed -i -E \ -e "s/([>;])net6.0([<;])/\1net${framework_version}\2/" \ -e "s|^((\s+))|\1\n\2\2CS0168;CS0219;CS8981;SYSLIB0050;SYSLIB0051|" \ @@ -23,23 +21,16 @@ find . -type d -name "obj" -exec rm -rf {} + find . -type d -name "bin" -exec rm -rf {} + sed -i -E 's/(ReleaseHeadless\|Any .+ = )Debug/\1Release/' Renode_NET.sln -# export CC=${CC} -# export CFLAGS="${CFLAGS} -fPIC" - # Prevent CMake build since we provide the binaries -sed -i -E 's;^(\s*)(cmake|\./check_weak_implementations|cp\s+(\-u\s+)?\-v\s+tlib/\*\.so);\1true \|\| \2;' build.sh mkdir -p ${SRC_DIR}/src/Infrastructure/src/Emulator/Cores/bin/Release/lib cp ${BUILD_PREFIX}/lib/renode-cores/* ${SRC_DIR}/src/Infrastructure/src/Emulator/Cores/bin/Release/lib rm -f ${SRC_DIR}/src/Infrastructure/src/Emulator/Cores/translate*.cproj if [[ "${target_platform}" == linux-* ]] || [[ "${target_platform}" == osx-* ]]; then - _os_name=${target_platform%-*} - chmod +x build.sh tools/{building,packaging}/*.sh - ./build.sh --net --no-gui --force-net-framework-version ${framework_version} + chmod +x tools/{building,packaging}/*.sh + ${RECIPE_DIR}/helpers/renode_build_with_dotnet.sh --net --no-gui --force-net-framework-version ${framework_version} else - _os_name=windows - chmod +x build.sh tools/{building,packaging}/*.sh - ./build.sh --net --no-gui --force-net-framework-version ${framework_version} + ${RECIPE_DIR}/helpers/renode_build_with_dotnet.ps1 --net --no-gui --force-net-framework-version ${framework_version} fi # Install procedure diff --git a/recipes/renode-cli/helpers/renode_build_with_dotnet.sh b/recipes/renode-cli/helpers/renode_build_with_dotnet.sh new file mode 100755 index 0000000000000..433a9c4e8772a --- /dev/null +++ b/recipes/renode-cli/helpers/renode_build_with_dotnet.sh @@ -0,0 +1,187 @@ +#!/usr/bin/env bash + +set -u +set -e + +OUTPUT_DIRECTORY="${SRC_DIR}/output" + +UPDATE_SUBMODULES=false +CONFIGURATION="Release" +HEADLESS=false +NET=false +TFM="net8.0" +GENERATE_DOTNET_BUILD_TARGET=true +PARAMS=() +NET_FRAMEWORK_VER= +RID="linux-x64" +HOST_ARCH="i386" +# Common cmake flags +CMAKE_COMMON="" + +function print_help() { + echo "Usage: $0 [--no-gui] [--net] [--force-net-framework-version] [--host-arch i386|aarch64] [-- ]" + echo + echo "--no-gui build with GUI disabled" + echo "--force-net-framework-version build against different version of .NET Framework than specified in the solution" + echo "--net build with dotnet" + echo "--host-arch build with a specific tcg host architecture (default: i386)" + echo " arguments to pass to the build system" +} + +OPTIONS=$(getopt -o vhnt: -l "no-gui,net,tlib-only,host-arch:" -n "$0" -- "$@") +eval set -- "$OPTIONS" + +while true; do + case $1 in + --no-gui) + HEADLESS=true + shift + ;; + --net) + NET=true + shift + ;; + --host-arch) + shift + HOST_ARCH=$1 + shift + ;; + --force-net-framework-version) + shift + NET_FRAMEWORK_VER=p:TargetFrameworkVersion=v$1 + PARAMS+=($NET_FRAMEWORK_VER) + shift + ;; + --) + shift + break + ;; + *) + print_help + exit 1 + ;; + esac +done + +PARAMS+=( + # By default use CC as Compiler- and LinkerPath, and AR as ArPath + ${CC:+"p:CompilerPath=$CC"} + ${CC:+"p:LinkerPath=$CC"} + ${AR:+"p:ArPath=$AR"} + # But allow users to override it + "$@" +) + +. "${{SRC_DIR}}/tools/common.sh" + +if $SKIP_FETCH +then + echo "Skipping library fetch" +else + "${{SRC_DIR}}"/tools/building/fetch_libraries.sh +fi + +if $HEADLESS +then + BUILD_TARGET=Headless + PARAMS+=(p:GUI_DISABLED=true) +elif $ON_WINDOWS +then + BUILD_TARGET=Windows + TFM="$TFM-windows10.0.17763.0" + RID="win-x64" +else + BUILD_TARGET=Mono +fi + +if [[ $GENERATE_DOTNET_BUILD_TARGET = true ]]; then + if $ON_WINDOWS; then + # CsWinRTAotOptimizerEnabled is disabled due to a bug in dotnet-sdk. + # See: https://github.com/dotnet/sdk/issues/44026 + OS_SPECIFIC_TARGET_OPTS='false' + fi +fi + +cat < "$(get_path "$PWD/Directory.Build.targets")" + + + $TFM + ${OS_SPECIFIC_TARGET_OPTS:+${OS_SPECIFIC_TARGET_OPTS}} + + +EOF + +fi + +if $NET +then + export DOTNET_CLI_TELEMETRY_OPTOUT=1 + CS_COMPILER="dotnet build" + TARGET="`get_path \"$PWD/Renode_NET.sln\"`" + BUILD_TYPE="dotnet" +else + TARGET="`get_path \"$PWD/Renode.sln\"`" + BUILD_TYPE="mono" +fi + +OUT_BIN_DIR="$(get_path "output/bin/${CONFIGURATION}")" +BUILD_TYPE_FILE=$(get_path "${OUT_BIN_DIR}/build_type") + +# Verify Mono and mcs version on Linux and macOS +if ! $ON_WINDOWS && ! $NET +then + if ! [ -x "$(command -v mcs)" ] + then + MINIMUM_MONO=`get_min_mono_version` + echo "mcs not found. Renode requires Mono $MINIMUM_MONO or newer. Please refer to documentation for installation instructions. Exiting!" + exit 1 + fi + + verify_mono_version +fi + +# Copy properties file according to the running OS +mkdir -p "$OUTPUT_DIRECTORY" +if $ON_OSX +then + PROP_FILE="${CURRENT_PATH:=.}/src/Infrastructure/src/Emulator/Cores/osx-properties.csproj" +elif $ON_LINUX +then + PROP_FILE="${CURRENT_PATH:=.}/src/Infrastructure/src/Emulator/Cores/linux-properties.csproj" +else + PROP_FILE="${CURRENT_PATH:=.}/src/Infrastructure/src/Emulator/Cores/windows-properties.csproj" +fi +cp "$PROP_FILE" "$OUTPUT_DIRECTORY/properties.csproj" + +if ! $NET +then + # Assets files are not deleted during `dotnet clean`, as it would confuse intellisense per comment in https://github.com/NuGet/Home/issues/7368#issuecomment-457411014, + # but we need to delete them to build Renode again for .NETFramework since `project.assets.json` doesn't play well if project files share the same directory. + # If `Renode_NET.sln` is picked for OmniSharp, it will trigger reanalysis of the project after removing assets files. + # We don't remove these files as part of `clean` target, because other intermediate files are well separated between .NET and .NETFramework + # and enforcing `clean` every time before rebuilding would slow down the build process on both frameworks. + find ${SRC_DIR} -type f -name 'project.assets.json' -delete +fi + +CORES_PATH="${SRC_DIR}/src/Infrastructure/src/Emulator/Cores" + +PARAMS+=(p:Configuration=${CONFIGURATION}${BUILD_TARGET} p:GenerateFullPaths=true p:Platform="\"$BUILD_PLATFORM\"") + +# build +eval "$CS_COMPILER $(build_args_helper "${PARAMS[@]}") $TARGET" +echo -n "$BUILD_TYPE" > "$BUILD_TYPE_FILE" + +# copy llvm library +LLVM_LIB="libllvm-disas" +if [[ $HOST_ARCH == "aarch64" ]]; then + # aarch64 host binaries have a different name + LLVM_LIB="libllvm-disas-aarch64" +fi +if [[ "${DETECTED_OS}" == "windows" ]]; then + LIB_EXT="dll" +elif [[ "${DETECTED_OS}" == "osx" ]]; then + LIB_EXT="dylib" +else + LIB_EXT="so" +fi +cp lib/resources/llvm/$LLVM_LIB.$LIB_EXT $OUT_BIN_DIR/libllvm-disas.$LIB_EXT diff --git a/recipes/renode-cli/patches/Cores-CMakeLists.txt b/recipes/renode-cli/patches/Cores-CMakeLists.txt deleted file mode 100644 index 6570fa08b1d85..0000000000000 --- a/recipes/renode-cli/patches/Cores-CMakeLists.txt +++ /dev/null @@ -1,39 +0,0 @@ -cmake_minimum_required(VERSION 3.12) - -project (renode-cores LANGUAGES C) - -add_subdirectory(tlib) - -# Add Renode sources to tlib target so that they get built as part of it - -if(NOT TARGET_ACTUAL_ARCH) - message(FATAL_ERROR "TARGET_ACTUAL_ARCH has to be set by tlib CMakeLists.txt!") -endif() - -file (GLOB RENODE_SOURCES - "renode/*.c" - "renode/arch/${TARGET_ACTUAL_ARCH}/*.c" -) - -target_sources(tlib PRIVATE - ${RENODE_SOURCES} -) - -# Include directories with Renode headers when building tlib - -target_include_directories(tlib PRIVATE - renode/include -) - -# Set tlib output filename - -set (ENDIAN_STR "le") -if (TARGET_BIG_ENDIAN) - set (ENDIAN_STR "be") -endif() - -set_target_properties(tlib PROPERTIES - PREFIX "" - OUTPUT_NAME "translate-${TARGET_ARCH}-${ENDIAN_STR}" - SUFFIX ".so" -) \ No newline at end of file diff --git a/recipes/renode-cli/recipe.yaml b/recipes/renode-cli/recipe.yaml index 167ffc1f774dc..7583f9c58b4c7 100644 --- a/recipes/renode-cli/recipe.yaml +++ b/recipes/renode-cli/recipe.yaml @@ -27,7 +27,7 @@ requirements: build: - dotnet - nuget-license - - renode-cores + - renode-cores ${{ version }} - sed host: - dotnet @@ -39,7 +39,7 @@ tests: bin: - renode - renode.cmd - - renode-test + # fails, why? - renode-test - script: - renode --help - renode-test diff --git a/recipes/renode-cores/helpers/renode_build_with_cmake.ps1 b/recipes/renode-cores/helpers/renode_build_with_cmake.ps1 old mode 100644 new mode 100755 From 4339a6055b54db6320036cf3025d03c56aa57fe3 Mon Sep 17 00:00:00 2001 From: memento Date: Thu, 30 Jan 2025 10:06:02 -0600 Subject: [PATCH 17/26] (fix) test script: hardcode pkg_name --- recipes/renode-cli/build.sh | 14 +- .../helpers/renode_build_with_dotnet.sh | 156 ++++-------------- recipes/renode-cli/recipe.yaml | 3 +- 3 files changed, 42 insertions(+), 131 deletions(-) diff --git a/recipes/renode-cli/build.sh b/recipes/renode-cli/build.sh index 3a9e095c98956..a414949650b87 100644 --- a/recipes/renode-cli/build.sh +++ b/recipes/renode-cli/build.sh @@ -24,14 +24,10 @@ sed -i -E 's/(ReleaseHeadless\|Any .+ = )Debug/\1Release/' Renode_NET.sln # Prevent CMake build since we provide the binaries mkdir -p ${SRC_DIR}/src/Infrastructure/src/Emulator/Cores/bin/Release/lib cp ${BUILD_PREFIX}/lib/renode-cores/* ${SRC_DIR}/src/Infrastructure/src/Emulator/Cores/bin/Release/lib -rm -f ${SRC_DIR}/src/Infrastructure/src/Emulator/Cores/translate*.cproj +# rm -f ${SRC_DIR}/src/Infrastructure/src/Emulator/Cores/translate*.cproj -if [[ "${target_platform}" == linux-* ]] || [[ "${target_platform}" == osx-* ]]; then - chmod +x tools/{building,packaging}/*.sh - ${RECIPE_DIR}/helpers/renode_build_with_dotnet.sh --net --no-gui --force-net-framework-version ${framework_version} -else - ${RECIPE_DIR}/helpers/renode_build_with_dotnet.ps1 --net --no-gui --force-net-framework-version ${framework_version} -fi +chmod +x tools/{building,packaging}/*.sh +${RECIPE_DIR}/helpers/renode_build_with_dotnet.sh ${framework_version} # Install procedure mkdir -p $PREFIX/libexec/${PKG_NAME} @@ -54,7 +50,7 @@ cp -r tools/sel4_extensions $PREFIX/opt/${PKG_NAME}/tools cp lib/resources/styles/robot.css $PREFIX/opt/${PKG_NAME}/tests -tools/packaging/common_copy_licenses.sh $PREFIX/opt/${PKG_NAME}/licenses $_os_name +tools/packaging/common_copy_licenses.sh $PREFIX/opt/${PKG_NAME}/licenses linux cp -r $PREFIX/opt/${PKG_NAME}/licenses license-files sed -i.bak "s#os\.path\.join(this_path, '\.\./lib/resources/styles/robot\.css')#os.path.join(this_path,'robot.css')#g" $PREFIX/opt/${PKG_NAME}/tests/robot_tests_provider.py @@ -76,7 +72,7 @@ cat > $PREFIX/bin/renode-test <<"EOF" #!/usr/bin/env bash STTY_CONFIG=`stty -g 2>/dev/null` -python3 "${CONDA_PREFIX}"/opt/"${PKG_NAME}"/tests/run_tests.py --robot-framework-remote-server-full-directory "${CONDA_PREFIX}"/libexec/"${PKG_NAME}" "$@" +python3 "${CONDA_PREFIX}"/opt/renode-cli/tests/run_tests.py --robot-framework-remote-server-full-directory "${CONDA_PREFIX}"/libexec/renode-cli "$@" RESULT_CODE=$? if [ -n "${STTY_CONFIG:-}" ] then diff --git a/recipes/renode-cli/helpers/renode_build_with_dotnet.sh b/recipes/renode-cli/helpers/renode_build_with_dotnet.sh index 433a9c4e8772a..74221d2815424 100755 --- a/recipes/renode-cli/helpers/renode_build_with_dotnet.sh +++ b/recipes/renode-cli/helpers/renode_build_with_dotnet.sh @@ -1,69 +1,25 @@ #!/usr/bin/env bash -set -u -set -e +set -uex + +framework_version=$1 +shift 1 OUTPUT_DIRECTORY="${SRC_DIR}/output" -UPDATE_SUBMODULES=false CONFIGURATION="Release" -HEADLESS=false -NET=false -TFM="net8.0" +BUILD_PLATFORM="Any CPU" +HEADLESS=true +NET=true +TFM="net${framework_version}" GENERATE_DOTNET_BUILD_TARGET=true -PARAMS=() NET_FRAMEWORK_VER= RID="linux-x64" HOST_ARCH="i386" # Common cmake flags CMAKE_COMMON="" -function print_help() { - echo "Usage: $0 [--no-gui] [--net] [--force-net-framework-version] [--host-arch i386|aarch64] [-- ]" - echo - echo "--no-gui build with GUI disabled" - echo "--force-net-framework-version build against different version of .NET Framework than specified in the solution" - echo "--net build with dotnet" - echo "--host-arch build with a specific tcg host architecture (default: i386)" - echo " arguments to pass to the build system" -} - -OPTIONS=$(getopt -o vhnt: -l "no-gui,net,tlib-only,host-arch:" -n "$0" -- "$@") -eval set -- "$OPTIONS" - -while true; do - case $1 in - --no-gui) - HEADLESS=true - shift - ;; - --net) - NET=true - shift - ;; - --host-arch) - shift - HOST_ARCH=$1 - shift - ;; - --force-net-framework-version) - shift - NET_FRAMEWORK_VER=p:TargetFrameworkVersion=v$1 - PARAMS+=($NET_FRAMEWORK_VER) - shift - ;; - --) - shift - break - ;; - *) - print_help - exit 1 - ;; - esac -done - -PARAMS+=( +PARAMS=( # By default use CC as Compiler- and LinkerPath, and AR as ArPath ${CC:+"p:CompilerPath=$CC"} ${CC:+"p:LinkerPath=$CC"} @@ -72,37 +28,15 @@ PARAMS+=( "$@" ) -. "${{SRC_DIR}}/tools/common.sh" - -if $SKIP_FETCH -then - echo "Skipping library fetch" -else - "${{SRC_DIR}}"/tools/building/fetch_libraries.sh -fi - if $HEADLESS then BUILD_TARGET=Headless PARAMS+=(p:GUI_DISABLED=true) -elif $ON_WINDOWS -then - BUILD_TARGET=Windows - TFM="$TFM-windows10.0.17763.0" - RID="win-x64" else BUILD_TARGET=Mono fi -if [[ $GENERATE_DOTNET_BUILD_TARGET = true ]]; then - if $ON_WINDOWS; then - # CsWinRTAotOptimizerEnabled is disabled due to a bug in dotnet-sdk. - # See: https://github.com/dotnet/sdk/issues/44026 - OS_SPECIFIC_TARGET_OPTS='false' - fi -fi - -cat < "$(get_path "$PWD/Directory.Build.targets")" +cat < "${SRC_DIR}/Directory.Build.targets" $TFM @@ -111,63 +45,43 @@ cat < "$(get_path "$PWD/Directory.Build.targets")" EOF -fi +export DOTNET_CLI_TELEMETRY_OPTOUT=1 +CS_COMPILER="dotnet build" +TARGET="${SRC_DIR}/Renode_NET.sln" +BUILD_TYPE="dotnet" -if $NET -then - export DOTNET_CLI_TELEMETRY_OPTOUT=1 - CS_COMPILER="dotnet build" - TARGET="`get_path \"$PWD/Renode_NET.sln\"`" - BUILD_TYPE="dotnet" -else - TARGET="`get_path \"$PWD/Renode.sln\"`" - BUILD_TYPE="mono" -fi - -OUT_BIN_DIR="$(get_path "output/bin/${CONFIGURATION}")" -BUILD_TYPE_FILE=$(get_path "${OUT_BIN_DIR}/build_type") - -# Verify Mono and mcs version on Linux and macOS -if ! $ON_WINDOWS && ! $NET -then - if ! [ -x "$(command -v mcs)" ] - then - MINIMUM_MONO=`get_min_mono_version` - echo "mcs not found. Renode requires Mono $MINIMUM_MONO or newer. Please refer to documentation for installation instructions. Exiting!" - exit 1 - fi - - verify_mono_version -fi +OUT_BIN_DIR="${SRC_DIR}/output/bin/${CONFIGURATION}" +BUILD_TYPE_FILE="${OUT_BIN_DIR}/build_type" # Copy properties file according to the running OS mkdir -p "$OUTPUT_DIRECTORY" -if $ON_OSX -then +rm -f "$OUTPUT_DIRECTORY/properties.csproj" +if [[ "${target_platform}" == "osx-"* ]]; then PROP_FILE="${CURRENT_PATH:=.}/src/Infrastructure/src/Emulator/Cores/osx-properties.csproj" -elif $ON_LINUX -then +elif [[ "${target_platform}" == "linux-"* ]] || [[ "${target_platform}" == "noarch" ]]; then PROP_FILE="${CURRENT_PATH:=.}/src/Infrastructure/src/Emulator/Cores/linux-properties.csproj" else PROP_FILE="${CURRENT_PATH:=.}/src/Infrastructure/src/Emulator/Cores/windows-properties.csproj" fi cp "$PROP_FILE" "$OUTPUT_DIRECTORY/properties.csproj" -if ! $NET -then - # Assets files are not deleted during `dotnet clean`, as it would confuse intellisense per comment in https://github.com/NuGet/Home/issues/7368#issuecomment-457411014, - # but we need to delete them to build Renode again for .NETFramework since `project.assets.json` doesn't play well if project files share the same directory. - # If `Renode_NET.sln` is picked for OmniSharp, it will trigger reanalysis of the project after removing assets files. - # We don't remove these files as part of `clean` target, because other intermediate files are well separated between .NET and .NETFramework - # and enforcing `clean` every time before rebuilding would slow down the build process on both frameworks. - find ${SRC_DIR} -type f -name 'project.assets.json' -delete -fi - CORES_PATH="${SRC_DIR}/src/Infrastructure/src/Emulator/Cores" PARAMS+=(p:Configuration=${CONFIGURATION}${BUILD_TARGET} p:GenerateFullPaths=true p:Platform="\"$BUILD_PLATFORM\"") # build +function build_args_helper() { + local retStr="" + for p in "$@" ; do + if [ "$CS_COMPILER" = 'xbuild' ] ; then + retStr="${retStr} /$p" + else + retStr="${retStr} -$p" + fi + done + echo ${retStr} +} + eval "$CS_COMPILER $(build_args_helper "${PARAMS[@]}") $TARGET" echo -n "$BUILD_TYPE" > "$BUILD_TYPE_FILE" @@ -177,11 +91,11 @@ if [[ $HOST_ARCH == "aarch64" ]]; then # aarch64 host binaries have a different name LLVM_LIB="libllvm-disas-aarch64" fi -if [[ "${DETECTED_OS}" == "windows" ]]; then - LIB_EXT="dll" -elif [[ "${DETECTED_OS}" == "osx" ]]; then +if [[ "${target_platform}" == "linux-"* ]] || [[ "${target_platform}" == "noarch" ]]; then + LIB_EXT="so" +elif [[ "${target_platform}" == "osx-"* ]]; then LIB_EXT="dylib" else - LIB_EXT="so" + LIB_EXT="dll" fi cp lib/resources/llvm/$LLVM_LIB.$LIB_EXT $OUT_BIN_DIR/libllvm-disas.$LIB_EXT diff --git a/recipes/renode-cli/recipe.yaml b/recipes/renode-cli/recipe.yaml index 7583f9c58b4c7..21a8ddb9e3276 100644 --- a/recipes/renode-cli/recipe.yaml +++ b/recipes/renode-cli/recipe.yaml @@ -26,8 +26,9 @@ build: requirements: build: - dotnet + - git - nuget-license - - renode-cores ${{ version }} + - renode-cores ==${{ version }} - sed host: - dotnet From f206438f3bd638c12f36911b213fea18f89b15a7 Mon Sep 17 00:00:00 2001 From: memento Date: Thu, 30 Jan 2025 17:14:38 -0600 Subject: [PATCH 18/26] (fix) dynamic libraries loader? --- recipes/renode-cli/build.sh | 7 +- .../helpers/DynamicLibraryLoader.cs | 90 +++++++++++++++++++ .../helpers/DynamicLibraryLoader.csproj | 19 ++++ .../patches/update-dynamic-Program.cs.patch | 45 ++++++++++ .../update-dynamic-Renode_NET.csproj.patch | 9 ++ ...te-dynamic-cores.template_NET.csproj.patch | 15 ++++ recipes/renode-cli/recipe.yaml | 6 +- recipes/renode-cores/build.bat | 9 ++ recipes/renode-cores/build.sh | 8 ++ recipes/renode-cores/recipe.yaml | 10 ++- recipes/renode-cores/scripts/activate.bat | 8 +- recipes/renode-cores/scripts/activate.sh | 4 + recipes/renode-cores/scripts/deactivate.bat | 8 ++ recipes/renode-cores/scripts/deactivate.sh | 8 ++ 14 files changed, 240 insertions(+), 6 deletions(-) create mode 100644 recipes/renode-cli/helpers/DynamicLibraryLoader.cs create mode 100644 recipes/renode-cli/helpers/DynamicLibraryLoader.csproj create mode 100644 recipes/renode-cli/patches/update-dynamic-Program.cs.patch create mode 100644 recipes/renode-cli/patches/update-dynamic-Renode_NET.csproj.patch create mode 100644 recipes/renode-cli/patches/update-dynamic-cores.template_NET.csproj.patch create mode 100644 recipes/renode-cores/scripts/activate.sh create mode 100644 recipes/renode-cores/scripts/deactivate.bat create mode 100644 recipes/renode-cores/scripts/deactivate.sh diff --git a/recipes/renode-cli/build.sh b/recipes/renode-cli/build.sh index a414949650b87..18fb773733841 100644 --- a/recipes/renode-cli/build.sh +++ b/recipes/renode-cli/build.sh @@ -24,7 +24,12 @@ sed -i -E 's/(ReleaseHeadless\|Any .+ = )Debug/\1Release/' Renode_NET.sln # Prevent CMake build since we provide the binaries mkdir -p ${SRC_DIR}/src/Infrastructure/src/Emulator/Cores/bin/Release/lib cp ${BUILD_PREFIX}/lib/renode-cores/* ${SRC_DIR}/src/Infrastructure/src/Emulator/Cores/bin/Release/lib -# rm -f ${SRC_DIR}/src/Infrastructure/src/Emulator/Cores/translate*.cproj + +# Remove the C cores that are not built in this recipe +rm -f ${SRC_DIR}/src/Infrastructure/src/Emulator/Cores/translate*.cproj + +# Add dynamic libraries framewkr +cp ${RECIPE_DIR}/helpers/DynamicLibraryLoader.{cs,csproj} ${SRC_DIR}/src/Renode chmod +x tools/{building,packaging}/*.sh ${RECIPE_DIR}/helpers/renode_build_with_dotnet.sh ${framework_version} diff --git a/recipes/renode-cli/helpers/DynamicLibraryLoader.cs b/recipes/renode-cli/helpers/DynamicLibraryLoader.cs new file mode 100644 index 0000000000000..24a14a85df054 --- /dev/null +++ b/recipes/renode-cli/helpers/DynamicLibraryLoader.cs @@ -0,0 +1,90 @@ +using System; +using System.Runtime.InteropServices; + +public class DynamicLibraryLoader +{ + private IntPtr _libraryHandle; + private readonly string _libraryPath; + + public DynamicLibraryLoader(string libraryPath) + { + _libraryPath = libraryPath; +#if PLATFORM_WINDOWS + _libraryHandle = LoadLibrary(libraryPath); +#elif PLATFORM_LINUX || PLATFORM_OSX + _libraryHandle = dlopen(libraryPath, RTLD_NOW); +#endif + + if (_libraryHandle == IntPtr.Zero) + { + throw new Exception("Failed to load library: " + libraryPath); + } + } + + public void LoadLibrary(string libraryName) + { + var fullPath = System.IO.Path.Combine(_libraryPath, libraryName); +#if PLATFORM_WINDOWS + _libraryHandle = LoadLibrary(fullPath); +#elif PLATFORM_LINUX || PLATFORM_OSX + _libraryHandle = dlopen(fullPath, RTLD_NOW); +#endif + + if (_libraryHandle == IntPtr.Zero) + { + throw new Exception("Failed to load library: " + fullPath); + } + } + + public T GetFunctionDelegate(string functionName) where T : Delegate + { + IntPtr functionAddress = IntPtr.Zero; + +#if PLATFORM_WINDOWS + functionAddress = GetProcAddress(_libraryHandle, functionName); +#elif PLATFORM_LINUX || PLATFORM_OSX + functionAddress = dlsym(_libraryHandle, functionName); +#endif + + if (functionAddress == IntPtr.Zero) + { + throw new Exception("Failed to get function address: " + functionName); + } + + return Marshal.GetDelegateForFunctionPointer(functionAddress); + } + + ~DynamicLibraryLoader() + { + if (_libraryHandle != IntPtr.Zero) + { +#if PLATFORM_WINDOWS + FreeLibrary(_libraryHandle); +#elif PLATFORM_LINUX || PLATFORM_OSX + dlclose(_libraryHandle); +#endif + } + } + +#if PLATFORM_WINDOWS + [DllImport("kernel32.dll", SetLastError = true)] + private static extern IntPtr LoadLibrary(string dllToLoad); + + [DllImport("kernel32.dll", SetLastError = true)] + private static extern IntPtr GetProcAddress(IntPtr hModule, string procedureName); + + [DllImport("kernel32.dll", SetLastError = true)] + private static extern bool FreeLibrary(IntPtr hModule); +#elif PLATFORM_LINUX || PLATFORM_OSX + [DllImport("libdl.so")] + private static extern IntPtr dlopen(string fileName, int flags); + + [DllImport("libdl.so")] + private static extern IntPtr dlsym(IntPtr handle, string symbol); + + [DllImport("libdl.so")] + private static extern int dlclose(IntPtr handle); + + private const int RTLD_NOW = 2; +#endif +} \ No newline at end of file diff --git a/recipes/renode-cli/helpers/DynamicLibraryLoader.csproj b/recipes/renode-cli/helpers/DynamicLibraryLoader.csproj new file mode 100644 index 0000000000000..06e242781a69e --- /dev/null +++ b/recipes/renode-cli/helpers/DynamicLibraryLoader.csproj @@ -0,0 +1,19 @@ + + + net8.0 + 7.3 + $(DefineConstants);PLATFORM_LINUX + false + + + $(DefineConstants);PLATFORM_WINDOWS + + + + $(DefineConstants);PLATFORM_OSX + + + + + + \ No newline at end of file diff --git a/recipes/renode-cli/patches/update-dynamic-Program.cs.patch b/recipes/renode-cli/patches/update-dynamic-Program.cs.patch new file mode 100644 index 0000000000000..c47b3a31aa651 --- /dev/null +++ b/recipes/renode-cli/patches/update-dynamic-Program.cs.patch @@ -0,0 +1,45 @@ +--- a/src/Renode/Program.cs 2025-01-30 11:54:45.389351518 -0600 ++++ b/src/Renode/Program.cs 2025-01-30 11:34:18.393137972 -0600 +@@ -11,2 +11,3 @@ + using System.IO; ++using System.Runtime.InteropServices; + using System; +@@ -45,2 +45,32 @@ + */ ++ ++ // Load dynamic libraries ++ var libraryDirectory = Environment.GetEnvironmentVariable("RENODE_CORES_PATH") ?? "../src/Infrastructure/src/Emulator/Cores/bin/Release/lib"; ++ var libraryFiles = Directory.GetFiles(libraryDirectory, "translate-*.so"); ++ var libraries = new string[] ++ { ++ "translate-arm-be.so", ++ "translate-arm-le.so", ++ "translate-arm-m-be.so", ++ "translate-arm-m-le.so", ++ "translate-arm64-le.so", ++ "translate-i386-le.so", ++ "translate-ppc-be.so", ++ "translate-ppc-le.so", ++ "translate-ppc64-be.so", ++ "translate-ppc64-le.so", ++ "translate-riscv-le.so", ++ "translate-riscv64-le.so", ++ "translate-sparc-be.so", ++ "translate-sparc-le.so", ++ "translate-x86_64-le.so", ++ "translate-xtensa-le.so", ++ }; ++ ++ var loader = new DynamicLibraryLoader(libraryDirectory); ++ foreach (var library in libraries) ++ { ++ loader.LoadLibrary(library); ++ } ++ + Core.EmulationManager.RebuildInstance(); +@@ -132,2 +162,5 @@ + } ++ ++ [UnmanagedFunctionPointer(CallingConvention.Cdecl)] ++ private delegate int FunctionDelegate(int a, int b); + } diff --git a/recipes/renode-cli/patches/update-dynamic-Renode_NET.csproj.patch b/recipes/renode-cli/patches/update-dynamic-Renode_NET.csproj.patch new file mode 100644 index 0000000000000..88033a578b5d7 --- /dev/null +++ b/recipes/renode-cli/patches/update-dynamic-Renode_NET.csproj.patch @@ -0,0 +1,9 @@ +--- a/src/Renode/Renode_NET.csproj 2024-09-17 05:28:40.000000000 -0500 ++++ b/src/Renode/Renode_NET.csproj 2025-01-30 11:47:34.648017897 -0600 +@@ -14,1 +14,1 @@ +- 7.2 ++ 7.3 +@@ -45,2 +45,3 @@ + ++ + diff --git a/recipes/renode-cli/patches/update-dynamic-cores.template_NET.csproj.patch b/recipes/renode-cli/patches/update-dynamic-cores.template_NET.csproj.patch new file mode 100644 index 0000000000000..e175485998989 --- /dev/null +++ b/recipes/renode-cli/patches/update-dynamic-cores.template_NET.csproj.patch @@ -0,0 +1,15 @@ +--- a/src/Infrastructure/src/Emulator/Cores/cores.template_NET.csproj 2024-09-17 05:29:16.000000000 -0500 ++++ b/src/Infrastructure/src/Emulator/Cores/cores.template_NET.csproj 2025-01-27 21:35:32.396468884 -0600 +@@ -15,12 +16,2 @@ + +- +- +- +- Antmicro.Renode.translate-$(Architecture)-le.so +- +- +- Antmicro.Renode.translate-$(Architecture)-be.so +- +- +- + \ No newline at end of file diff --git a/recipes/renode-cli/recipe.yaml b/recipes/renode-cli/recipe.yaml index 21a8ddb9e3276..2db6df7333d3e 100644 --- a/recipes/renode-cli/recipe.yaml +++ b/recipes/renode-cli/recipe.yaml @@ -18,6 +18,9 @@ source: - patches/update-cores.template_NET.csproj.patch - patches/update-IronPython-Unittest_NET.csproj.patch - patches/resolve-posix-unix.patch + - patches/update-dynamic-cores.template_NET.csproj.patch + - patches/update-dynamic-Program.cs.patch + - patches/update-dynamic-Renode_NET.csproj.patch build: number: 0 @@ -43,11 +46,12 @@ tests: # fails, why? - renode-test - script: - renode --help - - renode-test + - renode-test ${PREFIX}/opt/renode-cli/tests/unit-tests requirements: run: - robotframework 6.1 - psutil 5.9.3 + - python - pyyaml 6.0 about: diff --git a/recipes/renode-cores/build.bat b/recipes/renode-cores/build.bat index 97c39cc5adf4c..6dca6024a10b2 100644 --- a/recipes/renode-cores/build.bat +++ b/recipes/renode-cores/build.bat @@ -19,4 +19,13 @@ mkdir "%PREFIX%\Library\lib\%PKG_NAME%" icacls "%PREFIX%\Library\lib\%PKG_NAME%" /grant Users:(OI)(CI)F /T robocopy "%CORES_BIN_PATH%\lib" "%PREFIX%\Library\lib\%PKG_NAME%" /E /COPY:DATSO +:: Setting conda host environment variables +if not exist "%PREFIX%\etc\conda\activate.d\" mkdir "%PREFIX%\etc\conda\activate.d\" +if not exist "%PREFIX%\etc\conda\deactivate.d\" mkdir "%PREFIX%\etc\conda\deactivate.d\" + +copy "%RECIPE_DIR%\scripts\activate.bat" "%PREFIX%\etc\conda\activate.d\%PKG_NAME%-activate.bat" > nul +if %ERRORLEVEL% neq 0 exit /b %ERRORLEVEL% +copy "%RECIPE_DIR%\scripts\deactivate.bat" "%PREFIX%\etc\conda\deactivate.d\%PKG_NAME%-deactivate.bat" > nul +if %ERRORLEVEL% neq 0 exit /b %ERRORLEVEL% + endlocal diff --git a/recipes/renode-cores/build.sh b/recipes/renode-cores/build.sh index eeb5b57ff3fbc..c1205c6751492 100644 --- a/recipes/renode-cores/build.sh +++ b/recipes/renode-cores/build.sh @@ -16,3 +16,11 @@ CORES_BIN_PATH="$CORES_PATH/bin/$CONFIGURATION" mkdir -p "${PREFIX}/lib/${PKG_NAME}" tar -c -C "${CORES_BIN_PATH}/lib" . | tar -x -C "${PREFIX}/lib/${PKG_NAME}" + +# Copy the [de]activate scripts to $PREFIX/etc/conda/[de]activate.d. +# This will allow them to be run on environment activation. +for CHANGE in "activate" "deactivate" +do + mkdir -p "${PREFIX}/etc/conda/${CHANGE}.d" + cp "${RECIPE_DIR}/scripts/${CHANGE}.sh" "${PREFIX}/etc/conda/${CHANGE}.d/${PKG_NAME}-${CHANGE}.sh" +done \ No newline at end of file diff --git a/recipes/renode-cores/recipe.yaml b/recipes/renode-cores/recipe.yaml index 5d96d64f3280b..da4465d337920 100644 --- a/recipes/renode-cores/recipe.yaml +++ b/recipes/renode-cores/recipe.yaml @@ -56,9 +56,13 @@ tests: - ${{ "Library/" if not unix }}lib/renode-cores/translate-xtensa-le.so - if: unix then: - - ${{ "Library/" if not unix }}lib/renode-cores/translate-ppc64-be.so - - ${{ "Library/" if not unix }}lib/renode-cores/translate-ppc64-le.so - + - lib/renode-cores/translate-ppc64-be.so + - lib/renode-cores/translate-ppc64-le.so + - etc/conda/activate.d/renode-cores-activate.sh + - etc/conda/deactivate.d/renode-cores-deactivate.sh + else: + - etc/conda/activate.d/renode-cores-activate.bat + - etc/conda/deactivate.d/renode-cores-deactivate.bat about: homepage: https://github.com/renode/renode summary: "Antmicro's open source simulation and virtual development framework for complex embedded systems" diff --git a/recipes/renode-cores/scripts/activate.bat b/recipes/renode-cores/scripts/activate.bat index 7fd79e749862a..11790d75cbde3 100755 --- a/recipes/renode-cores/scripts/activate.bat +++ b/recipes/renode-cores/scripts/activate.bat @@ -1,2 +1,8 @@ @echo off -set PATH=%PATH%;%CONDA_PREFIX%\Library\renode\exec \ No newline at end of file +@if defined RENODE_CORES_PATH ( + @set "_RENODE_CORES_PATH_BACKUP=%RENODE_CORES_PATH%" + :: Remove the last path from the PATH + @for %%i in ("%RENODE_CORES_PATH%") do @set "PATH=%%~dpi" +) +set RENODE_CORES_PATH=%CONDA_PREFIX%\Library\renode-cores +set "PATH=%RENODE_CORES_PATH%;%PATH%" diff --git a/recipes/renode-cores/scripts/activate.sh b/recipes/renode-cores/scripts/activate.sh new file mode 100644 index 0000000000000..add69d61363d8 --- /dev/null +++ b/recipes/renode-cores/scripts/activate.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +export _RENODE_CORES_PATH_BACKUP=${RENODE_CORES_PATH:-} +export RENODE_CORES_PATH=${CONDA_PREFIX}/lib/renode-cores diff --git a/recipes/renode-cores/scripts/deactivate.bat b/recipes/renode-cores/scripts/deactivate.bat new file mode 100644 index 0000000000000..6960a91490575 --- /dev/null +++ b/recipes/renode-cores/scripts/deactivate.bat @@ -0,0 +1,8 @@ +@for %%i in ("%RENODE_CORES_PATH%") do @set "PATH=%%~dpi" + +@if defined _RENODE_CORES_PATH_BACKUP ( + @set "RENODE_CORES_PATH=%_RENODE_CORES_PATH_BACKUP%" + @set "_RENODE_CORES_PATH_BACKUP=" +) else ( + @set "RENODE_CORES_PATH=" +) diff --git a/recipes/renode-cores/scripts/deactivate.sh b/recipes/renode-cores/scripts/deactivate.sh new file mode 100644 index 0000000000000..c771254bc675d --- /dev/null +++ b/recipes/renode-cores/scripts/deactivate.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env bash + +# Restore previous env vars if they were set. +unset RENODE_CORES_PATH +if [[ -n "$_RENODE_CORES_PATH_BACKUP" ]]; then + export RENODE_CORES_PATH=$_RENODE_CORES_PATH_BACKUP + unset _RENODE_CORES_PATH_BACKUP +fi \ No newline at end of file From cab5f380a287a5fb1ca0326f76c4d49b0fe7818e Mon Sep 17 00:00:00 2001 From: memento Date: Thu, 30 Jan 2025 21:33:07 -0600 Subject: [PATCH 19/26] (fix) arm64 asm code --- .../patches/fix-tcg-arm64-asm.patch | 27 +++++++++++++++++++ recipes/renode-cores/recipe.yaml | 4 ++- 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 recipes/renode-cores/patches/fix-tcg-arm64-asm.patch diff --git a/recipes/renode-cores/patches/fix-tcg-arm64-asm.patch b/recipes/renode-cores/patches/fix-tcg-arm64-asm.patch new file mode 100644 index 0000000000000..79a0402690363 --- /dev/null +++ b/recipes/renode-cores/patches/fix-tcg-arm64-asm.patch @@ -0,0 +1,27 @@ +--- a/src/Infrastructure/src/Emulator/Cores/tlib/tcg/host-utils.h 2025-01-30 17:49:53.632175202 -0600 ++++ a/src/Infrastructure/src/Emulator/Cores/tlib/tcg/host-utils.h 2025-01-30 17:49:46.140225383 -0600 +@@ -83,2 +83,3 @@ + #if defined(TCG_TARGET_I386) && HOST_LONG_BITS == 64 ++#if defined(__x86_64__) || defined(_M_X64) + #define __HAVE_FAST_MULU64__ +@@ -97,2 +98,20 @@ + } ++#elif defined(__aarch64__) ++#define __HAVE_FAST_MULU64__ ++static inline void mulu64(uint64_t *plow, uint64_t *phigh, uint64_t a, uint64_t b) ++{ ++ __asm__ ("umulh %0, %1, %2" ++ : "=r" (*phigh) ++ : "r" (a), "r" (b)); ++ *plow = a * b; ++} ++#define __HAVE_FAST_MULS64__ ++static inline void muls64(uint64_t *plow, uint64_t *phigh, int64_t a, int64_t b) ++{ ++ __asm__ ("smulh %0, %1, %2" ++ : "=r" (*phigh) ++ : "r" (a), "r" (b)); ++ *plow = a * b; ++} ++#endif + #else diff --git a/recipes/renode-cores/recipe.yaml b/recipes/renode-cores/recipe.yaml index da4465d337920..ad77fec5862c3 100644 --- a/recipes/renode-cores/recipe.yaml +++ b/recipes/renode-cores/recipe.yaml @@ -12,7 +12,9 @@ source: sha256: 40c50afe8db86a9c63f4a86b93116a6babd43bf241cfaac47b2c0d2cbc2b15a8 patches: - patches/update-for-cmake-build.sh.patch - + - if: osx and arm64 + then: + - patches/fix-tcg-arm64-asm.patch build: number: 0 From 020a069b6227f409e1be576da3518203b8e4c5b5 Mon Sep 17 00:00:00 2001 From: memento Date: Thu, 30 Jan 2025 21:37:02 -0600 Subject: [PATCH 20/26] (ref) remove build.sh patch --- recipes/renode-cores/recipe.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/recipes/renode-cores/recipe.yaml b/recipes/renode-cores/recipe.yaml index ad77fec5862c3..112134d11496d 100644 --- a/recipes/renode-cores/recipe.yaml +++ b/recipes/renode-cores/recipe.yaml @@ -11,7 +11,7 @@ source: - url: https://github.com/renode/renode/releases/download/v${{ version }}/renode_${{ version }}_source.tar.xz sha256: 40c50afe8db86a9c63f4a86b93116a6babd43bf241cfaac47b2c0d2cbc2b15a8 patches: - - patches/update-for-cmake-build.sh.patch + # - patches/update-for-cmake-build.sh.patch - if: osx and arm64 then: - patches/fix-tcg-arm64-asm.patch From 0d3e41696ec284c436a344dbe91cfcaabcd58678 Mon Sep 17 00:00:00 2001 From: memento Date: Fri, 31 Jan 2025 11:14:59 -0600 Subject: [PATCH 21/26] (dev) remove patches, switch to arch renode-cli --- recipes/renode-cli/build.bat | 75 ++++ recipes/renode-cli/build.sh | 3 - .../helpers/DynamicLibraryLoader.cs | 90 ----- .../helpers/DynamicLibraryLoader.csproj | 19 - .../helpers/renode_build_with_dotnet.ps1 | 83 ++++ .../helpers/renode_build_with_dotnet.sh | 12 +- .../patches/update-dynamic-Program.cs.patch | 45 --- .../update-dynamic-Renode_NET.csproj.patch | 9 - ...te-dynamic-cores.template_NET.csproj.patch | 15 - .../patches/update-for-cmake-build.sh.patch | 367 ------------------ recipes/renode-cli/recipe.yaml | 11 +- recipes/renode-cores/build.bat | 8 +- recipes/renode-cores/build.sh | 10 +- .../helpers/renode_build_with_cmake.ps1 | 57 --- .../helpers/renode_build_with_cmake.sh | 68 +--- .../renode-cores/patches/Cores-CMakeLists.txt | 39 -- .../patches/fix-tcg-arm64-asm.patch | 27 -- .../renode-cores/patches/tlib-CMakeLists.txt | 232 ----------- .../patches/update-for-cmake-build.sh.patch | 367 ------------------ recipes/renode-cores/recipe.yaml | 12 +- 20 files changed, 185 insertions(+), 1364 deletions(-) create mode 100644 recipes/renode-cli/build.bat delete mode 100644 recipes/renode-cli/helpers/DynamicLibraryLoader.cs delete mode 100644 recipes/renode-cli/helpers/DynamicLibraryLoader.csproj create mode 100755 recipes/renode-cli/helpers/renode_build_with_dotnet.ps1 delete mode 100644 recipes/renode-cli/patches/update-dynamic-Program.cs.patch delete mode 100644 recipes/renode-cli/patches/update-dynamic-Renode_NET.csproj.patch delete mode 100644 recipes/renode-cli/patches/update-dynamic-cores.template_NET.csproj.patch delete mode 100644 recipes/renode-cli/patches/update-for-cmake-build.sh.patch delete mode 100644 recipes/renode-cores/patches/Cores-CMakeLists.txt delete mode 100644 recipes/renode-cores/patches/fix-tcg-arm64-asm.patch delete mode 100644 recipes/renode-cores/patches/tlib-CMakeLists.txt delete mode 100644 recipes/renode-cores/patches/update-for-cmake-build.sh.patch diff --git a/recipes/renode-cli/build.bat b/recipes/renode-cli/build.bat new file mode 100644 index 0000000000000..734bdefc6bb89 --- /dev/null +++ b/recipes/renode-cli/build.bat @@ -0,0 +1,75 @@ +@echo off +setlocal enabledelayedexpansion + +set "install_prefix=%PREFIX%\opt\%PKG_NAME%" + +for /f "tokens=*" %%i in ('dotnet --version') do set "dotnet_version=%%i" +set "framework_version=%dotnet_version:~0,-2%" + +rem Patch the project files to use the correct .NET version +for /r %%i in (lib src tests) do ( + for /r %%j in (*.csproj) do ( + sed -i -E "s/([>;])net6.0([<;])/\1net%framework_version%\2/" "%%j" + sed -i -E "s|^((\s+))|\1\n\2\2CS0168;CS0219;CS8981;SYSLIB0050;SYSLIB0051|" "%%j" + sed -i -E 's|^(\s+)<(Package)?Reference\s+Include="Mono.Posix".*\n||g' "%%j" + ) +) +for /d %%i in (obj bin) do ( + rd /s /q "%%i" +) +sed -i -E "s/(ReleaseHeadless\|Any .+ = )Debug/\1Release/" Renode_NET.sln + +rem Prevent CMake build since we provide the binaries +mkdir "%SRC_DIR%\src\Infrastructure\src\Emulator\Cores\bin\Release\lib" +copy "%BUILD_PREFIX%\lib\renode-cores\*" "%SRC_DIR%\src\Infrastructure\src\Emulator\Cores\bin\Release\lib" + +rem Remove the C cores that are not built in this recipe +del "%SRC_DIR%\src\Infrastructure\src\Emulator\Cores\translate*.cproj" + +rem Build with dotnet +call powershell "%RECIPE_DIR%\helpers\renode_build_with_dotnet.ps1" %framework_version% + +rem Install procedure +mkdir "%PREFIX%\libexec\%PKG_NAME%" +xcopy /e /i /y "output\bin\Release\net%framework_version%\*" "%PREFIX%\libexec\%PKG_NAME%" + +mkdir "%PREFIX%\opt\%PKG_NAME%\scripts" +mkdir "%PREFIX%\opt\%PKG_NAME%\platforms" +mkdir "%PREFIX%\opt\%PKG_NAME%\tests" +mkdir "%PREFIX%\opt\%PKG_NAME%\tools" +mkdir "%PREFIX%\opt\%PKG_NAME%\licenses" + +copy ".renode-root" "%PREFIX%\opt\%PKG_NAME%" +xcopy /e /i /y "scripts\*" "%PREFIX%\opt\%PKG_NAME%\scripts" +xcopy /e /i /y "platforms\*" "%PREFIX%\opt\%PKG_NAME%\platforms" +xcopy /e /i /y "tests\*" "%PREFIX%\opt\%PKG_NAME%\tests" +xcopy /e /i /y "tools\metrics_analyzer" "%PREFIX%\opt\%PKG_NAME%\tools" +xcopy /e /i /y "tools\execution_tracer" "%PREFIX%\opt\%PKG_NAME%\tools" +xcopy /e /i /y "tools\gdb_compare" "%PREFIX%\opt\%PKG_NAME%\tools" +xcopy /e /i /y "tools\sel4_extensions" "%PREFIX%\opt\%PKG_NAME%\tools" + +copy "lib\resources\styles\robot.css" "%PREFIX%\opt\%PKG_NAME%\tests" + +call tools\packaging\common_copy_licenses.bat "%PREFIX%\opt\%PKG_NAME%\licenses" linux +xcopy /e /i /y "%PREFIX%\opt\%PKG_NAME%\licenses" "license-files" + +sed -i.bak "s#os\.path\.join(this_path, '\.\./lib/resources/styles/robot\.css')#os.path.join(this_path,'robot.css')#g" "%PREFIX%\opt\%PKG_NAME%\tests\robot_tests_provider.py" +del "%PREFIX%\opt\%PKG_NAME%\tests\robot_tests_provider.py.bak" + +mkdir "%PREFIX%\bin" +( +echo @echo off +echo call %%DOTNET_ROOT%%\dotnet exec %%CONDA_PREFIX%%\libexec\renode-cli\Renode.dll %%* +) > "%PREFIX%\bin\renode.cmd" +chmod +x "%PREFIX%\bin\renode.cmd" + +( +echo @echo off +echo setlocal enabledelayedexpansion +echo set "STTY_CONFIG=%%stty -g 2^>nul%%" +echo python3 "%%CONDA_PREFIX%%\opt\renode-cli\tests\run_tests.py" --robot-framework-remote-server-full-directory "%%CONDA_PREFIX%%\libexec\renode-cli" %%* +echo set "RESULT_CODE=%%ERRORLEVEL%%" +echo if not "%%STTY_CONFIG%%"=="" stty "%%STTY_CONFIG%%" +echo exit /b %%RESULT_CODE%% +) > "%PREFIX%\bin\renode-test.cmd" +chmod +x "%PREFIX%\bin\renode-test.cmd" \ No newline at end of file diff --git a/recipes/renode-cli/build.sh b/recipes/renode-cli/build.sh index 18fb773733841..db15bc6cd5885 100644 --- a/recipes/renode-cli/build.sh +++ b/recipes/renode-cli/build.sh @@ -28,9 +28,6 @@ cp ${BUILD_PREFIX}/lib/renode-cores/* ${SRC_DIR}/src/Infrastructure/src/Emulator # Remove the C cores that are not built in this recipe rm -f ${SRC_DIR}/src/Infrastructure/src/Emulator/Cores/translate*.cproj -# Add dynamic libraries framewkr -cp ${RECIPE_DIR}/helpers/DynamicLibraryLoader.{cs,csproj} ${SRC_DIR}/src/Renode - chmod +x tools/{building,packaging}/*.sh ${RECIPE_DIR}/helpers/renode_build_with_dotnet.sh ${framework_version} diff --git a/recipes/renode-cli/helpers/DynamicLibraryLoader.cs b/recipes/renode-cli/helpers/DynamicLibraryLoader.cs deleted file mode 100644 index 24a14a85df054..0000000000000 --- a/recipes/renode-cli/helpers/DynamicLibraryLoader.cs +++ /dev/null @@ -1,90 +0,0 @@ -using System; -using System.Runtime.InteropServices; - -public class DynamicLibraryLoader -{ - private IntPtr _libraryHandle; - private readonly string _libraryPath; - - public DynamicLibraryLoader(string libraryPath) - { - _libraryPath = libraryPath; -#if PLATFORM_WINDOWS - _libraryHandle = LoadLibrary(libraryPath); -#elif PLATFORM_LINUX || PLATFORM_OSX - _libraryHandle = dlopen(libraryPath, RTLD_NOW); -#endif - - if (_libraryHandle == IntPtr.Zero) - { - throw new Exception("Failed to load library: " + libraryPath); - } - } - - public void LoadLibrary(string libraryName) - { - var fullPath = System.IO.Path.Combine(_libraryPath, libraryName); -#if PLATFORM_WINDOWS - _libraryHandle = LoadLibrary(fullPath); -#elif PLATFORM_LINUX || PLATFORM_OSX - _libraryHandle = dlopen(fullPath, RTLD_NOW); -#endif - - if (_libraryHandle == IntPtr.Zero) - { - throw new Exception("Failed to load library: " + fullPath); - } - } - - public T GetFunctionDelegate(string functionName) where T : Delegate - { - IntPtr functionAddress = IntPtr.Zero; - -#if PLATFORM_WINDOWS - functionAddress = GetProcAddress(_libraryHandle, functionName); -#elif PLATFORM_LINUX || PLATFORM_OSX - functionAddress = dlsym(_libraryHandle, functionName); -#endif - - if (functionAddress == IntPtr.Zero) - { - throw new Exception("Failed to get function address: " + functionName); - } - - return Marshal.GetDelegateForFunctionPointer(functionAddress); - } - - ~DynamicLibraryLoader() - { - if (_libraryHandle != IntPtr.Zero) - { -#if PLATFORM_WINDOWS - FreeLibrary(_libraryHandle); -#elif PLATFORM_LINUX || PLATFORM_OSX - dlclose(_libraryHandle); -#endif - } - } - -#if PLATFORM_WINDOWS - [DllImport("kernel32.dll", SetLastError = true)] - private static extern IntPtr LoadLibrary(string dllToLoad); - - [DllImport("kernel32.dll", SetLastError = true)] - private static extern IntPtr GetProcAddress(IntPtr hModule, string procedureName); - - [DllImport("kernel32.dll", SetLastError = true)] - private static extern bool FreeLibrary(IntPtr hModule); -#elif PLATFORM_LINUX || PLATFORM_OSX - [DllImport("libdl.so")] - private static extern IntPtr dlopen(string fileName, int flags); - - [DllImport("libdl.so")] - private static extern IntPtr dlsym(IntPtr handle, string symbol); - - [DllImport("libdl.so")] - private static extern int dlclose(IntPtr handle); - - private const int RTLD_NOW = 2; -#endif -} \ No newline at end of file diff --git a/recipes/renode-cli/helpers/DynamicLibraryLoader.csproj b/recipes/renode-cli/helpers/DynamicLibraryLoader.csproj deleted file mode 100644 index 06e242781a69e..0000000000000 --- a/recipes/renode-cli/helpers/DynamicLibraryLoader.csproj +++ /dev/null @@ -1,19 +0,0 @@ - - - net8.0 - 7.3 - $(DefineConstants);PLATFORM_LINUX - false - - - $(DefineConstants);PLATFORM_WINDOWS - - - - $(DefineConstants);PLATFORM_OSX - - - - - - \ No newline at end of file diff --git a/recipes/renode-cli/helpers/renode_build_with_dotnet.ps1 b/recipes/renode-cli/helpers/renode_build_with_dotnet.ps1 new file mode 100755 index 0000000000000..062bf49f6b339 --- /dev/null +++ b/recipes/renode-cli/helpers/renode_build_with_dotnet.ps1 @@ -0,0 +1,83 @@ +#!/usr/bin/env pwsh + +param ( + [string]$framework_version +) + +$OUTPUT_DIRECTORY = "${env:SRC_DIR}/output" +$CONFIGURATION = "Release" +$BUILD_PLATFORM = "Any CPU" +$HEADLESS = $true +$NET = $true +$TFM = "net$framework_version" +$HOST_ARCH = "i386" +$CMAKE_COMMON = "" + +$PARAMS = @() +if ($env:CC) { + $PARAMS += "p:CompilerPath=$env:CC" + $PARAMS += "p:LinkerPath=$env:CC" +} +if ($env:AR) { + $PARAMS += "p:ArPath=$env:AR" +} +$PARAMS += $args + +if ($HEADLESS) { + $BUILD_TARGET = "Headless" + $PARAMS += "p:GUI_DISABLED=true" +} else { + $BUILD_TARGET = "Mono" +} + +$DirectoryBuildTargetsContent = @" + + + $TFM + ${env:OS_SPECIFIC_TARGET_OPTS} + + +"@ + +$DirectoryBuildTargetsPath = "${env:SRC_DIR}/Directory.Build.targets" +Set-Content -Path $DirectoryBuildTargetsPath -Value $DirectoryBuildTargetsContent + +$env:DOTNET_CLI_TELEMETRY_OPTOUT = 1 +$CS_COMPILER = "dotnet build" +$TARGET = "${env:SRC_DIR}/Renode_NET.sln" +$BUILD_TYPE = "dotnet" + +$OUT_BIN_DIR = "${env:SRC_DIR}/output/bin/$CONFIGURATION" +$BUILD_TYPE_FILE = "$OUT_BIN_DIR/build_type" + +# Copy properties file according to the running OS +New-Item -ItemType Directory -Force -Path $OUTPUT_DIRECTORY +Remove-Item -Force -Path "$OUTPUT_DIRECTORY/properties.csproj" +$PROP_FILE = "${env:CURRENT_PATH:=.}/src/Infrastructure/src/Emulator/Cores/linux-properties.csproj" +Copy-Item -Path $PROP_FILE -Destination "$OUTPUT_DIRECTORY/properties.csproj" + +$CORES_PATH = "${env:SRC_DIR}/src/Infrastructure/src/Emulator/Cores" + +$PARAMS += "p:Configuration=${CONFIGURATION}${BUILD_TARGET}" +$PARAMS += "p:GenerateFullPaths=true" +$PARAMS += "p:Platform=`"$BUILD_PLATFORM`"" + +# build +function Build-Args-Helper { + param ( + [string[]]$params + ) + $retStr = "" + foreach ($p in $params) { + $retStr += " -$p" + } + return $retStr +} + +Invoke-Expression "$CS_COMPILER $(Build-Args-Helper -params $PARAMS) $TARGET" +Set-Content -Path $BUILD_TYPE_FILE -Value $BUILD_TYPE + +# copy llvm library +$LLVM_LIB = "libllvm-disas" +$LIB_EXT = "dll" +Copy-Item -Path "lib/resources/llvm/$LLVM_LIB.$LIB_EXT" -Destination "$OUT_BIN_DIR/libllvm-disas.$LIB_EXT" diff --git a/recipes/renode-cli/helpers/renode_build_with_dotnet.sh b/recipes/renode-cli/helpers/renode_build_with_dotnet.sh index 74221d2815424..03d4ab52b76c9 100755 --- a/recipes/renode-cli/helpers/renode_build_with_dotnet.sh +++ b/recipes/renode-cli/helpers/renode_build_with_dotnet.sh @@ -12,9 +12,6 @@ BUILD_PLATFORM="Any CPU" HEADLESS=true NET=true TFM="net${framework_version}" -GENERATE_DOTNET_BUILD_TARGET=true -NET_FRAMEWORK_VER= -RID="linux-x64" HOST_ARCH="i386" # Common cmake flags CMAKE_COMMON="" @@ -61,7 +58,8 @@ if [[ "${target_platform}" == "osx-"* ]]; then elif [[ "${target_platform}" == "linux-"* ]] || [[ "${target_platform}" == "noarch" ]]; then PROP_FILE="${CURRENT_PATH:=.}/src/Infrastructure/src/Emulator/Cores/linux-properties.csproj" else - PROP_FILE="${CURRENT_PATH:=.}/src/Infrastructure/src/Emulator/Cores/windows-properties.csproj" + echo "Unsupported platform: ${target_platform}" + exit 1 fi cp "$PROP_FILE" "$OUTPUT_DIRECTORY/properties.csproj" @@ -73,11 +71,7 @@ PARAMS+=(p:Configuration=${CONFIGURATION}${BUILD_TARGET} p:GenerateFullPaths=tru function build_args_helper() { local retStr="" for p in "$@" ; do - if [ "$CS_COMPILER" = 'xbuild' ] ; then - retStr="${retStr} /$p" - else - retStr="${retStr} -$p" - fi + retStr="${retStr} -$p" done echo ${retStr} } diff --git a/recipes/renode-cli/patches/update-dynamic-Program.cs.patch b/recipes/renode-cli/patches/update-dynamic-Program.cs.patch deleted file mode 100644 index c47b3a31aa651..0000000000000 --- a/recipes/renode-cli/patches/update-dynamic-Program.cs.patch +++ /dev/null @@ -1,45 +0,0 @@ ---- a/src/Renode/Program.cs 2025-01-30 11:54:45.389351518 -0600 -+++ b/src/Renode/Program.cs 2025-01-30 11:34:18.393137972 -0600 -@@ -11,2 +11,3 @@ - using System.IO; -+using System.Runtime.InteropServices; - using System; -@@ -45,2 +45,32 @@ - */ -+ -+ // Load dynamic libraries -+ var libraryDirectory = Environment.GetEnvironmentVariable("RENODE_CORES_PATH") ?? "../src/Infrastructure/src/Emulator/Cores/bin/Release/lib"; -+ var libraryFiles = Directory.GetFiles(libraryDirectory, "translate-*.so"); -+ var libraries = new string[] -+ { -+ "translate-arm-be.so", -+ "translate-arm-le.so", -+ "translate-arm-m-be.so", -+ "translate-arm-m-le.so", -+ "translate-arm64-le.so", -+ "translate-i386-le.so", -+ "translate-ppc-be.so", -+ "translate-ppc-le.so", -+ "translate-ppc64-be.so", -+ "translate-ppc64-le.so", -+ "translate-riscv-le.so", -+ "translate-riscv64-le.so", -+ "translate-sparc-be.so", -+ "translate-sparc-le.so", -+ "translate-x86_64-le.so", -+ "translate-xtensa-le.so", -+ }; -+ -+ var loader = new DynamicLibraryLoader(libraryDirectory); -+ foreach (var library in libraries) -+ { -+ loader.LoadLibrary(library); -+ } -+ - Core.EmulationManager.RebuildInstance(); -@@ -132,2 +162,5 @@ - } -+ -+ [UnmanagedFunctionPointer(CallingConvention.Cdecl)] -+ private delegate int FunctionDelegate(int a, int b); - } diff --git a/recipes/renode-cli/patches/update-dynamic-Renode_NET.csproj.patch b/recipes/renode-cli/patches/update-dynamic-Renode_NET.csproj.patch deleted file mode 100644 index 88033a578b5d7..0000000000000 --- a/recipes/renode-cli/patches/update-dynamic-Renode_NET.csproj.patch +++ /dev/null @@ -1,9 +0,0 @@ ---- a/src/Renode/Renode_NET.csproj 2024-09-17 05:28:40.000000000 -0500 -+++ b/src/Renode/Renode_NET.csproj 2025-01-30 11:47:34.648017897 -0600 -@@ -14,1 +14,1 @@ -- 7.2 -+ 7.3 -@@ -45,2 +45,3 @@ - -+ - diff --git a/recipes/renode-cli/patches/update-dynamic-cores.template_NET.csproj.patch b/recipes/renode-cli/patches/update-dynamic-cores.template_NET.csproj.patch deleted file mode 100644 index e175485998989..0000000000000 --- a/recipes/renode-cli/patches/update-dynamic-cores.template_NET.csproj.patch +++ /dev/null @@ -1,15 +0,0 @@ ---- a/src/Infrastructure/src/Emulator/Cores/cores.template_NET.csproj 2024-09-17 05:29:16.000000000 -0500 -+++ b/src/Infrastructure/src/Emulator/Cores/cores.template_NET.csproj 2025-01-27 21:35:32.396468884 -0600 -@@ -15,12 +16,2 @@ - -- -- -- -- Antmicro.Renode.translate-$(Architecture)-le.so -- -- -- Antmicro.Renode.translate-$(Architecture)-be.so -- -- -- - \ No newline at end of file diff --git a/recipes/renode-cli/patches/update-for-cmake-build.sh.patch b/recipes/renode-cli/patches/update-for-cmake-build.sh.patch deleted file mode 100644 index a9f480f68bc3d..0000000000000 --- a/recipes/renode-cli/patches/update-for-cmake-build.sh.patch +++ /dev/null @@ -1,367 +0,0 @@ ---- /home/memento/PycharmProjects/staged-recipes-2/build_artifacts/src_cache/v1_15_3_692604eb/build.sh 2024-09-17 03:09:19.000000000 -0500 -+++ build.new.sh 2025-01-24 15:30:24.984659038 -0600 -@@ -18,4 +18,8 @@ - SKIP_FETCH=false -+TLIB_ONLY=false -+TLIB_EXPORT_COMPILE_COMMANDS=false -+TLIB_ARCH="" - NET=false --TFM="net6.0" -+TFM="net8.0" -+GENERATE_DOTNET_BUILD_TARGET=true - PARAMS=() -@@ -24,5 +28,8 @@ - RID="linux-x64" -+HOST_ARCH="i386" -+# Common cmake flags -+CMAKE_COMMON="" - - function print_help() { -- echo "Usage: $0 [-cdvspnt] [-b properties-file.csproj] [--no-gui] [--skip-fetch] [--profile-build] [-- ]" -+ echo "Usage: $0 [-cdvspnt] [-b properties-file.csproj] [--no-gui] [--skip-fetch] [--profile-build] [--tlib-only] [--tlib-export-compile-commands] [--tlib-arch ] [--host-arch i386|aarch64] [-- ]" - echo -@@ -42,3 +49,9 @@ - echo "-B bundle target runtime (default value: $RID, requires --net, -t)" -- echo "--profile-build build optimized for tlib profiling" -+ echo "-F select the target framework for which Renode should be built (default value: $TFM)" -+ echo "--profile-build build optimized for profiling" -+ echo "--tlib-only only build tlib" -+ echo "--tlib-arch build only single arch (implies --tlib-only)" -+ echo "--tlib-export-compile-commands build tlibs with 'compile_commands.json' (requires --tlib-arch)" -+ echo "--host-arch build with a specific tcg host architecture (default: i386)" -+ echo "--skip-dotnet-target-generation don't generate 'Directory.Build.targets' file, useful when experimenting with different build settings" - echo " arguments to pass to the build system" -@@ -46,3 +59,3 @@ - --while getopts "cdvpnstb:o:B:-:" opt -+while getopts "cdvpnstb:o:B:F:a:-:" opt - do -@@ -81,2 +94,9 @@ - ;; -+ F) -+ if ! $NET; then -+ echo "-F requires --net being set" -+ exit 1 -+ fi -+ TFM=$OPTARG -+ ;; - -) -@@ -100,3 +120,28 @@ - "profile-build") -- PARAMS+=('p:TlibProfilingBuild=true') -+ CMAKE_COMMON="-DPROFILING_BUILD=ON" -+ ;; -+ "tlib-only") -+ TLIB_ONLY=true -+ ;; -+ "tlib-arch") -+ # This only makes sense with '--tlib-only' set; it might as well imply it -+ TLIB_ONLY=true -+ shift $((OPTIND-1)) -+ TLIB_ARCH=$1 -+ OPTIND=2 -+ ;; -+ "tlib-export-compile-commands") -+ if [ -z $TLIB_ARCH ]; then -+ echo "--tlib-export-compile-commands requires --tlib-arch begin set" -+ exit 1 -+ fi -+ TLIB_EXPORT_COMPILE_COMMANDS=true -+ ;; -+ "host-arch") -+ shift $((OPTIND-1)) -+ HOST_ARCH=$1 -+ OPTIND=2 -+ ;; -+ "skip-dotnet-target-generation") -+ GENERATE_DOTNET_BUILD_TARGET=false - ;; -@@ -184,3 +229,4 @@ - BUILD_TARGET=Windows -- TFM="net6.0-windows10.0.17763.0" -+ TFM="$TFM-windows10.0.17763.0" -+ RID="win-x64" - else -@@ -189,10 +235,34 @@ - -+if [[ $GENERATE_DOTNET_BUILD_TARGET = true ]]; then -+ if $ON_WINDOWS; then -+ # CsWinRTAotOptimizerEnabled is disabled due to a bug in dotnet-sdk. -+ # See: https://github.com/dotnet/sdk/issues/44026 -+ OS_SPECIFIC_TARGET_OPTS='false' -+ fi -+ -+cat < "$(get_path "$PWD/Directory.Build.targets")" -+ -+ -+ $TFM -+ ${OS_SPECIFIC_TARGET_OPTS:+${OS_SPECIFIC_TARGET_OPTS}} -+ -+ -+EOF -+ -+fi -+ - if $NET - then -+ export DOTNET_CLI_TELEMETRY_OPTOUT=1 - CS_COMPILER="dotnet build" - TARGET="`get_path \"$PWD/Renode_NET.sln\"`" -+ BUILD_TYPE="dotnet" - else - TARGET="`get_path \"$PWD/Renode.sln\"`" -+ BUILD_TYPE="mono" - fi - -+OUT_BIN_DIR="$(get_path "output/bin/${CONFIGURATION}")" -+BUILD_TYPE_FILE=$(get_path "${OUT_BIN_DIR}/build_type") -+ - # Verify Mono and mcs version on Linux and macOS -@@ -203,3 +273,3 @@ - MINIMUM_MONO=`get_min_mono_version` -- echo "mcs not found. Renode requries Mono $MINIMUM_MONO or newer. Please refer to documentation for installation instructions. Exiting!" -+ echo "mcs not found. Renode requires Mono $MINIMUM_MONO or newer. Please refer to documentation for installation instructions. Exiting!" - exit 1 -@@ -237,20 +307,3 @@ - --# Build CCTask in Release configuration --CCTASK_OUTPUT=`mktemp` --CCTASK_BUILD_ARGS=($NET_FRAMEWORK_VER p:Configuration=Release p:Platform="\"$BUILD_PLATFORM\"") --set +e --CCTASK_SLN=CCTask.sln --if $NET --then -- CCTASK_SLN=CCTask_NET.sln --fi --eval "$CS_COMPILER $(build_args_helper "${CCTASK_BUILD_ARGS[@]}") $(get_path $ROOT_PATH/lib/cctask/$CCTASK_SLN)" 2>&1 > $CCTASK_OUTPUT -- --if [ $? -ne 0 ]; then -- cat $CCTASK_OUTPUT -- rm $CCTASK_OUTPUT -- exit 1 --fi --rm $CCTASK_OUTPUT --set -e -+CORES_PATH="$ROOT_PATH/src/Infrastructure/src/Emulator/Cores" - -@@ -259,19 +312,22 @@ - then -- if ! $NET -- then -- PARAMS+=(t:Clean) -- fi -- for conf in Debug Release -+ for project_dir in $(find "$(get_path "${ROOT_PATH}/src")" -iname '*.csproj' -exec dirname '{}' \;) - do -- for build_target in Windows Mono Headless -+ for dir in {bin,obj}/{Debug,Release} - do -- if $NET -+ output_dir="$(get_path "${project_dir}/${dir}")" -+ if [[ -d "${output_dir}" ]] - then -- dotnet clean $(build_args_helper ${PARAMS[@]}) $(build_args_helper p:Configuration=${conf}${build_target}) "$TARGET" -- else -- $CS_COMPILER $(build_args_helper ${PARAMS[@]}) $(build_args_helper p:Configuration=${conf}${build_target}) "$TARGET" -+ echo "Removing: ${output_dir}" -+ rm -rf "${output_dir}" - fi - done -- rm -fr $OUTPUT_DIRECTORY/bin/$conf - done -+ -+ # Manually clean the main output directory as it's location is non-standard -+ main_output_dir="$(get_path "${OUTPUT_DIRECTORY}/bin")" -+ if [[ -d "${main_output_dir}" ]] -+ then -+ echo "Removing: ${main_output_dir}" -+ rm -rf "${main_output_dir}" -+ fi - exit 0 -@@ -279,2 +335,13 @@ - -+# Check if a full rebuild is needed -+if [[ -f "$BUILD_TYPE_FILE" ]] -+then -+ if [[ "$(cat "$BUILD_TYPE_FILE")" != "$BUILD_TYPE" ]] -+ then -+ echo "Attempted to build Renode in a different configuration than the previous build" -+ echo "Please run '$0 -c' to clean the previous build before continuing" -+ exit 1 -+ fi -+fi -+ - # check weak implementations of core libraries -@@ -286,12 +353,105 @@ - -+# Paths for tlib -+CORES_BUILD_PATH="$CORES_PATH/obj/$CONFIGURATION" -+CORES_BIN_PATH="$CORES_PATH/bin/$CONFIGURATION" -+ -+# Cmake generator, handled in their own variable since the names contain spaces -+if $ON_WINDOWS -+then -+ CMAKE_GEN="-GMinGW Makefiles" -+else -+ CMAKE_GEN="-GUnix Makefiles" -+fi -+ -+# Macos architecture flags, to make rosetta work properly -+if $ON_OSX -+then -+ CMAKE_COMMON+=" -DCMAKE_OSX_ARCHITECTURES=x86_64" -+ if [ $HOST_ARCH == "aarch64" ]; then -+ CMAKE_COMMON+=" -DCMAKE_OSX_ARCHITECTURES=arm64" -+ fi -+fi -+ -+# This list contains all cores that will be built. -+# If you are adding a new core or endianness add it here to have the correct tlib built -+CORES=(arm.le arm.be arm64.le arm-m.le arm-m.be ppc.le ppc.be ppc64.le ppc64.be i386.le x86_64.le riscv.le riscv64.le sparc.le sparc.be xtensa.le) -+ -+# if '--tlib-arch' was used - pick the first matching one -+if [[ ! -z $TLIB_ARCH ]]; then -+ NONE_MATCHED=true -+ for potential_match in "${CORES[@]}"; do -+ if [[ $potential_match == "$TLIB_ARCH"* ]]; then -+ CORES=($potential_match) -+ echo "Compiling tlib for $potential_match" -+ NONE_MATCHED=false -+ break -+ fi -+ done -+ if $NONE_MATCHED ; then -+ echo "Failed to match any tlib arch" -+ exit 1 -+ fi -+fi -+ -+# build tlib -+for core_config in "${CORES[@]}" -+do -+ CORE="$(echo $core_config | cut -d '.' -f 1)" -+ ENDIAN="$(echo $core_config | cut -d '.' -f 2)" -+ BITS=32 -+ # Check if core is 64-bit -+ if [[ $CORE =~ "64" ]]; then -+ BITS=64 -+ fi -+ # Core specific flags to cmake -+ CMAKE_CONF_FLAGS="-DTARGET_ARCH=$CORE -DTARGET_WORD_SIZE=$BITS -DCMAKE_BUILD_TYPE=$CONFIGURATION" -+ CORE_DIR=$CORES_BUILD_PATH/$CORE/$ENDIAN -+ mkdir -p $CORE_DIR -+ pushd "$CORE_DIR" > /dev/null -+ if [[ $ENDIAN == "be" ]]; then -+ CMAKE_CONF_FLAGS+=" -DTARGET_BIG_ENDIAN=1" -+ fi -+ if [[ "$TLIB_EXPORT_COMPILE_COMMANDS" = true ]]; then -+ CMAKE_CONF_FLAGS+=" -DCMAKE_EXPORT_COMPILE_COMMANDS=1" -+ fi -+ cmake "$CMAKE_GEN" $CMAKE_COMMON $CMAKE_CONF_FLAGS -DHOST_ARCH=$HOST_ARCH $CORES_PATH -+ cmake --build . -+ CORE_BIN_DIR=$CORES_BIN_PATH/lib -+ mkdir -p $CORE_BIN_DIR -+ if $ON_OSX; then -+ # macos `cp` does not have the -u flag -+ cp -v tlib/*.so $CORE_BIN_DIR/ -+ else -+ cp -u -v tlib/*.so $CORE_BIN_DIR/ -+ fi -+ # copy compile_commands.json to tlib directory -+ if [[ "$TLIB_EXPORT_COMPILE_COMMANDS" = true ]]; then -+ command cp -v -f $CORE_DIR/compile_commands.json $CORES_PATH/tlib/ -+ fi -+ popd > /dev/null -+done -+ -+if $TLIB_ONLY -+then -+ exit 0 -+fi -+ - # build - eval "$CS_COMPILER $(build_args_helper "${PARAMS[@]}") $TARGET" -+echo -n "$BUILD_TYPE" > "$BUILD_TYPE_FILE" - - # copy llvm library --if $NET --then -- cp src/Infrastructure/src/Emulator/Peripherals/bin/$CONFIGURATION/$TFM/libllvm-disas.* output/bin/$CONFIGURATION/$TFM -+LLVM_LIB="libllvm-disas" -+if [[ $HOST_ARCH == "aarch64" ]]; then -+ # aarch64 host binaries have a different name -+ LLVM_LIB="libllvm-disas-aarch64" -+fi -+if [[ "${DETECTED_OS}" == "windows" ]]; then -+ LIB_EXT="dll" -+elif [[ "${DETECTED_OS}" == "osx" ]]; then -+ LIB_EXT="dylib" - else -- cp src/Infrastructure/src/Emulator/Peripherals/bin/$CONFIGURATION/libllvm-disas.* output/bin/$CONFIGURATION -+ LIB_EXT="so" - fi -+cp lib/resources/llvm/$LLVM_LIB.$LIB_EXT $OUT_BIN_DIR/libllvm-disas.$LIB_EXT - -@@ -326,11 +486,24 @@ - then -- # Restore dependecies for linux-x64 runtime. It prevents error NETSDK1112 during publish. -- dotnet restore --runtime linux-x64 Renode_NET.sln -- -- eval "dotnet publish -f $TFM --self-contained false $(build_args_helper "${PARAMS[@]}") $TARGET" -- export RID TFM -- $ROOT_PATH/tools/packaging/make_linux_dotnet_package.sh $params -+ # dotnet package on linux uses a separate script -+ if $ON_LINUX -+ then -+ # maxcpucount:1 to avoid an error with multithreaded publish -+ eval "dotnet publish -maxcpucount:1 -f $TFM --self-contained false $(build_args_helper "${PARAMS[@]}") $TARGET" -+ export RID TFM -+ $ROOT_PATH/tools/packaging/make_linux_dotnet_package.sh $params -+ # Source package bundles nuget dependencies required for building the dotnet version of Renode -+ # so it can only be built when using dotnet. The generated package can also be used with Mono/.NETFramework -+ $ROOT_PATH/tools/packaging/make_source_package.sh $params -+ elif $ON_WINDOWS && ! $PORTABLE -+ then -+ # No Non portable dotnet package on windows yet -+ echo "Only portable dotnet packages are supported on windows. Rerun build.sh with -t flag to build portable" -+ exit 1 -+ elif $ON_OSX -+ then -+ echo "dotnet packages not supported on ${DETECTED_OS}" -+ exit 1 -+ fi - else - $ROOT_PATH/tools/packaging/make_${DETECTED_OS}_packages.sh $params -- $ROOT_PATH/tools/packaging/make_source_package.sh $params - fi -@@ -341,16 +514,17 @@ - PARAMS+=(p:PORTABLE=true) -- if $ON_LINUX -+ if $NET - then -- if $NET -- then -- eval "dotnet publish -r $RID -f $TFM --self-contained true $(build_args_helper "${PARAMS[@]}") $TARGET" -- export RID TFM -- $ROOT_PATH/tools/packaging/make_linux_portable_dotnet.sh $params -- else -- $ROOT_PATH/tools/packaging/make_linux_portable.sh $params -- fi -+ # maxcpucount:1 to avoid an error with multithreaded publish -+ eval "dotnet publish -maxcpucount:1 -r $RID -f $TFM --self-contained true $(build_args_helper "${PARAMS[@]}") $TARGET" -+ export RID TFM -+ $ROOT_PATH/tools/packaging/make_${DETECTED_OS}_portable_dotnet.sh $params - else -- echo "Portable packages are only available on Linux. Exiting!" -- exit 1 -+ if $ON_LINUX -+ then -+ $ROOT_PATH/tools/packaging/make_linux_portable.sh $params -+ else -+ echo "Portable packages for Mono are only available on Linux. Exiting!" -+ exit 1 -+ fi - fi --fi -+fi -\ No newline at end of file diff --git a/recipes/renode-cli/recipe.yaml b/recipes/renode-cli/recipe.yaml index 2db6df7333d3e..25c7a5b9e9b76 100644 --- a/recipes/renode-cli/recipe.yaml +++ b/recipes/renode-cli/recipe.yaml @@ -14,17 +14,12 @@ source: - if: unix then: - patches/update-IronPython-Renode_NET.csproj.patch - - patches/update-for-cmake-build.sh.patch - patches/update-cores.template_NET.csproj.patch - patches/update-IronPython-Unittest_NET.csproj.patch - patches/resolve-posix-unix.patch - - patches/update-dynamic-cores.template_NET.csproj.patch - - patches/update-dynamic-Program.cs.patch - - patches/update-dynamic-Renode_NET.csproj.patch build: number: 0 - noarch: generic requirements: build: @@ -32,7 +27,9 @@ requirements: - git - nuget-license - renode-cores ==${{ version }} - - sed + - if: unix + then: sed + else: m2-sed host: - dotnet run: @@ -43,7 +40,7 @@ tests: bin: - renode - renode.cmd - # fails, why? - renode-test + - renode-test - script: - renode --help - renode-test ${PREFIX}/opt/renode-cli/tests/unit-tests diff --git a/recipes/renode-cores/build.bat b/recipes/renode-cores/build.bat index 6dca6024a10b2..df6c841b39587 100644 --- a/recipes/renode-cores/build.bat +++ b/recipes/renode-cores/build.bat @@ -3,11 +3,13 @@ setlocal EnableDelayedExpansion rem Update the submodule to the latest commit CMakeLists.txt -copy "%RECIPE_DIR%\patches\Cores-CMakeLists.txt" "%SRC_DIR%\src\Infrastructure\src\Emulator\Cores\CMakeLists.txt" -copy "%RECIPE_DIR%\patches\tlib-CMakeLists.txt" "%SRC_DIR%\src\Infrastructure\src\Emulator\Cores\tlib\CMakeLists.txt" +set "CMAKEFILES_TXT=src\Emulator\Cores\CMakeLists.txt" +copy "cmake-renode-infrastructure\${CMAKEFILES_TXT}" "${SRC_DIR}\src\Infrastructure\${CMAKEFILES_TXT}" +copy "cmake-tlib\CMakeLists.txt" "${SRC_DIR}\src\Infrastructure\src\Emulator\Cores\tlib" +copy "cmake-tlib\tcg\CMakeLists.txt" "${SRC_DIR}\src\Infrastructure\src\Emulator\Cores\tlib\tcg" if %errorlevel% neq 0 exit /b %errorlevel% -powershell -ExecutionPolicy Bypass -File "%RECIPE_DIR%\helpers\renode_build_with_cmake.ps1" --tlib-only --net --no-gui +powershell -ExecutionPolicy Bypass -File "%RECIPE_DIR%\helpers\renode_build_with_cmake.ps1" if %errorlevel% neq 0 exit /b %errorlevel% rem Install procedure into a conda path that renode-cli can retrieve diff --git a/recipes/renode-cores/build.sh b/recipes/renode-cores/build.sh index c1205c6751492..48608c3ee7979 100644 --- a/recipes/renode-cores/build.sh +++ b/recipes/renode-cores/build.sh @@ -2,12 +2,14 @@ set -o xtrace -o nounset -o pipefail -o errexit -# Update the submodule to the latest commit CMakeLists.txt -cp ${RECIPE_DIR}/patches/Cores-CMakeLists.txt ${SRC_DIR}/src/Infrastructure/src/Emulator/Cores/CMakeLists.txt -cp ${RECIPE_DIR}/patches/tlib-CMakeLists.txt ${SRC_DIR}/src/Infrastructure/src/Emulator/Cores/tlib/CMakeLists.txt +# Update the submodule CMakeLists.txt with a recent version (post-CMake conversion) +CMAKEFILES_TXT="src/Emulator/Cores/CMakeLists.txt" +cp "cmake-renode-infrastructure/${CMAKEFILES_TXT}" "${SRC_DIR}/src/Infrastructure/${CMAKEFILES_TXT}" +cp cmake-tlib/CMakeLists.txt "${SRC_DIR}/src/Infrastructure/src/Emulator/Cores/tlib" +cp cmake-tlib/tcg/CMakeLists.txt "${SRC_DIR}/src/Infrastructure/src/Emulator/Cores/tlib/tcg" chmod +x build.sh tools/building/check_weak_implementations.sh -${RECIPE_DIR}/helpers/renode_build_with_cmake.sh --tlib-only --net --no-gui +${RECIPE_DIR}/helpers/renode_build_with_cmake.sh # Install procedure into a conda path that renode-cli can retrieve CONFIGURATION="Release" diff --git a/recipes/renode-cores/helpers/renode_build_with_cmake.ps1 b/recipes/renode-cores/helpers/renode_build_with_cmake.ps1 index 4e9781940b794..44758a06c6931 100755 --- a/recipes/renode-cores/helpers/renode_build_with_cmake.ps1 +++ b/recipes/renode-cores/helpers/renode_build_with_cmake.ps1 @@ -1,8 +1,5 @@ $ErrorActionPreference = "Stop" -$ValidArgs = @("-v", "--no-gui", "--net", "--tlib-only") -$PassedArgs = $args.Where({$ValidArgs -contains $_}) - $cpuCount = (Get-CimInstance Win32_Processor).NumberOfLogicalProcessors $env:PATH = "${env:BUILD_PREFIX}/Library/mingw-w64/bin;${env:BUILD_PREFIX}/Library/bin;${env:PREFIX}/Library/bin;${env:PREFIX}/bin;${env:PATH}" @@ -11,63 +8,9 @@ $env:SRC_DIR = $env:SRC_DIR $CMAKE = (Get-Command cmake).Source $CONFIGURATION = "Release" -$HEADLESS = $false -$TLIB_ONLY = $false -$NET = $false $HOST_ARCH = "i386" $CMAKE_COMMON = "" -function print_help { - Write-Host "Usage: $0 [-cdvspnt] [-b properties-file.csproj] [--no-gui] [--skip-fetch] [--profile-build] [--tlib-only] [--tlib-export-compile-commands] [--tlib-arch ] [--host-arch i386|aarch64] [-- ]" - Write-Host - Write-Host "-v verbose output" - Write-Host "--no-gui build with GUI disabled" - Write-Host "--net build with dotnet" - Write-Host "--tlib-only only build tlib" - Write-Host " arguments to pass to the build system" -} - -while ($opts.Count -gt 0) { - $opt = $opts[0] - switch -regex ($opt) { - "-v" { - $opts = $opts[1..$($opts.Count - 1)] - } - "--no-gui" { - $HEADLESS = $true - $opts = $opts[1..$($opts.Count - 1)] - } - "--net" { - $NET = $true - $opts = $opts[1..$($opts.Count - 1)] - } - "--tlib-only" { - $TLIB_ONLY = $true - $opts = $opts[1..$($opts.Count - 1)] - } - default { - print_help - exit 1 - } - } -} - -if ($env:PLATFORM) { - Write-Host "PLATFORM environment variable is currently set to: >>$env:PLATFORM<<" - Write-Host "This might cause problems during the build." - Write-Host "Please clear it with:" - Write-Host - Write-Host " unset PLATFORM" - Write-Host - Write-Host " and run the build script again." - exit 1 -} - -if ($HEADLESS) { - Write-Host "Headless build" - $BUILD_TARGET = "Headless" -} - $CORES_PATH = Join-Path -Path $env:SRC_DIR -ChildPath "src\Infrastructure\src\Emulator\Cores" Push-Location "$env:SRC_DIR\tools\building" diff --git a/recipes/renode-cores/helpers/renode_build_with_cmake.sh b/recipes/renode-cores/helpers/renode_build_with_cmake.sh index 7bc46311260f4..759d14393d4e8 100755 --- a/recipes/renode-cores/helpers/renode_build_with_cmake.sh +++ b/recipes/renode-cores/helpers/renode_build_with_cmake.sh @@ -1,76 +1,11 @@ #!/usr/bin/env bash -set -u -set -e +set -o xtrace -o nounset -o pipefail -o errexit CONFIGURATION="Release" -HEADLESS=false -TLIB_ONLY=false -NET=false HOST_ARCH="i386" CMAKE_COMMON="" -function print_help() { - echo "Usage: $0 [--no-gui] [--net] [--tlib-only] [--host-arch i386|aarch64] [-- ]" - echo - echo "--no-gui build with GUI disabled" - echo "--net build with dotnet" - echo "--tlib-only only build tlib" - echo "--host-arch specify host architecture (i386 or aarch64)" - echo " arguments to pass to the build system" -} - -OPTIONS=$(getopt -o vhnt: -l "no-gui,net,tlib-only,host-arch:" -n "$0" -- "$@") -eval set -- "$OPTIONS" - -while true; do - case $1 in - --no-gui) - HEADLESS=true - shift - ;; - --net) - NET=true - shift - ;; - --tlib-only) - TLIB_ONLY=true - shift - ;; - --host-arch) - shift - HOST_ARCH=$1 - shift - ;; - --) - shift - break - ;; - *) - print_help - exit 1 - ;; - esac -done - -if [ -n "${PLATFORM:-}" ] -then - echo "PLATFORM environment variable is currently set to: >>$PLATFORM<<" - echo "This might cause problems during the build." - echo "Please clear it with:" - echo "" - echo " unset PLATFORM" - echo "" - echo " and run the build script again." - - exit 1 -fi - -if $HEADLESS -then - BUILD_TARGET=Headless -fi - # check weak implementations of core libraries pushd "${SRC_DIR}/tools/building" > /dev/null ./check_weak_implementations.sh @@ -88,6 +23,7 @@ if [[ "${target_platform}" == "osx-64" ]]; then CMAKE_COMMON+=" -DCMAKE_OSX_ARCHITECTURES=x86_64" fi if [[ "${target_platform}" == "osx-arm64" ]]; then + HOST_ARCH="aarch64" CMAKE_COMMON+=" -DCMAKE_OSX_ARCHITECTURES=arm64" fi diff --git a/recipes/renode-cores/patches/Cores-CMakeLists.txt b/recipes/renode-cores/patches/Cores-CMakeLists.txt deleted file mode 100644 index 6570fa08b1d85..0000000000000 --- a/recipes/renode-cores/patches/Cores-CMakeLists.txt +++ /dev/null @@ -1,39 +0,0 @@ -cmake_minimum_required(VERSION 3.12) - -project (renode-cores LANGUAGES C) - -add_subdirectory(tlib) - -# Add Renode sources to tlib target so that they get built as part of it - -if(NOT TARGET_ACTUAL_ARCH) - message(FATAL_ERROR "TARGET_ACTUAL_ARCH has to be set by tlib CMakeLists.txt!") -endif() - -file (GLOB RENODE_SOURCES - "renode/*.c" - "renode/arch/${TARGET_ACTUAL_ARCH}/*.c" -) - -target_sources(tlib PRIVATE - ${RENODE_SOURCES} -) - -# Include directories with Renode headers when building tlib - -target_include_directories(tlib PRIVATE - renode/include -) - -# Set tlib output filename - -set (ENDIAN_STR "le") -if (TARGET_BIG_ENDIAN) - set (ENDIAN_STR "be") -endif() - -set_target_properties(tlib PROPERTIES - PREFIX "" - OUTPUT_NAME "translate-${TARGET_ARCH}-${ENDIAN_STR}" - SUFFIX ".so" -) \ No newline at end of file diff --git a/recipes/renode-cores/patches/fix-tcg-arm64-asm.patch b/recipes/renode-cores/patches/fix-tcg-arm64-asm.patch deleted file mode 100644 index 79a0402690363..0000000000000 --- a/recipes/renode-cores/patches/fix-tcg-arm64-asm.patch +++ /dev/null @@ -1,27 +0,0 @@ ---- a/src/Infrastructure/src/Emulator/Cores/tlib/tcg/host-utils.h 2025-01-30 17:49:53.632175202 -0600 -+++ a/src/Infrastructure/src/Emulator/Cores/tlib/tcg/host-utils.h 2025-01-30 17:49:46.140225383 -0600 -@@ -83,2 +83,3 @@ - #if defined(TCG_TARGET_I386) && HOST_LONG_BITS == 64 -+#if defined(__x86_64__) || defined(_M_X64) - #define __HAVE_FAST_MULU64__ -@@ -97,2 +98,20 @@ - } -+#elif defined(__aarch64__) -+#define __HAVE_FAST_MULU64__ -+static inline void mulu64(uint64_t *plow, uint64_t *phigh, uint64_t a, uint64_t b) -+{ -+ __asm__ ("umulh %0, %1, %2" -+ : "=r" (*phigh) -+ : "r" (a), "r" (b)); -+ *plow = a * b; -+} -+#define __HAVE_FAST_MULS64__ -+static inline void muls64(uint64_t *plow, uint64_t *phigh, int64_t a, int64_t b) -+{ -+ __asm__ ("smulh %0, %1, %2" -+ : "=r" (*phigh) -+ : "r" (a), "r" (b)); -+ *plow = a * b; -+} -+#endif - #else diff --git a/recipes/renode-cores/patches/tlib-CMakeLists.txt b/recipes/renode-cores/patches/tlib-CMakeLists.txt deleted file mode 100644 index c8218360e8360..0000000000000 --- a/recipes/renode-cores/patches/tlib-CMakeLists.txt +++ /dev/null @@ -1,232 +0,0 @@ -cmake_minimum_required(VERSION 3.12) - -project (tlib LANGUAGES C) - -if(CMAKE_BUILD_TYPE STREQUAL "Debug") - set(DEBUG_DEFS "-DDEBUG -DDEBUG_ON") -endif() - -option (HOST_BIG_ENDIAN "Host big endian" OFF) - -if(NOT DEFINED HOST_ARCH) - message(STATUS "'HOST_ARCH' isn't set; analyzing the CPU (${CMAKE_SYSTEM_PROCESSOR})...") - if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "(AMD64|amd64|86)") - set (HOST_ARCH "i386" CACHE STRING "Host architecture") - elseif(${CMAKE_SYSTEM_PROCESSOR} MATCHES "(aarch64|arm64)") - set (HOST_ARCH "aarch64" CACHE STRING "Host architecture") - # Has to come last to not match arm macs arm64, while still matching a cpu like armv7l - elseif(${CMAKE_SYSTEM_PROCESSOR} MATCHES "(arm)") - set (HOST_ARCH "arm" CACHE STRING "Host architecture") - else() - message(FATAL_ERROR "CMAKE_SYSTEM_PROCESSOR '${CMAKE_SYSTEM_PROCESSOR}' doesn't seem to be supported. Supported host architectures are: 'arm', 'i386', 'aarch64/arm64'. Please set 'HOST_ARCH' manually.") - endif() -endif() -message(VERBOSE "Using HOST_ARCH: ${HOST_ARCH}") - -# Detect whether the host is 32- or 64-bit -math (EXPR WORD_SIZE_FOUND "${CMAKE_SIZEOF_VOID_P} * 8") -set (HOST_WORD_SIZE "${WORD_SIZE_FOUND}" CACHE STRING "Host word size") -message(VERBOSE "Using HOST_WORD_SIZE: ${HOST_WORD_SIZE}") - -if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) - set(CMAKE_BUILD_TYPE "Release" CACHE - STRING "Choose the type of build." FORCE) - set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS - "Debug" "Release" "RelWithDebInfo") -endif() - -option (PROFILING_BUILD "Build optimized for profiling" OFF) -if(PROFILING_BUILD) - message(STATUS "Profiling enhancements are enabled") - add_definitions ( - # Forcing not to omit frame pointer can have negative impact on performance, - # so the end profiling result will not exactly be equal to running on live system. - # Unfortunately without frame pointers perf might have problem with unwinding stack - # and call traces in reports will become less readable if using frame pointers for stack unwinding. - -fno-omit-frame-pointer - -DGENERATE_PERF_MAP - -g3 - ) -elseif(CMAKE_BUILD_TYPE STREQUAL "Release") - add_definitions(-fomit-frame-pointer) -endif() - -if (HOST_ARCH MATCHES "(arm|aarch64)" AND CMAKE_BUILD_TYPE STREQUAL "Release" AND NOT CMAKE_C_COMPILER_ID STREQUAL "AppleClang") - # gcc emits a clobber error for unwind.h DECLARE_ENV_PTR() in release mode on arm targets - # so demote it to a warning in this case, but not on arm mac clang, because this flag does not exsist - add_definitions(-Wno-error=clobbered) - add_definitions(-Wno-clobbered) -endif() - -option (TARGET_BIG_ENDIAN "Target big endian" OFF) -set (TARGET_ARCH "" CACHE STRING "Target architecture") -set (TARGET_WORD_SIZE "32" CACHE STRING "Target word size") -message(VERBOSE "Target is: ${TARGET_WORD_SIZE}-bit ${TARGET_ARCH}") - -set_property (CACHE HOST_ARCH PROPERTY STRINGS i386 arm aarch64) -set_property (CACHE TARGET_ARCH PROPERTY STRINGS i386 x86_64 arm arm-m arm64 sparc ppc ppc64 riscv riscv64 xtensa) - -if(NOT HOST_ARCH) - message (FATAL_ERROR "Host architecture not set") -endif() - -if(NOT TARGET_ARCH) - message (FATAL_ERROR "Target architecture not set") -endif() - -if(TARGET_BIG_ENDIAN) - set (BIG_ENDIAN_DEF -DTARGET_WORDS_BIGENDIAN=1) -endif() - -# Let's make 'TARGET_ACTUAL_ARCH' a lowercase 'TARGET_ARCH'. -string (TOLOWER "${TARGET_ARCH}" TARGET_ACTUAL_ARCH) - -if("${TARGET_ACTUAL_ARCH}" STREQUAL "arm-m") - set (TARGET_ACTUAL_ARCH "arm") - set (ARM_M_DEF -DTARGET_PROTO_ARM_M=1) -elseif("${TARGET_ACTUAL_ARCH}" STREQUAL "ppc64") - set (TARGET_ACTUAL_ARCH "ppc") -elseif("${TARGET_ACTUAL_ARCH}" STREQUAL "riscv64") - set (TARGET_ACTUAL_ARCH "riscv") -elseif("${TARGET_ACTUAL_ARCH}" STREQUAL "x86_64") - set (TARGET_ACTUAL_ARCH "i386") -endif() - -# Let's make TARGET_ACTUAL_ARCH available in CMakes adding tlib subdirectory. Using PARENT_SCOPE -# in the top project triggers warnings though so the if below prevents them in tlib built directly. -if(NOT ${CMAKE_PROJECT_NAME} STREQUAL tlib) - set (TARGET_ACTUAL_ARCH "${TARGET_ACTUAL_ARCH}" PARENT_SCOPE) -endif() - -set(TARGET_INSN_START_EXTRA_WORDS 0) -if("${TARGET_ACTUAL_ARCH}" MATCHES "^(arm|i386|sparc)$") - set(TARGET_INSN_START_EXTRA_WORDS 1) -elseif("${TARGET_ACTUAL_ARCH}" STREQUAL "arm64") - set(TARGET_INSN_START_EXTRA_WORDS 2) -endif() - -if("${TARGET_ACTUAL_ARCH}" STREQUAL "arm64" AND NOT "${TARGET_WORD_SIZE}" STREQUAL "64") - message (FATAL_ERROR "ERROR: arm64 target has to be built with TARGET_WORD_SIZE=64") -endif() - -string (TOUPPER "${HOST_ARCH}" HOST_ARCH_U) -string (TOUPPER "${TARGET_ACTUAL_ARCH}" TARGET_ACTUAL_ARCH_U) - -set(TLIB_COMMIT_SHA "" CACHE STRING "Current tlib commit SHA") -if(NOT TLIB_COMMIT_SHA) - execute_process(COMMAND git rev-parse --short HEAD RESULT_VARIABLE GIT_RESULT OUTPUT_VARIABLE GIT_OUTPUT OUTPUT_STRIP_TRAILING_WHITESPACE WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}) - if(NOT GIT_RESULT EQUAL 0) - set(GIT_OUTPUT "undefined") - endif() - - set(TLIB_COMMIT_SHA "${GIT_OUTPUT}" CACHE STRING "Current tlib commit SHA" FORCE) -endif() - -add_subdirectory(tcg) - -if("${TARGET_ACTUAL_ARCH}" STREQUAL "riscv" OR "${TARGET_ACTUAL_ARCH}" STREQUAL "riscv64") - set(SOFTFLOAT_SPECIALIZED_ARCHITECTURE "RISCV") - add_subdirectory(softfloat-3) - set(SOFTFLOAT3 softfloat-3) - - if(CMAKE_BUILD_TYPE STREQUAL "Release" AND NOT PROFILING_BUILD) - target_compile_definitions(softfloat-3 PRIVATE - INLINE_LEVEL=5 - ) - endif() -endif() - -if (NOT CMAKE_C_COMPILER_ID MATCHES "(clang)" AND NOT "${TARGET_ACTUAL_ARCH}" STREQUAL "arm64") - # Clang throws warnings from the arm64 target's function stubs - # so do not enable -Werror in that case until that is fixed - add_definitions(-Werror) -endif() - - -add_definitions ( - -fPIC - -Wall - -Wextra - -Wno-unused-parameter - -Wno-sign-compare - - -DHOST_BITS_${HOST_WORD_SIZE} - -DHOST_${HOST_ARCH_U}=1 - -DHOST_LONG_BITS=${HOST_WORD_SIZE} - - -DTARGET_${TARGET_ACTUAL_ARCH_U}=1 - - -DTARGET_SHORT_ALIGNMENT=2 - -DTARGET_INT_ALIGNMENT=4 - -DTARGET_LONG_ALIGNMENT=4 - -DTARGET_LLONG_ALIGNMENT=4 - - -DTARGET_LONG_BITS=${TARGET_WORD_SIZE} - -DTARGET_INSN_START_EXTRA_WORDS=${TARGET_INSN_START_EXTRA_WORDS} - ${ARM_M_DEF} - - -DTCG_TARGET_${HOST_ARCH_U} - -DTLIB_COMMIT=${TLIB_COMMIT_SHA} - ${BIG_ENDIAN_DEF} - ${DEBUG_DEFS} - ) - -if("${TARGET_ACTUAL_ARCH}" STREQUAL "arm" OR "${TARGET_ACTUAL_ARCH}" STREQUAL "arm64") - file (GLOB ARM_COMMON_SRC "arch/arm_common/*.c") - set (ARM_COMMON_INCL "arch/arm_common") -endif() - -include_directories ( - tcg - softfloat-2 - include - tcg/${HOST_ARCH} - arch/${TARGET_ACTUAL_ARCH} - ${ARM_COMMON_INCL} - ) - -file (GLOB SOURCES - "*.c" - "softfloat-2/*.c" - "arch/*.c" - "external/*.c" - "arch/${TARGET_ACTUAL_ARCH}/*.c" - ${ARM_COMMON_SRC} - ) - -add_library (tlib SHARED ${SOURCES}) -add_dependencies (tlib tcg) - -if("${TARGET_ACTUAL_ARCH}" STREQUAL "i386") - set (MATH_LIB_LINK_ARG "-lm" CACHE STRING - "Argument pointing linker to a math functions library. It's required to translate i386 code.") -endif() - -# On windows, make sure the winpthread gets linked statically -if(${CMAKE_HOST_SYSTEM_NAME} MATCHES "(Windows|CYGWIN)") - set(PTREAD_OPT -static winpthread -dynamic) -else() - set(PTREAD_OPT pthread) -endif() - -# On x86_64 Linux, the memcpy function was modified in GNU libc v2.14. -# It'd be impossible to run tlib without this wrapping with older libc. -if(${CMAKE_HOST_SYSTEM_NAME} STREQUAL Linux AND ${HOST_ARCH} STREQUAL i386 AND ${HOST_WORD_SIZE} EQUAL 64) - set(WRAP_MEMCPY_OPT -Wl,--wrap=memcpy) -endif() - -# -z flag does not work on Windows -if ((NOT (${CMAKE_HOST_SYSTEM_NAME} MATCHES "(Windows|CYGWIN)" )) AND ("${C_COMPILER_ID}" STREQUAL "GNU")) - set (Z_OPTS -zdefs) -endif() - -target_link_libraries (tlib - ${WRAP_MEMCPY_OPT} - -fPIC - ${Z_OPTS} - - ${MATH_LIB_LINK_ARG} - ${PTREAD_OPT} - ${SOFTFLOAT3} - tcg - ) diff --git a/recipes/renode-cores/patches/update-for-cmake-build.sh.patch b/recipes/renode-cores/patches/update-for-cmake-build.sh.patch deleted file mode 100644 index a9f480f68bc3d..0000000000000 --- a/recipes/renode-cores/patches/update-for-cmake-build.sh.patch +++ /dev/null @@ -1,367 +0,0 @@ ---- /home/memento/PycharmProjects/staged-recipes-2/build_artifacts/src_cache/v1_15_3_692604eb/build.sh 2024-09-17 03:09:19.000000000 -0500 -+++ build.new.sh 2025-01-24 15:30:24.984659038 -0600 -@@ -18,4 +18,8 @@ - SKIP_FETCH=false -+TLIB_ONLY=false -+TLIB_EXPORT_COMPILE_COMMANDS=false -+TLIB_ARCH="" - NET=false --TFM="net6.0" -+TFM="net8.0" -+GENERATE_DOTNET_BUILD_TARGET=true - PARAMS=() -@@ -24,5 +28,8 @@ - RID="linux-x64" -+HOST_ARCH="i386" -+# Common cmake flags -+CMAKE_COMMON="" - - function print_help() { -- echo "Usage: $0 [-cdvspnt] [-b properties-file.csproj] [--no-gui] [--skip-fetch] [--profile-build] [-- ]" -+ echo "Usage: $0 [-cdvspnt] [-b properties-file.csproj] [--no-gui] [--skip-fetch] [--profile-build] [--tlib-only] [--tlib-export-compile-commands] [--tlib-arch ] [--host-arch i386|aarch64] [-- ]" - echo -@@ -42,3 +49,9 @@ - echo "-B bundle target runtime (default value: $RID, requires --net, -t)" -- echo "--profile-build build optimized for tlib profiling" -+ echo "-F select the target framework for which Renode should be built (default value: $TFM)" -+ echo "--profile-build build optimized for profiling" -+ echo "--tlib-only only build tlib" -+ echo "--tlib-arch build only single arch (implies --tlib-only)" -+ echo "--tlib-export-compile-commands build tlibs with 'compile_commands.json' (requires --tlib-arch)" -+ echo "--host-arch build with a specific tcg host architecture (default: i386)" -+ echo "--skip-dotnet-target-generation don't generate 'Directory.Build.targets' file, useful when experimenting with different build settings" - echo " arguments to pass to the build system" -@@ -46,3 +59,3 @@ - --while getopts "cdvpnstb:o:B:-:" opt -+while getopts "cdvpnstb:o:B:F:a:-:" opt - do -@@ -81,2 +94,9 @@ - ;; -+ F) -+ if ! $NET; then -+ echo "-F requires --net being set" -+ exit 1 -+ fi -+ TFM=$OPTARG -+ ;; - -) -@@ -100,3 +120,28 @@ - "profile-build") -- PARAMS+=('p:TlibProfilingBuild=true') -+ CMAKE_COMMON="-DPROFILING_BUILD=ON" -+ ;; -+ "tlib-only") -+ TLIB_ONLY=true -+ ;; -+ "tlib-arch") -+ # This only makes sense with '--tlib-only' set; it might as well imply it -+ TLIB_ONLY=true -+ shift $((OPTIND-1)) -+ TLIB_ARCH=$1 -+ OPTIND=2 -+ ;; -+ "tlib-export-compile-commands") -+ if [ -z $TLIB_ARCH ]; then -+ echo "--tlib-export-compile-commands requires --tlib-arch begin set" -+ exit 1 -+ fi -+ TLIB_EXPORT_COMPILE_COMMANDS=true -+ ;; -+ "host-arch") -+ shift $((OPTIND-1)) -+ HOST_ARCH=$1 -+ OPTIND=2 -+ ;; -+ "skip-dotnet-target-generation") -+ GENERATE_DOTNET_BUILD_TARGET=false - ;; -@@ -184,3 +229,4 @@ - BUILD_TARGET=Windows -- TFM="net6.0-windows10.0.17763.0" -+ TFM="$TFM-windows10.0.17763.0" -+ RID="win-x64" - else -@@ -189,10 +235,34 @@ - -+if [[ $GENERATE_DOTNET_BUILD_TARGET = true ]]; then -+ if $ON_WINDOWS; then -+ # CsWinRTAotOptimizerEnabled is disabled due to a bug in dotnet-sdk. -+ # See: https://github.com/dotnet/sdk/issues/44026 -+ OS_SPECIFIC_TARGET_OPTS='false' -+ fi -+ -+cat < "$(get_path "$PWD/Directory.Build.targets")" -+ -+ -+ $TFM -+ ${OS_SPECIFIC_TARGET_OPTS:+${OS_SPECIFIC_TARGET_OPTS}} -+ -+ -+EOF -+ -+fi -+ - if $NET - then -+ export DOTNET_CLI_TELEMETRY_OPTOUT=1 - CS_COMPILER="dotnet build" - TARGET="`get_path \"$PWD/Renode_NET.sln\"`" -+ BUILD_TYPE="dotnet" - else - TARGET="`get_path \"$PWD/Renode.sln\"`" -+ BUILD_TYPE="mono" - fi - -+OUT_BIN_DIR="$(get_path "output/bin/${CONFIGURATION}")" -+BUILD_TYPE_FILE=$(get_path "${OUT_BIN_DIR}/build_type") -+ - # Verify Mono and mcs version on Linux and macOS -@@ -203,3 +273,3 @@ - MINIMUM_MONO=`get_min_mono_version` -- echo "mcs not found. Renode requries Mono $MINIMUM_MONO or newer. Please refer to documentation for installation instructions. Exiting!" -+ echo "mcs not found. Renode requires Mono $MINIMUM_MONO or newer. Please refer to documentation for installation instructions. Exiting!" - exit 1 -@@ -237,20 +307,3 @@ - --# Build CCTask in Release configuration --CCTASK_OUTPUT=`mktemp` --CCTASK_BUILD_ARGS=($NET_FRAMEWORK_VER p:Configuration=Release p:Platform="\"$BUILD_PLATFORM\"") --set +e --CCTASK_SLN=CCTask.sln --if $NET --then -- CCTASK_SLN=CCTask_NET.sln --fi --eval "$CS_COMPILER $(build_args_helper "${CCTASK_BUILD_ARGS[@]}") $(get_path $ROOT_PATH/lib/cctask/$CCTASK_SLN)" 2>&1 > $CCTASK_OUTPUT -- --if [ $? -ne 0 ]; then -- cat $CCTASK_OUTPUT -- rm $CCTASK_OUTPUT -- exit 1 --fi --rm $CCTASK_OUTPUT --set -e -+CORES_PATH="$ROOT_PATH/src/Infrastructure/src/Emulator/Cores" - -@@ -259,19 +312,22 @@ - then -- if ! $NET -- then -- PARAMS+=(t:Clean) -- fi -- for conf in Debug Release -+ for project_dir in $(find "$(get_path "${ROOT_PATH}/src")" -iname '*.csproj' -exec dirname '{}' \;) - do -- for build_target in Windows Mono Headless -+ for dir in {bin,obj}/{Debug,Release} - do -- if $NET -+ output_dir="$(get_path "${project_dir}/${dir}")" -+ if [[ -d "${output_dir}" ]] - then -- dotnet clean $(build_args_helper ${PARAMS[@]}) $(build_args_helper p:Configuration=${conf}${build_target}) "$TARGET" -- else -- $CS_COMPILER $(build_args_helper ${PARAMS[@]}) $(build_args_helper p:Configuration=${conf}${build_target}) "$TARGET" -+ echo "Removing: ${output_dir}" -+ rm -rf "${output_dir}" - fi - done -- rm -fr $OUTPUT_DIRECTORY/bin/$conf - done -+ -+ # Manually clean the main output directory as it's location is non-standard -+ main_output_dir="$(get_path "${OUTPUT_DIRECTORY}/bin")" -+ if [[ -d "${main_output_dir}" ]] -+ then -+ echo "Removing: ${main_output_dir}" -+ rm -rf "${main_output_dir}" -+ fi - exit 0 -@@ -279,2 +335,13 @@ - -+# Check if a full rebuild is needed -+if [[ -f "$BUILD_TYPE_FILE" ]] -+then -+ if [[ "$(cat "$BUILD_TYPE_FILE")" != "$BUILD_TYPE" ]] -+ then -+ echo "Attempted to build Renode in a different configuration than the previous build" -+ echo "Please run '$0 -c' to clean the previous build before continuing" -+ exit 1 -+ fi -+fi -+ - # check weak implementations of core libraries -@@ -286,12 +353,105 @@ - -+# Paths for tlib -+CORES_BUILD_PATH="$CORES_PATH/obj/$CONFIGURATION" -+CORES_BIN_PATH="$CORES_PATH/bin/$CONFIGURATION" -+ -+# Cmake generator, handled in their own variable since the names contain spaces -+if $ON_WINDOWS -+then -+ CMAKE_GEN="-GMinGW Makefiles" -+else -+ CMAKE_GEN="-GUnix Makefiles" -+fi -+ -+# Macos architecture flags, to make rosetta work properly -+if $ON_OSX -+then -+ CMAKE_COMMON+=" -DCMAKE_OSX_ARCHITECTURES=x86_64" -+ if [ $HOST_ARCH == "aarch64" ]; then -+ CMAKE_COMMON+=" -DCMAKE_OSX_ARCHITECTURES=arm64" -+ fi -+fi -+ -+# This list contains all cores that will be built. -+# If you are adding a new core or endianness add it here to have the correct tlib built -+CORES=(arm.le arm.be arm64.le arm-m.le arm-m.be ppc.le ppc.be ppc64.le ppc64.be i386.le x86_64.le riscv.le riscv64.le sparc.le sparc.be xtensa.le) -+ -+# if '--tlib-arch' was used - pick the first matching one -+if [[ ! -z $TLIB_ARCH ]]; then -+ NONE_MATCHED=true -+ for potential_match in "${CORES[@]}"; do -+ if [[ $potential_match == "$TLIB_ARCH"* ]]; then -+ CORES=($potential_match) -+ echo "Compiling tlib for $potential_match" -+ NONE_MATCHED=false -+ break -+ fi -+ done -+ if $NONE_MATCHED ; then -+ echo "Failed to match any tlib arch" -+ exit 1 -+ fi -+fi -+ -+# build tlib -+for core_config in "${CORES[@]}" -+do -+ CORE="$(echo $core_config | cut -d '.' -f 1)" -+ ENDIAN="$(echo $core_config | cut -d '.' -f 2)" -+ BITS=32 -+ # Check if core is 64-bit -+ if [[ $CORE =~ "64" ]]; then -+ BITS=64 -+ fi -+ # Core specific flags to cmake -+ CMAKE_CONF_FLAGS="-DTARGET_ARCH=$CORE -DTARGET_WORD_SIZE=$BITS -DCMAKE_BUILD_TYPE=$CONFIGURATION" -+ CORE_DIR=$CORES_BUILD_PATH/$CORE/$ENDIAN -+ mkdir -p $CORE_DIR -+ pushd "$CORE_DIR" > /dev/null -+ if [[ $ENDIAN == "be" ]]; then -+ CMAKE_CONF_FLAGS+=" -DTARGET_BIG_ENDIAN=1" -+ fi -+ if [[ "$TLIB_EXPORT_COMPILE_COMMANDS" = true ]]; then -+ CMAKE_CONF_FLAGS+=" -DCMAKE_EXPORT_COMPILE_COMMANDS=1" -+ fi -+ cmake "$CMAKE_GEN" $CMAKE_COMMON $CMAKE_CONF_FLAGS -DHOST_ARCH=$HOST_ARCH $CORES_PATH -+ cmake --build . -+ CORE_BIN_DIR=$CORES_BIN_PATH/lib -+ mkdir -p $CORE_BIN_DIR -+ if $ON_OSX; then -+ # macos `cp` does not have the -u flag -+ cp -v tlib/*.so $CORE_BIN_DIR/ -+ else -+ cp -u -v tlib/*.so $CORE_BIN_DIR/ -+ fi -+ # copy compile_commands.json to tlib directory -+ if [[ "$TLIB_EXPORT_COMPILE_COMMANDS" = true ]]; then -+ command cp -v -f $CORE_DIR/compile_commands.json $CORES_PATH/tlib/ -+ fi -+ popd > /dev/null -+done -+ -+if $TLIB_ONLY -+then -+ exit 0 -+fi -+ - # build - eval "$CS_COMPILER $(build_args_helper "${PARAMS[@]}") $TARGET" -+echo -n "$BUILD_TYPE" > "$BUILD_TYPE_FILE" - - # copy llvm library --if $NET --then -- cp src/Infrastructure/src/Emulator/Peripherals/bin/$CONFIGURATION/$TFM/libllvm-disas.* output/bin/$CONFIGURATION/$TFM -+LLVM_LIB="libllvm-disas" -+if [[ $HOST_ARCH == "aarch64" ]]; then -+ # aarch64 host binaries have a different name -+ LLVM_LIB="libllvm-disas-aarch64" -+fi -+if [[ "${DETECTED_OS}" == "windows" ]]; then -+ LIB_EXT="dll" -+elif [[ "${DETECTED_OS}" == "osx" ]]; then -+ LIB_EXT="dylib" - else -- cp src/Infrastructure/src/Emulator/Peripherals/bin/$CONFIGURATION/libllvm-disas.* output/bin/$CONFIGURATION -+ LIB_EXT="so" - fi -+cp lib/resources/llvm/$LLVM_LIB.$LIB_EXT $OUT_BIN_DIR/libllvm-disas.$LIB_EXT - -@@ -326,11 +486,24 @@ - then -- # Restore dependecies for linux-x64 runtime. It prevents error NETSDK1112 during publish. -- dotnet restore --runtime linux-x64 Renode_NET.sln -- -- eval "dotnet publish -f $TFM --self-contained false $(build_args_helper "${PARAMS[@]}") $TARGET" -- export RID TFM -- $ROOT_PATH/tools/packaging/make_linux_dotnet_package.sh $params -+ # dotnet package on linux uses a separate script -+ if $ON_LINUX -+ then -+ # maxcpucount:1 to avoid an error with multithreaded publish -+ eval "dotnet publish -maxcpucount:1 -f $TFM --self-contained false $(build_args_helper "${PARAMS[@]}") $TARGET" -+ export RID TFM -+ $ROOT_PATH/tools/packaging/make_linux_dotnet_package.sh $params -+ # Source package bundles nuget dependencies required for building the dotnet version of Renode -+ # so it can only be built when using dotnet. The generated package can also be used with Mono/.NETFramework -+ $ROOT_PATH/tools/packaging/make_source_package.sh $params -+ elif $ON_WINDOWS && ! $PORTABLE -+ then -+ # No Non portable dotnet package on windows yet -+ echo "Only portable dotnet packages are supported on windows. Rerun build.sh with -t flag to build portable" -+ exit 1 -+ elif $ON_OSX -+ then -+ echo "dotnet packages not supported on ${DETECTED_OS}" -+ exit 1 -+ fi - else - $ROOT_PATH/tools/packaging/make_${DETECTED_OS}_packages.sh $params -- $ROOT_PATH/tools/packaging/make_source_package.sh $params - fi -@@ -341,16 +514,17 @@ - PARAMS+=(p:PORTABLE=true) -- if $ON_LINUX -+ if $NET - then -- if $NET -- then -- eval "dotnet publish -r $RID -f $TFM --self-contained true $(build_args_helper "${PARAMS[@]}") $TARGET" -- export RID TFM -- $ROOT_PATH/tools/packaging/make_linux_portable_dotnet.sh $params -- else -- $ROOT_PATH/tools/packaging/make_linux_portable.sh $params -- fi -+ # maxcpucount:1 to avoid an error with multithreaded publish -+ eval "dotnet publish -maxcpucount:1 -r $RID -f $TFM --self-contained true $(build_args_helper "${PARAMS[@]}") $TARGET" -+ export RID TFM -+ $ROOT_PATH/tools/packaging/make_${DETECTED_OS}_portable_dotnet.sh $params - else -- echo "Portable packages are only available on Linux. Exiting!" -- exit 1 -+ if $ON_LINUX -+ then -+ $ROOT_PATH/tools/packaging/make_linux_portable.sh $params -+ else -+ echo "Portable packages for Mono are only available on Linux. Exiting!" -+ exit 1 -+ fi - fi --fi -+fi -\ No newline at end of file diff --git a/recipes/renode-cores/recipe.yaml b/recipes/renode-cores/recipe.yaml index 112134d11496d..519ce4aa28c13 100644 --- a/recipes/renode-cores/recipe.yaml +++ b/recipes/renode-cores/recipe.yaml @@ -10,11 +10,13 @@ package: source: - url: https://github.com/renode/renode/releases/download/v${{ version }}/renode_${{ version }}_source.tar.xz sha256: 40c50afe8db86a9c63f4a86b93116a6babd43bf241cfaac47b2c0d2cbc2b15a8 - patches: - # - patches/update-for-cmake-build.sh.patch - - if: osx and arm64 - then: - - patches/fix-tcg-arm64-asm.patch + - git: https://github.com/renode/renode-infrastructure.git + rev: 3fc2d5fe643068e595e875d9408cb4329522b229 + target_directory: cmake-renode-infrastructure + - git: https://github.com/antmicro/tlib.git + rev: 69fff75a0eba7471283b0b8db2e55e8388e284f6 + target_directory: cmake-tlib + build: number: 0 From a663b6e80ed18aaa48a3702156114e25b1717e98 Mon Sep 17 00:00:00 2001 From: MementoRC Date: Fri, 31 Jan 2025 13:55:07 -0800 Subject: [PATCH 22/26] (wip) solved ppc64 non-unix. Odd 'do' fail --- recipes/renode-cli/build.bat | 24 ++++++++---------- recipes/renode-cores/build.bat | 25 +++++++++++++++---- recipes/renode-cores/build.sh | 3 +++ .../helpers/renode_build_with_cmake.ps1 | 6 ++--- recipes/renode-cores/recipe.yaml | 23 ++++++++++------- 5 files changed, 50 insertions(+), 31 deletions(-) diff --git a/recipes/renode-cli/build.bat b/recipes/renode-cli/build.bat index 734bdefc6bb89..cb0f681b17bf6 100644 --- a/recipes/renode-cli/build.bat +++ b/recipes/renode-cli/build.bat @@ -3,20 +3,18 @@ setlocal enabledelayedexpansion set "install_prefix=%PREFIX%\opt\%PKG_NAME%" -for /f "tokens=*" %%i in ('dotnet --version') do set "dotnet_version=%%i" -set "framework_version=%dotnet_version:~0,-2%" +:: for /f "tokens=*" %%i in ('dotnet --version') do set "dotnet_version=%%i" +:: set "framework_version=%dotnet_version:~0,-2%" +set "framework_version=8.0" rem Patch the project files to use the correct .NET version -for /r %%i in (lib src tests) do ( - for /r %%j in (*.csproj) do ( - sed -i -E "s/([>;])net6.0([<;])/\1net%framework_version%\2/" "%%j" - sed -i -E "s|^((\s+))|\1\n\2\2CS0168;CS0219;CS8981;SYSLIB0050;SYSLIB0051|" "%%j" - sed -i -E 's|^(\s+)<(Package)?Reference\s+Include="Mono.Posix".*\n||g' "%%j" - ) -) -for /d %%i in (obj bin) do ( - rd /s /q "%%i" -) +find lib src tests -name "*.csproj" -exec sed -i -E \ + -e "s/([>;])net6.0([<;])/\1net${framework_version}\2/" \ + -e "s|^((\s+))|\1\n\2\2CS0168;CS0219;CS8981;SYSLIB0050;SYSLIB0051|" \ + -e 's|^(\s+)<(Package)?Reference\s+Include="Mono.Posix".*\n||g' \ + {} \; +find . -type d -name "obj" -exec rm -rf {} + +find . -type d -name "bin" -exec rm -rf {} + sed -i -E "s/(ReleaseHeadless\|Any .+ = )Debug/\1Release/" Renode_NET.sln rem Prevent CMake build since we provide the binaries @@ -72,4 +70,4 @@ echo set "RESULT_CODE=%%ERRORLEVEL%%" echo if not "%%STTY_CONFIG%%"=="" stty "%%STTY_CONFIG%%" echo exit /b %%RESULT_CODE%% ) > "%PREFIX%\bin\renode-test.cmd" -chmod +x "%PREFIX%\bin\renode-test.cmd" \ No newline at end of file +chmod +x "%PREFIX%\bin\renode-test.cmd" diff --git a/recipes/renode-cores/build.bat b/recipes/renode-cores/build.bat index df6c841b39587..d3b6491ea693f 100644 --- a/recipes/renode-cores/build.bat +++ b/recipes/renode-cores/build.bat @@ -3,11 +3,26 @@ setlocal EnableDelayedExpansion rem Update the submodule to the latest commit CMakeLists.txt -set "CMAKEFILES_TXT=src\Emulator\Cores\CMakeLists.txt" -copy "cmake-renode-infrastructure\${CMAKEFILES_TXT}" "${SRC_DIR}\src\Infrastructure\${CMAKEFILES_TXT}" -copy "cmake-tlib\CMakeLists.txt" "${SRC_DIR}\src\Infrastructure\src\Emulator\Cores\tlib" -copy "cmake-tlib\tcg\CMakeLists.txt" "${SRC_DIR}\src\Infrastructure\src\Emulator\Cores\tlib\tcg" -if %errorlevel% neq 0 exit /b %errorlevel% +mkdir %SRC_DIR%\updates +pushd %SRC_DIR%\updates + git clone "https://github.com/renode/renode-infrastructure.git" + pushd renode-infrastructure + git checkout 3fc2d5fe643068e595e875d9408cb4329522b229 + set "CMAKEFILES_TXT=src\Emulator\Cores\CMakeLists.txt" + copy %CMAKEFILES_TXT% "%SRC_DIR%\src\Infrastructure\%CMAKEFILES_TXT%" + popd + + git clone "https://github.com/antmicro/tlib.git" + pushd tlib + git checkout 69fff75a0eba7471283b0b8db2e55e8388e284f6 + copy "CMakeLists.txt" "%SRC_DIR%\src\Infrastructure\src\Emulator\Cores\tlib" + copy "tcg\CMakeLists.txt" "%SRC_DIR%\src\Infrastructure\src\Emulator\Cores\tlib\tcg" + copy LICENSE %RECIPE_DIR%\tlib-LICENSE + popd + if %errorlevel% neq 0 exit /b %errorlevel% +popd + +copy "%SRC_DIR%\src\Infrastructure\src\Emulator\Cores\tlib\softfloat-3\COPYING.txt" "%RECIPE_DIR%\softfloat-3-COPYING.txt" powershell -ExecutionPolicy Bypass -File "%RECIPE_DIR%\helpers\renode_build_with_cmake.ps1" if %errorlevel% neq 0 exit /b %errorlevel% diff --git a/recipes/renode-cores/build.sh b/recipes/renode-cores/build.sh index 48608c3ee7979..9ec971f2df1ec 100644 --- a/recipes/renode-cores/build.sh +++ b/recipes/renode-cores/build.sh @@ -8,6 +8,9 @@ cp "cmake-renode-infrastructure/${CMAKEFILES_TXT}" "${SRC_DIR}/src/Infrastructur cp cmake-tlib/CMakeLists.txt "${SRC_DIR}/src/Infrastructure/src/Emulator/Cores/tlib" cp cmake-tlib/tcg/CMakeLists.txt "${SRC_DIR}/src/Infrastructure/src/Emulator/Cores/tlib/tcg" +cp cmake-tlib/LICENSE "${RECIPE_DIR}/tlib-LICENSE" +cp "${SRC_DIR}/src/Infrastructure/src/Emulator/Cores/tlib/softfloat-3/COPYING.txt" "${RECIPE_DIR}/softfloat-3-COPYING.txt" + chmod +x build.sh tools/building/check_weak_implementations.sh ${RECIPE_DIR}/helpers/renode_build_with_cmake.sh diff --git a/recipes/renode-cores/helpers/renode_build_with_cmake.ps1 b/recipes/renode-cores/helpers/renode_build_with_cmake.ps1 index 44758a06c6931..749b3e2ccc347 100755 --- a/recipes/renode-cores/helpers/renode_build_with_cmake.ps1 +++ b/recipes/renode-cores/helpers/renode_build_with_cmake.ps1 @@ -33,10 +33,8 @@ function Update-CMakeLists { (gc $filePath) -replace $flagToRemove,$flagToAdd | sc $filePath } -Update-CMakeLists "$CORES_PATH\tlib\CMakeLists.txt" "-fPIC" "-Wno-unused-function" -# Not in this older 1.15.3 version (in master) -# Update-CMakeLists "$CORES_PATH\tlib\softload-3\CMakeLists.txt" "-fPIC" "" -Update-CMakeLists "$CORES_PATH\tlib\tcg\CMakeLists.txt" "-fPIC" "-Wno-unused-function" +Update-CMakeLists "$CORES_PATH\tlib\CMakeLists.txt" "-fPIC" "-Wno-unused-function -Wno-maybe-uninitialized" +Update-CMakeLists "$CORES_PATH\tlib\tcg\CMakeLists.txt" "-fPIC" "-Wno-unused-function -Wno-maybe-uninitialized" foreach ($core_config in $CORES) { Write-Host "Building $core_config" diff --git a/recipes/renode-cores/recipe.yaml b/recipes/renode-cores/recipe.yaml index 519ce4aa28c13..31d1bfbb76ba3 100644 --- a/recipes/renode-cores/recipe.yaml +++ b/recipes/renode-cores/recipe.yaml @@ -10,12 +10,14 @@ package: source: - url: https://github.com/renode/renode/releases/download/v${{ version }}/renode_${{ version }}_source.tar.xz sha256: 40c50afe8db86a9c63f4a86b93116a6babd43bf241cfaac47b2c0d2cbc2b15a8 - - git: https://github.com/renode/renode-infrastructure.git - rev: 3fc2d5fe643068e595e875d9408cb4329522b229 - target_directory: cmake-renode-infrastructure - - git: https://github.com/antmicro/tlib.git - rev: 69fff75a0eba7471283b0b8db2e55e8388e284f6 - target_directory: cmake-tlib + - if: unix + then: + - git: https://github.com/renode/renode-infrastructure.git + rev: "3fc2d5fe643068e595e875d9408cb4329522b229" + target_directory: cmake-renode-infrastructure + - git: https://github.com/antmicro/tlib.git + rev: "69fff75a0eba7471283b0b8db2e55e8388e284f6" + target_directory: cmake-tlib build: number: 0 @@ -35,8 +37,10 @@ requirements: - ${{ compiler('m2w64_c') }} - ${{ compiler('m2w64_cxx') }} - ${{ stdlib('m2w64_c') }} + - git - m2-base - m2-bash + - m2-findutils - m2-sed - m2-tar - ninja @@ -52,6 +56,8 @@ tests: - ${{ "Library/" if not unix }}lib/renode-cores/translate-i386-le.so - ${{ "Library/" if not unix }}lib/renode-cores/translate-ppc-be.so - ${{ "Library/" if not unix }}lib/renode-cores/translate-ppc-le.so + - ${{ "Library/" if not unix }}lib/renode-cores/translate-ppc64-be.so + - ${{ "Library/" if not unix }}lib/renode-cores/translate-ppc64-le.so - ${{ "Library/" if not unix }}lib/renode-cores/translate-riscv-le.so - ${{ "Library/" if not unix }}lib/renode-cores/translate-riscv64-le.so - ${{ "Library/" if not unix }}lib/renode-cores/translate-sparc-be.so @@ -60,8 +66,6 @@ tests: - ${{ "Library/" if not unix }}lib/renode-cores/translate-xtensa-le.so - if: unix then: - - lib/renode-cores/translate-ppc64-be.so - - lib/renode-cores/translate-ppc64-le.so - etc/conda/activate.d/renode-cores-activate.sh - etc/conda/deactivate.d/renode-cores-deactivate.sh else: @@ -80,7 +84,8 @@ about: license: MIT license_file: - LICENSE - - licensefiles/ + - tlib-LICENSE + - softfloat-3-COPYING.txt documentation: https://renode.io/ repository: https://github.com/renode/renode From 4d819f2246a763859af8b3aeea66909f89eb2a2a Mon Sep 17 00:00:00 2001 From: MementoRC Date: Fri, 31 Jan 2025 16:26:56 -0800 Subject: [PATCH 23/26] (wip) closing in on that wraith of an OS --- recipes/renode-cli/build.bat | 18 +++++++++------ .../helpers/renode_build_with_dotnet.ps1 | 22 +++++++++---------- recipes/renode-cli/recipe.yaml | 6 ++--- recipes/renode-cores/build.bat | 14 ++++++------ recipes/renode-cores/build.sh | 10 ++++----- recipes/renode-cores/recipe.yaml | 8 +------ recipes/renode-cores/scripts/activate.bat | 8 ------- recipes/renode-cores/scripts/activate.sh | 4 ---- recipes/renode-cores/scripts/deactivate.bat | 8 ------- recipes/renode-cores/scripts/deactivate.sh | 8 ------- 10 files changed, 37 insertions(+), 69 deletions(-) delete mode 100755 recipes/renode-cores/scripts/activate.bat delete mode 100644 recipes/renode-cores/scripts/activate.sh delete mode 100644 recipes/renode-cores/scripts/deactivate.bat delete mode 100644 recipes/renode-cores/scripts/deactivate.sh diff --git a/recipes/renode-cli/build.bat b/recipes/renode-cli/build.bat index cb0f681b17bf6..380849960dfc6 100644 --- a/recipes/renode-cli/build.bat +++ b/recipes/renode-cli/build.bat @@ -8,13 +8,17 @@ set "install_prefix=%PREFIX%\opt\%PKG_NAME%" set "framework_version=8.0" rem Patch the project files to use the correct .NET version -find lib src tests -name "*.csproj" -exec sed -i -E \ - -e "s/([>;])net6.0([<;])/\1net${framework_version}\2/" \ - -e "s|^((\s+))|\1\n\2\2CS0168;CS0219;CS8981;SYSLIB0050;SYSLIB0051|" \ - -e 's|^(\s+)<(Package)?Reference\s+Include="Mono.Posix".*\n||g' \ - {} \; -find . -type d -name "obj" -exec rm -rf {} + -find . -type d -name "bin" -exec rm -rf {} + +:: for /f "delims=" %%i in ('find lib src tests -name "*.csproj"') do ( +:: sed -i -E "s/([>;])net6.0([<;])/\1net${framework_version}\2/" "%%i" +:: sed -i -E "s|^((\s+))|\1\n\2\2CS0168;CS0219;CS8981;SYSLIB0050;SYSLIB0051|" "%%i" +:: ) +:: %BUILD_PREFIX%\Library\usr\bin\find.exe lib src tests -name "*.csproj" -exec sed -i -E ^ +:: -e "s/([>;])net6.0([<;])/\1net${framework_version}\2/" ^ +:: -e "s|^((\s+))|\1\n\2\2CS0168;CS0219;CS8981;SYSLIB0050;SYSLIB0051|" ^ +:: -e 's|^(\s+)<(Package)?Reference\s+Include="Mono.Posix".*\n||g' ^ +:: {} \; +:: %BUILD_PREFIX%\Library\usr\bin\find.exe . -type d -name "obj" -exec rm -rf {} \; +:: %BUILD_PREFIX%\Library\usr\bin\find.exe . -type d -name "bin" -exec rm -rf {} \; sed -i -E "s/(ReleaseHeadless\|Any .+ = )Debug/\1Release/" Renode_NET.sln rem Prevent CMake build since we provide the binaries diff --git a/recipes/renode-cli/helpers/renode_build_with_dotnet.ps1 b/recipes/renode-cli/helpers/renode_build_with_dotnet.ps1 index 062bf49f6b339..b44d9c52a19ac 100755 --- a/recipes/renode-cli/helpers/renode_build_with_dotnet.ps1 +++ b/recipes/renode-cli/helpers/renode_build_with_dotnet.ps1 @@ -1,10 +1,8 @@ -#!/usr/bin/env pwsh - param ( [string]$framework_version ) -$OUTPUT_DIRECTORY = "${env:SRC_DIR}/output" +$OUTPUT_DIRECTORY = "${env:SRC_DIR}\output" $CONFIGURATION = "Release" $BUILD_PLATFORM = "Any CPU" $HEADLESS = $true @@ -39,24 +37,24 @@ $DirectoryBuildTargetsContent = @" "@ -$DirectoryBuildTargetsPath = "${env:SRC_DIR}/Directory.Build.targets" +$DirectoryBuildTargetsPath = "${env:SRC_DIR}\Directory.Build.targets" Set-Content -Path $DirectoryBuildTargetsPath -Value $DirectoryBuildTargetsContent $env:DOTNET_CLI_TELEMETRY_OPTOUT = 1 $CS_COMPILER = "dotnet build" -$TARGET = "${env:SRC_DIR}/Renode_NET.sln" +$TARGET = "${env:SRC_DIR}\Renode_NET.sln" $BUILD_TYPE = "dotnet" -$OUT_BIN_DIR = "${env:SRC_DIR}/output/bin/$CONFIGURATION" -$BUILD_TYPE_FILE = "$OUT_BIN_DIR/build_type" +$OUT_BIN_DIR = "${env:SRC_DIR}\output\bin\$CONFIGURATION" +$BUILD_TYPE_FILE = "$OUT_BIN_DIR\build_type" # Copy properties file according to the running OS New-Item -ItemType Directory -Force -Path $OUTPUT_DIRECTORY -Remove-Item -Force -Path "$OUTPUT_DIRECTORY/properties.csproj" -$PROP_FILE = "${env:CURRENT_PATH:=.}/src/Infrastructure/src/Emulator/Cores/linux-properties.csproj" -Copy-Item -Path $PROP_FILE -Destination "$OUTPUT_DIRECTORY/properties.csproj" +# Remove-Item -Force -Path "$OUTPUT_DIRECTORY\properties.csproj" +$PROP_FILE = "${env:SRC_DIR}\src\Infrastructure\src\Emulator\Cores\windows-properties_NET.csproj" +Copy-Item -Path $PROP_FILE -Destination "$OUTPUT_DIRECTORY\properties.csproj" -$CORES_PATH = "${env:SRC_DIR}/src/Infrastructure/src/Emulator/Cores" +$CORES_PATH = "${env:SRC_DIR}\src\Infrastructure\src\Emulator\Cores" $PARAMS += "p:Configuration=${CONFIGURATION}${BUILD_TARGET}" $PARAMS += "p:GenerateFullPaths=true" @@ -80,4 +78,4 @@ Set-Content -Path $BUILD_TYPE_FILE -Value $BUILD_TYPE # copy llvm library $LLVM_LIB = "libllvm-disas" $LIB_EXT = "dll" -Copy-Item -Path "lib/resources/llvm/$LLVM_LIB.$LIB_EXT" -Destination "$OUT_BIN_DIR/libllvm-disas.$LIB_EXT" +Copy-Item -Path "lib\resources\llvm\$LLVM_LIB.$LIB_EXT" -Destination "$OUT_BIN_DIR\libllvm-disas.$LIB_EXT" diff --git a/recipes/renode-cli/recipe.yaml b/recipes/renode-cli/recipe.yaml index 25c7a5b9e9b76..a7521a6446b99 100644 --- a/recipes/renode-cli/recipe.yaml +++ b/recipes/renode-cli/recipe.yaml @@ -11,11 +11,11 @@ source: - url: https://github.com/renode/renode/releases/download/v${{ version }}/renode_${{ version }}_source.tar.xz sha256: 40c50afe8db86a9c63f4a86b93116a6babd43bf241cfaac47b2c0d2cbc2b15a8 patches: + - patches/update-IronPython-Renode_NET.csproj.patch + - patches/update-cores.template_NET.csproj.patch + - patches/update-IronPython-Unittest_NET.csproj.patch - if: unix then: - - patches/update-IronPython-Renode_NET.csproj.patch - - patches/update-cores.template_NET.csproj.patch - - patches/update-IronPython-Unittest_NET.csproj.patch - patches/resolve-posix-unix.patch build: diff --git a/recipes/renode-cores/build.bat b/recipes/renode-cores/build.bat index d3b6491ea693f..5ab408c42c169 100644 --- a/recipes/renode-cores/build.bat +++ b/recipes/renode-cores/build.bat @@ -37,12 +37,12 @@ icacls "%PREFIX%\Library\lib\%PKG_NAME%" /grant Users:(OI)(CI)F /T robocopy "%CORES_BIN_PATH%\lib" "%PREFIX%\Library\lib\%PKG_NAME%" /E /COPY:DATSO :: Setting conda host environment variables -if not exist "%PREFIX%\etc\conda\activate.d\" mkdir "%PREFIX%\etc\conda\activate.d\" -if not exist "%PREFIX%\etc\conda\deactivate.d\" mkdir "%PREFIX%\etc\conda\deactivate.d\" - -copy "%RECIPE_DIR%\scripts\activate.bat" "%PREFIX%\etc\conda\activate.d\%PKG_NAME%-activate.bat" > nul -if %ERRORLEVEL% neq 0 exit /b %ERRORLEVEL% -copy "%RECIPE_DIR%\scripts\deactivate.bat" "%PREFIX%\etc\conda\deactivate.d\%PKG_NAME%-deactivate.bat" > nul -if %ERRORLEVEL% neq 0 exit /b %ERRORLEVEL% +:: if not exist "%PREFIX%\etc\conda\activate.d\" mkdir "%PREFIX%\etc\conda\activate.d\" +:: if not exist "%PREFIX%\etc\conda\deactivate.d\" mkdir "%PREFIX%\etc\conda\deactivate.d\" +:: +:: copy "%RECIPE_DIR%\scripts\activate.bat" "%PREFIX%\etc\conda\activate.d\%PKG_NAME%-activate.bat" > nul +:: if %ERRORLEVEL% neq 0 exit /b %ERRORLEVEL% +:: copy "%RECIPE_DIR%\scripts\deactivate.bat" "%PREFIX%\etc\conda\deactivate.d\%PKG_NAME%-deactivate.bat" > nul +:: if %ERRORLEVEL% neq 0 exit /b %ERRORLEVEL% endlocal diff --git a/recipes/renode-cores/build.sh b/recipes/renode-cores/build.sh index 9ec971f2df1ec..5e51a56c767a2 100644 --- a/recipes/renode-cores/build.sh +++ b/recipes/renode-cores/build.sh @@ -24,8 +24,8 @@ tar -c -C "${CORES_BIN_PATH}/lib" . | tar -x -C "${PREFIX}/lib/${PKG_NAME}" # Copy the [de]activate scripts to $PREFIX/etc/conda/[de]activate.d. # This will allow them to be run on environment activation. -for CHANGE in "activate" "deactivate" -do - mkdir -p "${PREFIX}/etc/conda/${CHANGE}.d" - cp "${RECIPE_DIR}/scripts/${CHANGE}.sh" "${PREFIX}/etc/conda/${CHANGE}.d/${PKG_NAME}-${CHANGE}.sh" -done \ No newline at end of file +# for CHANGE in "activate" "deactivate" +# do +# mkdir -p "${PREFIX}/etc/conda/${CHANGE}.d" +# cp "${RECIPE_DIR}/scripts/${CHANGE}.sh" "${PREFIX}/etc/conda/${CHANGE}.d/${PKG_NAME}-${CHANGE}.sh" +# done \ No newline at end of file diff --git a/recipes/renode-cores/recipe.yaml b/recipes/renode-cores/recipe.yaml index 31d1bfbb76ba3..26664f1b272ab 100644 --- a/recipes/renode-cores/recipe.yaml +++ b/recipes/renode-cores/recipe.yaml @@ -64,13 +64,7 @@ tests: - ${{ "Library/" if not unix }}lib/renode-cores/translate-sparc-le.so - ${{ "Library/" if not unix }}lib/renode-cores/translate-x86_64-le.so - ${{ "Library/" if not unix }}lib/renode-cores/translate-xtensa-le.so - - if: unix - then: - - etc/conda/activate.d/renode-cores-activate.sh - - etc/conda/deactivate.d/renode-cores-deactivate.sh - else: - - etc/conda/activate.d/renode-cores-activate.bat - - etc/conda/deactivate.d/renode-cores-deactivate.bat + about: homepage: https://github.com/renode/renode summary: "Antmicro's open source simulation and virtual development framework for complex embedded systems" diff --git a/recipes/renode-cores/scripts/activate.bat b/recipes/renode-cores/scripts/activate.bat deleted file mode 100755 index 11790d75cbde3..0000000000000 --- a/recipes/renode-cores/scripts/activate.bat +++ /dev/null @@ -1,8 +0,0 @@ -@echo off -@if defined RENODE_CORES_PATH ( - @set "_RENODE_CORES_PATH_BACKUP=%RENODE_CORES_PATH%" - :: Remove the last path from the PATH - @for %%i in ("%RENODE_CORES_PATH%") do @set "PATH=%%~dpi" -) -set RENODE_CORES_PATH=%CONDA_PREFIX%\Library\renode-cores -set "PATH=%RENODE_CORES_PATH%;%PATH%" diff --git a/recipes/renode-cores/scripts/activate.sh b/recipes/renode-cores/scripts/activate.sh deleted file mode 100644 index add69d61363d8..0000000000000 --- a/recipes/renode-cores/scripts/activate.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env bash - -export _RENODE_CORES_PATH_BACKUP=${RENODE_CORES_PATH:-} -export RENODE_CORES_PATH=${CONDA_PREFIX}/lib/renode-cores diff --git a/recipes/renode-cores/scripts/deactivate.bat b/recipes/renode-cores/scripts/deactivate.bat deleted file mode 100644 index 6960a91490575..0000000000000 --- a/recipes/renode-cores/scripts/deactivate.bat +++ /dev/null @@ -1,8 +0,0 @@ -@for %%i in ("%RENODE_CORES_PATH%") do @set "PATH=%%~dpi" - -@if defined _RENODE_CORES_PATH_BACKUP ( - @set "RENODE_CORES_PATH=%_RENODE_CORES_PATH_BACKUP%" - @set "_RENODE_CORES_PATH_BACKUP=" -) else ( - @set "RENODE_CORES_PATH=" -) diff --git a/recipes/renode-cores/scripts/deactivate.sh b/recipes/renode-cores/scripts/deactivate.sh deleted file mode 100644 index c771254bc675d..0000000000000 --- a/recipes/renode-cores/scripts/deactivate.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/env bash - -# Restore previous env vars if they were set. -unset RENODE_CORES_PATH -if [[ -n "$_RENODE_CORES_PATH_BACKUP" ]]; then - export RENODE_CORES_PATH=$_RENODE_CORES_PATH_BACKUP - unset _RENODE_CORES_PATH_BACKUP -fi \ No newline at end of file From dc9010db2a06e424d8794598f203aa61644fff0d Mon Sep 17 00:00:00 2001 From: memento Date: Sat, 1 Feb 2025 16:08:54 -0600 Subject: [PATCH 24/26] (dev) sed error? --- recipes/renode-cores/build.sh | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/recipes/renode-cores/build.sh b/recipes/renode-cores/build.sh index 5e51a56c767a2..2812235802f15 100644 --- a/recipes/renode-cores/build.sh +++ b/recipes/renode-cores/build.sh @@ -8,6 +8,13 @@ cp "cmake-renode-infrastructure/${CMAKEFILES_TXT}" "${SRC_DIR}/src/Infrastructur cp cmake-tlib/CMakeLists.txt "${SRC_DIR}/src/Infrastructure/src/Emulator/Cores/tlib" cp cmake-tlib/tcg/CMakeLists.txt "${SRC_DIR}/src/Infrastructure/src/Emulator/Cores/tlib/tcg" +if [[ "${target_platform}" == "osx-arm64" ]]; then + # We use Clang on osx-arm64, which does not support -Wno-error=clobbered/-Wno-error=clobbered + sed -i -E 's/add_definitions(-Wno-error=clobbered)/string(REPLACE "-Wno-error=clobbered" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")/' "${SRC_DIR}/src/Infrastructure/src/Emulator/Cores/tlib/CMakeLists.txt" + # Oddly, it does not find additional.h, trying to add the include path + sed -i -E 's| \$\{CMAKE_SOURCE_DIR\}| \$\{CMAKE_SOURCE_DIR\} \$\{CMAKE_SOURCE_DIR\}/\.\.|' "${SRC_DIR}/src/Infrastructure/src/Emulator/Cores/tlib/tcg/CMakeLists.txt" +fi + cp cmake-tlib/LICENSE "${RECIPE_DIR}/tlib-LICENSE" cp "${SRC_DIR}/src/Infrastructure/src/Emulator/Cores/tlib/softfloat-3/COPYING.txt" "${RECIPE_DIR}/softfloat-3-COPYING.txt" From 90942711c227b9445c530fdb22c1ac826afbd00d Mon Sep 17 00:00:00 2001 From: memento Date: Sun, 2 Feb 2025 09:09:06 -0600 Subject: [PATCH 25/26] (fix) win: .so not copied to cli. arm64: clobbered --- recipes/renode-cli/build.bat | 22 ++++++---------------- recipes/renode-cores/build.sh | 11 ++++++++--- 2 files changed, 14 insertions(+), 19 deletions(-) diff --git a/recipes/renode-cli/build.bat b/recipes/renode-cli/build.bat index 380849960dfc6..efeb279097177 100644 --- a/recipes/renode-cli/build.bat +++ b/recipes/renode-cli/build.bat @@ -1,39 +1,27 @@ @echo off setlocal enabledelayedexpansion -set "install_prefix=%PREFIX%\opt\%PKG_NAME%" - -:: for /f "tokens=*" %%i in ('dotnet --version') do set "dotnet_version=%%i" :: set "framework_version=%dotnet_version:~0,-2%" set "framework_version=8.0" -rem Patch the project files to use the correct .NET version -:: for /f "delims=" %%i in ('find lib src tests -name "*.csproj"') do ( -:: sed -i -E "s/([>;])net6.0([<;])/\1net${framework_version}\2/" "%%i" -:: sed -i -E "s|^((\s+))|\1\n\2\2CS0168;CS0219;CS8981;SYSLIB0050;SYSLIB0051|" "%%i" -:: ) -:: %BUILD_PREFIX%\Library\usr\bin\find.exe lib src tests -name "*.csproj" -exec sed -i -E ^ -:: -e "s/([>;])net6.0([<;])/\1net${framework_version}\2/" ^ -:: -e "s|^((\s+))|\1\n\2\2CS0168;CS0219;CS8981;SYSLIB0050;SYSLIB0051|" ^ -:: -e 's|^(\s+)<(Package)?Reference\s+Include="Mono.Posix".*\n||g' ^ -:: {} \; -:: %BUILD_PREFIX%\Library\usr\bin\find.exe . -type d -name "obj" -exec rm -rf {} \; -:: %BUILD_PREFIX%\Library\usr\bin\find.exe . -type d -name "bin" -exec rm -rf {} \; sed -i -E "s/(ReleaseHeadless\|Any .+ = )Debug/\1Release/" Renode_NET.sln rem Prevent CMake build since we provide the binaries mkdir "%SRC_DIR%\src\Infrastructure\src\Emulator\Cores\bin\Release\lib" -copy "%BUILD_PREFIX%\lib\renode-cores\*" "%SRC_DIR%\src\Infrastructure\src\Emulator\Cores\bin\Release\lib" +copy "%BUILD_PREFIX%\Library\lib\renode-cores\*" "%SRC_DIR%\src\Infrastructure\src\Emulator\Cores\bin\Release\lib" +if %errorlevel% neq 0 exit /b %errorlevel% rem Remove the C cores that are not built in this recipe del "%SRC_DIR%\src\Infrastructure\src\Emulator\Cores\translate*.cproj" rem Build with dotnet call powershell "%RECIPE_DIR%\helpers\renode_build_with_dotnet.ps1" %framework_version% +if %errorlevel% neq 0 exit /b %errorlevel% rem Install procedure mkdir "%PREFIX%\libexec\%PKG_NAME%" xcopy /e /i /y "output\bin\Release\net%framework_version%\*" "%PREFIX%\libexec\%PKG_NAME%" +if %errorlevel% neq 0 exit /b %errorlevel% mkdir "%PREFIX%\opt\%PKG_NAME%\scripts" mkdir "%PREFIX%\opt\%PKG_NAME%\platforms" @@ -53,7 +41,9 @@ xcopy /e /i /y "tools\sel4_extensions" "%PREFIX%\opt\%PKG_NAME%\tools" copy "lib\resources\styles\robot.css" "%PREFIX%\opt\%PKG_NAME%\tests" call tools\packaging\common_copy_licenses.bat "%PREFIX%\opt\%PKG_NAME%\licenses" linux +if %errorlevel% neq 0 exit /b %errorlevel% xcopy /e /i /y "%PREFIX%\opt\%PKG_NAME%\licenses" "license-files" +if %errorlevel% neq 0 exit /b %errorlevel% sed -i.bak "s#os\.path\.join(this_path, '\.\./lib/resources/styles/robot\.css')#os.path.join(this_path,'robot.css')#g" "%PREFIX%\opt\%PKG_NAME%\tests\robot_tests_provider.py" del "%PREFIX%\opt\%PKG_NAME%\tests\robot_tests_provider.py.bak" diff --git a/recipes/renode-cores/build.sh b/recipes/renode-cores/build.sh index 2812235802f15..90b108189cd96 100644 --- a/recipes/renode-cores/build.sh +++ b/recipes/renode-cores/build.sh @@ -9,10 +9,15 @@ cp cmake-tlib/CMakeLists.txt "${SRC_DIR}/src/Infrastructure/src/Emulator/Cores/t cp cmake-tlib/tcg/CMakeLists.txt "${SRC_DIR}/src/Infrastructure/src/Emulator/Cores/tlib/tcg" if [[ "${target_platform}" == "osx-arm64" ]]; then - # We use Clang on osx-arm64, which does not support -Wno-error=clobbered/-Wno-error=clobbered - sed -i -E 's/add_definitions(-Wno-error=clobbered)/string(REPLACE "-Wno-error=clobbered" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")/' "${SRC_DIR}/src/Infrastructure/src/Emulator/Cores/tlib/CMakeLists.txt" + # We use Clang on osx-arm64, which does not support -Wno-error=clobbered/-Wno-clobbered + sed -i -E 's/add_definitions\(-Wno-error=clobbered\)/add_compile_options(-Wno-unknown-warning-option -Wno-clobbered)/' \ + "${SRC_DIR}/src/Infrastructure/src/Emulator/Cores/CMakeLists.txt" \ + "${SRC_DIR}/src/Infrastructure/src/Emulator/Cores/tlib/CMakeLists.txt" \ + "${SRC_DIR}/src/Infrastructure/src/Emulator/Cores/tlib/tcg/CMakeLists.txt" + # Oddly, it does not find additional.h, trying to add the include path - sed -i -E 's| \$\{CMAKE_SOURCE_DIR\}| \$\{CMAKE_SOURCE_DIR\} \$\{CMAKE_SOURCE_DIR\}/\.\.|' "${SRC_DIR}/src/Infrastructure/src/Emulator/Cores/tlib/tcg/CMakeLists.txt" + sed -i -E 's| \$\{CMAKE_SOURCE_DIR\}| \$\{CMAKE_SOURCE_DIR\} \$\{CMAKE_SOURCE_DIR\}/tlib/tcg|' \ + "${SRC_DIR}/src/Infrastructure/src/Emulator/Cores/tlib/tcg/CMakeLists.txt" fi cp cmake-tlib/LICENSE "${RECIPE_DIR}/tlib-LICENSE" From b3063563ef500fac58be2d94a5293dd62d398963 Mon Sep 17 00:00:00 2001 From: memento Date: Tue, 4 Feb 2025 21:28:14 -0600 Subject: [PATCH 26/26] (fix) win build update --- recipes/renode-cli/build.bat | 138 ++++++++++-------- recipes/renode-cli/build.sh | 5 + recipes/renode-cli/helpers/build.ps1 | 90 ++++++++++++ .../helpers/renode_build_with_dotnet.ps1 | 58 +++----- 4 files changed, 195 insertions(+), 96 deletions(-) create mode 100644 recipes/renode-cli/helpers/build.ps1 diff --git a/recipes/renode-cli/build.bat b/recipes/renode-cli/build.bat index efeb279097177..a2e62d810ad13 100644 --- a/recipes/renode-cli/build.bat +++ b/recipes/renode-cli/build.bat @@ -1,67 +1,81 @@ @echo off setlocal enabledelayedexpansion -:: set "framework_version=%dotnet_version:~0,-2%" -set "framework_version=8.0" - -sed -i -E "s/(ReleaseHeadless\|Any .+ = )Debug/\1Release/" Renode_NET.sln - -rem Prevent CMake build since we provide the binaries -mkdir "%SRC_DIR%\src\Infrastructure\src\Emulator\Cores\bin\Release\lib" -copy "%BUILD_PREFIX%\Library\lib\renode-cores\*" "%SRC_DIR%\src\Infrastructure\src\Emulator\Cores\bin\Release\lib" -if %errorlevel% neq 0 exit /b %errorlevel% - -rem Remove the C cores that are not built in this recipe -del "%SRC_DIR%\src\Infrastructure\src\Emulator\Cores\translate*.cproj" - -rem Build with dotnet -call powershell "%RECIPE_DIR%\helpers\renode_build_with_dotnet.ps1" %framework_version% -if %errorlevel% neq 0 exit /b %errorlevel% - -rem Install procedure -mkdir "%PREFIX%\libexec\%PKG_NAME%" -xcopy /e /i /y "output\bin\Release\net%framework_version%\*" "%PREFIX%\libexec\%PKG_NAME%" +call powershell "%RECIPE_DIR%\helpers\build.ps1" if %errorlevel% neq 0 exit /b %errorlevel% -mkdir "%PREFIX%\opt\%PKG_NAME%\scripts" -mkdir "%PREFIX%\opt\%PKG_NAME%\platforms" -mkdir "%PREFIX%\opt\%PKG_NAME%\tests" -mkdir "%PREFIX%\opt\%PKG_NAME%\tools" -mkdir "%PREFIX%\opt\%PKG_NAME%\licenses" - -copy ".renode-root" "%PREFIX%\opt\%PKG_NAME%" -xcopy /e /i /y "scripts\*" "%PREFIX%\opt\%PKG_NAME%\scripts" -xcopy /e /i /y "platforms\*" "%PREFIX%\opt\%PKG_NAME%\platforms" -xcopy /e /i /y "tests\*" "%PREFIX%\opt\%PKG_NAME%\tests" -xcopy /e /i /y "tools\metrics_analyzer" "%PREFIX%\opt\%PKG_NAME%\tools" -xcopy /e /i /y "tools\execution_tracer" "%PREFIX%\opt\%PKG_NAME%\tools" -xcopy /e /i /y "tools\gdb_compare" "%PREFIX%\opt\%PKG_NAME%\tools" -xcopy /e /i /y "tools\sel4_extensions" "%PREFIX%\opt\%PKG_NAME%\tools" - -copy "lib\resources\styles\robot.css" "%PREFIX%\opt\%PKG_NAME%\tests" - -call tools\packaging\common_copy_licenses.bat "%PREFIX%\opt\%PKG_NAME%\licenses" linux -if %errorlevel% neq 0 exit /b %errorlevel% -xcopy /e /i /y "%PREFIX%\opt\%PKG_NAME%\licenses" "license-files" -if %errorlevel% neq 0 exit /b %errorlevel% - -sed -i.bak "s#os\.path\.join(this_path, '\.\./lib/resources/styles/robot\.css')#os.path.join(this_path,'robot.css')#g" "%PREFIX%\opt\%PKG_NAME%\tests\robot_tests_provider.py" -del "%PREFIX%\opt\%PKG_NAME%\tests\robot_tests_provider.py.bak" - -mkdir "%PREFIX%\bin" -( -echo @echo off -echo call %%DOTNET_ROOT%%\dotnet exec %%CONDA_PREFIX%%\libexec\renode-cli\Renode.dll %%* -) > "%PREFIX%\bin\renode.cmd" -chmod +x "%PREFIX%\bin\renode.cmd" - -( -echo @echo off -echo setlocal enabledelayedexpansion -echo set "STTY_CONFIG=%%stty -g 2^>nul%%" -echo python3 "%%CONDA_PREFIX%%\opt\renode-cli\tests\run_tests.py" --robot-framework-remote-server-full-directory "%%CONDA_PREFIX%%\libexec\renode-cli" %%* -echo set "RESULT_CODE=%%ERRORLEVEL%%" -echo if not "%%STTY_CONFIG%%"=="" stty "%%STTY_CONFIG%%" -echo exit /b %%RESULT_CODE%% -) > "%PREFIX%\bin\renode-test.cmd" -chmod +x "%PREFIX%\bin\renode-test.cmd" +:: for /f "tokens=1,2 delims=." %%a in ('dotnet --version') do ( +:: set "framework_version=%%a.%%b" +:: ) +:: +:: rem Patch the project files to use the correct .NET version +:: for /f "delims=" %%i in ('find lib src tests -name "*.csproj"') do ( +:: sed -i -E "s/([>;])net6\.0.*([<;])/\1net${framework_version}\2/" "%%i" +:: sed -i -E "s|^((\s+))|\1\n\2\2CS0168;CS0219;CS8981;SYSLIB0050;SYSLIB0051|" "%%i" +:: ) +:: sed -i -E "s/(ReleaseHeadless\|Any .+ = )Debug/\1Release/" Renode_NET.sln +:: if %errorlevel% neq 0 exit /b %errorlevel% +:: +:: :: Update System.Drawing.Common to 5.0.3 +:: sed -i -E "s|||" \ +:: "%SRC_DIR%"\lib\termsharp\TermSharp_NET.csproj \ +:: "%SRC_DIR%"\lib\termsharp\xwt\Xwt.*\Xwt.*.csproj +:: if %errorlevel% neq 0 exit /b %errorlevel% +:: +:: mkdir "%SRC_DIR%\src\Infrastructure\src\Emulator\Cores\bin\Release\lib" +:: copy "%BUILD_PREFIX%\Library\lib\renode-cores\*" "%SRC_DIR%\src\Infrastructure\src\Emulator\Cores\bin\Release\lib" +:: if %errorlevel% neq 0 exit /b %errorlevel% +:: +:: rem Remove the C cores project that are not built in this recipe +:: del "%SRC_DIR%\src\Infrastructure\src\Emulator\Cores\translate*.cproj" +:: +:: rem Build with dotnet +:: call powershell "%RECIPE_DIR%\helpers\renode_build_with_dotnet.ps1" %framework_version% +:: if %errorlevel% neq 0 exit /b %errorlevel% +:: +:: rem Install procedure +:: mkdir "%PREFIX%\libexec\%PKG_NAME%" +:: xcopy /e /i /y "output\bin\Release\net%framework_version%\*" "%PREFIX%\libexec\%PKG_NAME%" +:: if %errorlevel% neq 0 exit /b %errorlevel% +:: +:: mkdir "%PREFIX%\opt\%PKG_NAME%\scripts" +:: mkdir "%PREFIX%\opt\%PKG_NAME%\platforms" +:: mkdir "%PREFIX%\opt\%PKG_NAME%\tests" +:: mkdir "%PREFIX%\opt\%PKG_NAME%\tools" +:: mkdir "%PREFIX%\opt\%PKG_NAME%\licenses" +:: +:: copy ".renode-root" "%PREFIX%\opt\%PKG_NAME%" +:: xcopy /e /i /y "scripts\*" "%PREFIX%\opt\%PKG_NAME%\scripts" +:: xcopy /e /i /y "platforms\*" "%PREFIX%\opt\%PKG_NAME%\platforms" +:: xcopy /e /i /y "tests\*" "%PREFIX%\opt\%PKG_NAME%\tests" +:: xcopy /e /i /y "tools\metrics_analyzer" "%PREFIX%\opt\%PKG_NAME%\tools" +:: xcopy /e /i /y "tools\execution_tracer" "%PREFIX%\opt\%PKG_NAME%\tools" +:: xcopy /e /i /y "tools\gdb_compare" "%PREFIX%\opt\%PKG_NAME%\tools" +:: xcopy /e /i /y "tools\sel4_extensions" "%PREFIX%\opt\%PKG_NAME%\tools" +:: +:: copy "lib\resources\styles\robot.css" "%PREFIX%\opt\%PKG_NAME%\tests" +:: +:: call tools\packaging\common_copy_licenses.bat "%PREFIX%\opt\%PKG_NAME%\licenses" linux +:: xcopy /e /i /y "%PREFIX%\opt\%PKG_NAME%\licenses" "license-files" +:: +:: sed -i.bak "s#os\.path\.join(this_path, '\.\./lib/resources/styles/robot\.css')#os.path.join(this_path,'robot.css')#g" "%PREFIX%\opt\%PKG_NAME%\tests\robot_tests_provider.py" +:: del "%PREFIX%\opt\%PKG_NAME%\tests\robot_tests_provider.py.bak" +:: +:: mkdir "%PREFIX%\bin" +:: ( +:: echo @echo off +:: echo call %%DOTNET_ROOT%%\dotnet exec %%CONDA_PREFIX%%\libexec\renode-cli\Renode.dll %%* +:: ) > "%PREFIX%\bin\renode.cmd" +:: chmod +x "%PREFIX%\bin\renode.cmd" +:: +:: ( +:: echo @echo off +:: echo setlocal enabledelayedexpansion +:: echo set "STTY_CONFIG=%%stty -g 2^>nul%%" +:: echo python3 "%%CONDA_PREFIX%%\opt\renode-cli\tests\run_tests.py" --robot-framework-remote-server-full-directory "%%CONDA_PREFIX%%\libexec\renode-cli" %%* +:: echo set "RESULT_CODE=%%ERRORLEVEL%%" +:: echo if not "%%STTY_CONFIG%%"=="" stty "%%STTY_CONFIG%%" +:: echo exit /b %%RESULT_CODE%% +:: ) > "%PREFIX%\bin\renode-test.cmd" +:: chmod +x "%PREFIX%\bin\renode-test.cmd" +:: \ No newline at end of file diff --git a/recipes/renode-cli/build.sh b/recipes/renode-cli/build.sh index db15bc6cd5885..5c2c5dfa45b48 100644 --- a/recipes/renode-cli/build.sh +++ b/recipes/renode-cli/build.sh @@ -21,6 +21,11 @@ find . -type d -name "obj" -exec rm -rf {} + find . -type d -name "bin" -exec rm -rf {} + sed -i -E 's/(ReleaseHeadless\|Any .+ = )Debug/\1Release/' Renode_NET.sln +# Update System.Drawing.Common to 5.0.3 +sed -i -E 's|||' \ + "${SRC_DIR}"/lib/termsharp/TermSharp_NET.csproj \ + "${SRC_DIR}"/lib/termsharp/xwt/Xwt.*/Xwt.*.csproj + # Prevent CMake build since we provide the binaries mkdir -p ${SRC_DIR}/src/Infrastructure/src/Emulator/Cores/bin/Release/lib cp ${BUILD_PREFIX}/lib/renode-cores/* ${SRC_DIR}/src/Infrastructure/src/Emulator/Cores/bin/Release/lib diff --git a/recipes/renode-cli/helpers/build.ps1 b/recipes/renode-cli/helpers/build.ps1 new file mode 100644 index 0000000000000..eb22fe77c5f7c --- /dev/null +++ b/recipes/renode-cli/helpers/build.ps1 @@ -0,0 +1,90 @@ +# Set framework version +$dotnet_version = (dotnet --version) +if ($dotnet_version -match "^(\d+\.\d+)") { + $framework_version = $Matches[1] +} else { + Write-Error "Could not determine .NET version. Using default 8.0." + $framework_version = "8.0" +} + +$SRC_DIR = Resolve-Path "$Env:SRC_DIR" +$BUILD_PREFIX = Resolve-Path "$Env:BUILD_PREFIX" +$PREFIX = Resolve-Path "$Env:PREFIX" +$PKG_NAME = $Env:PKG_NAME + +# Update Renode_NET.sln (replace Debug with Release) +(Get-Content "Renode_NET.sln") | ForEach-Object { $_ -replace "(ReleaseHeadless\|Any CPU\..+ = )Debug", '$1Release' } | Set-Content "Renode_NET.sln" + +$csprojFiles = Get-ChildItem -Path $SRC_DIR -Filter "*.csproj" -Recurse +foreach ($file in $csprojFiles) { + $csprojContent = (Get-Content $file.FullName) + + # Update System.Drawing.Common to 5.0.3 + $csprojContent = $csprojContent -replace "", "" + + # Add package reference only to UI_NET.csproj + if ($file.FullName -match "(UI)_NET\.csproj") { + if ($csprojContent -notmatch "PresentationFramework") { + # $csprojContent = $csprojContent -replace "(<\/Project>)", " `n `n `n`$1" + $csprojContent = $csprojContent -replace "(<\/PropertyGroup>)", " true`n`$1" + } + } + + # Remove excessive warnings .csproj files (TargetFramework and NoWarn) + $csprojContent = $csprojContent -replace "()", "`$1`n`t`tCA1416;CS0649;CS0168;CS0219;CS8981;SYSLIB0050;SYSLIB0051" + Set-Content -Path $file.FullName -Value $csprojContent +} + +# Install renode-cores .so where they are looked for +New-Item -ItemType Directory -Path "$SRC_DIR\src\Infrastructure\src\Emulator\Cores\bin\Release\lib" -Force +Copy-Item -Path "$BUILD_PREFIX\Library\lib\renode-cores\*" -Destination "$SRC_DIR\src\Infrastructure\src\Emulator\Cores\bin\Release\lib" -Force + +# Remove C cores not built in this recipe +Remove-Item -Path "$SRC_DIR\src\Infrastructure\src\Emulator\Cores\translate*.cproj" -Force + +# Build with dotnet +New-Item -ItemType Directory -Path "$PREFIX\Library\lib" -Force +& $Env:RECIPE_DIR\helpers\renode_build_with_dotnet.ps1 $framework_version + +# Install procedure +New-Item -ItemType Directory -Path "$PREFIX\libexec\$PKG_NAME" -Force +Copy-Item -Path "$SRC_DIR\output\bin\Release\net$framework_version-windows\*" -Destination "$PREFIX\libexec\$PKG_NAME\" -Recurse -Force + +New-Item -ItemType Directory -Path "$PREFIX\opt\$PKG_NAME\scripts", "$PREFIX\opt\$PKG_NAME\platforms", "$PREFIX\opt\$PKG_NAME\tests", "$PREFIX\opt\$PKG_NAME\tools", "$PREFIX\opt\$PKG_NAME\licenses" -Force + +Copy-Item -Path "$SRC_DIR\.renode-root" -Destination "$PREFIX\opt\$PKG_NAME" -Force +Copy-Item -Path "$SRC_DIR\scripts\*" -Destination "$PREFIX\opt\$PKG_NAME\scripts" -Recurse -Force +Copy-Item -Path "$SRC_DIR\platforms\*" -Destination "$PREFIX\opt\$PKG_NAME\platforms" -Recurse -Force +Copy-Item -Path "$SRC_DIR\tests\*" -Destination "$PREFIX\opt\$PKG_NAME\tests" -Recurse -Force +Copy-Item -Path "$SRC_DIR\tools\metrics_analyzer", "$SRC_DIR\tools\execution_tracer", "$SRC_DIR\tools\gdb_compare", "$SRC_DIR\tools\sel4_extensions" -Destination "$PREFIX\opt\$PKG_NAME\tools" -Recurse -Force + +Copy-Item "$SRC_DIR\lib\resources\styles\robot.css" "$PREFIX\opt\$PKG_NAME\tests" -Force + +$licensesPath = (Resolve-Path "$PREFIX\opt\$PKG_NAME\licenses").Path -replace '\\', '/' +$scriptPath = (Resolve-Path "$SRC_DIR\tools\packaging\common_copy_licenses.sh").Path -replace '\\', '/' +$command = "'$scriptPath' '$licensesPath' 'linux'" +& "bash.exe" -c $command +Copy-Item -Path "$PREFIX\opt\$PKG_NAME\licenses" -Destination "license-files" -Recurse -Force + +# Update robot_tests_provider.py (replace path to robot.css) +(Get-Content "$PREFIX\opt\$PKG_NAME\tests\robot_tests_provider.py") | ForEach-Object { $_ -replace "os\.path\.join\(this_path, '\.\./lib/resources/styles/robot\.css'\)", "os.path.join(this_path,'robot.css')" } | Set-Content "$PREFIX\opt\$PKG_NAME\tests\robot_tests_provider.py" + +# Create renode.cmd +New-Item -ItemType File -Path "$PREFIX\bin\renode.cmd" -Force +@" +@echo off +call %DOTNET_ROOT%\dotnet exec %CONDA_PREFIX%\libexec\renode-cli\Renode.dll %* +"@ | Out-File -FilePath "$PREFIX\bin\renode.cmd" -Encoding ascii +# No chmod +x needed in PowerShell + +# Create renode-test.cmd +New-Item -ItemType File -Path "$PREFIX\bin\renode-test.cmd" -Force +@" +@echo off +setlocal enabledelayedexpansion +set "STTY_CONFIG=%stty -g 2^>nul%" +python3 "%CONDA_PREFIX%\opt\renode-cli\tests\run_tests.py" --robot-framework-remote-server-full-directory "%CONDA_PREFIX%\libexec\renode-cli" %* +set "RESULT_CODE=%ERRORLEVEL%" +if not "%STTY_CONFIG%"=="" stty "%STTY_CONFIG%" +exit /b %RESULT_CODE% +"@ | Out-File -FilePath "$PREFIX\bin\renode-test.cmd" -Encoding ascii diff --git a/recipes/renode-cli/helpers/renode_build_with_dotnet.ps1 b/recipes/renode-cli/helpers/renode_build_with_dotnet.ps1 index b44d9c52a19ac..0b851e1a4e377 100755 --- a/recipes/renode-cli/helpers/renode_build_with_dotnet.ps1 +++ b/recipes/renode-cli/helpers/renode_build_with_dotnet.ps1 @@ -2,80 +2,70 @@ param ( [string]$framework_version ) -$OUTPUT_DIRECTORY = "${env:SRC_DIR}\output" +$SRC_DIR = Resolve-Path "$Env:SRC_DIR" + +$OUTPUT_DIRECTORY = "$SRC_DIR\output" $CONFIGURATION = "Release" $BUILD_PLATFORM = "Any CPU" $HEADLESS = $true $NET = $true -$TFM = "net$framework_version" +$TFM = "net$framework_version-windows" $HOST_ARCH = "i386" $CMAKE_COMMON = "" $PARAMS = @() -if ($env:CC) { - $PARAMS += "p:CompilerPath=$env:CC" - $PARAMS += "p:LinkerPath=$env:CC" +if ($Env:CC) { + $PARAMS += "/p:CompilerPath=$Env:CC" + $PARAMS += "/p:LinkerPath=$Env:CC" } -if ($env:AR) { - $PARAMS += "p:ArPath=$env:AR" +if ($Env:AR) { + $PARAMS += "/p:ArPath=$Env:AR" } $PARAMS += $args if ($HEADLESS) { $BUILD_TARGET = "Headless" - $PARAMS += "p:GUI_DISABLED=true" -} else { - $BUILD_TARGET = "Mono" + $PARAMS += "/p:GUI_DISABLED=true" } $DirectoryBuildTargetsContent = @" $TFM - ${env:OS_SPECIFIC_TARGET_OPTS} + ${Env:OS_SPECIFIC_TARGET_OPTS} "@ -$DirectoryBuildTargetsPath = "${env:SRC_DIR}\Directory.Build.targets" +$DirectoryBuildTargetsPath = "$SRC_DIR\Directory.Build.targets" Set-Content -Path $DirectoryBuildTargetsPath -Value $DirectoryBuildTargetsContent -$env:DOTNET_CLI_TELEMETRY_OPTOUT = 1 -$CS_COMPILER = "dotnet build" -$TARGET = "${env:SRC_DIR}\Renode_NET.sln" +$Env:DOTNET_CLI_TELEMETRY_OPTOUT = 1 +$CS_COMPILER = "dotnet build /m" +$TARGET = "$SRC_DIR\Renode_NET.sln" $BUILD_TYPE = "dotnet" -$OUT_BIN_DIR = "${env:SRC_DIR}\output\bin\$CONFIGURATION" +$OUT_BIN_DIR = "$SRC_DIR\output\bin\$CONFIGURATION" $BUILD_TYPE_FILE = "$OUT_BIN_DIR\build_type" # Copy properties file according to the running OS +New-Item -ItemType Directory -Force -Path $OUT_BIN_DIR New-Item -ItemType Directory -Force -Path $OUTPUT_DIRECTORY # Remove-Item -Force -Path "$OUTPUT_DIRECTORY\properties.csproj" -$PROP_FILE = "${env:SRC_DIR}\src\Infrastructure\src\Emulator\Cores\windows-properties_NET.csproj" +$PROP_FILE = "$SRC_DIR\src\Infrastructure\src\Emulator\Cores\windows-properties_NET.csproj" Copy-Item -Path $PROP_FILE -Destination "$OUTPUT_DIRECTORY\properties.csproj" -$CORES_PATH = "${env:SRC_DIR}\src\Infrastructure\src\Emulator\Cores" +$CORES_PATH = "$SRC_DIR\src\Infrastructure\src\Emulator\Cores" -$PARAMS += "p:Configuration=${CONFIGURATION}${BUILD_TARGET}" -$PARAMS += "p:GenerateFullPaths=true" -$PARAMS += "p:Platform=`"$BUILD_PLATFORM`"" +$PARAMS += "/p:Configuration=${CONFIGURATION}${BUILD_TARGET}" +$PARAMS += "/p:GenerateFullPaths=true" +$PARAMS += "/p:Platform=`"$BUILD_PLATFORM`"" # build -function Build-Args-Helper { - param ( - [string[]]$params - ) - $retStr = "" - foreach ($p in $params) { - $retStr += " -$p" - } - return $retStr -} - -Invoke-Expression "$CS_COMPILER $(Build-Args-Helper -params $PARAMS) $TARGET" +Invoke-Expression "$CS_COMPILER @PARAMS $TARGET" Set-Content -Path $BUILD_TYPE_FILE -Value $BUILD_TYPE # copy llvm library $LLVM_LIB = "libllvm-disas" $LIB_EXT = "dll" -Copy-Item -Path "lib\resources\llvm\$LLVM_LIB.$LIB_EXT" -Destination "$OUT_BIN_DIR\libllvm-disas.$LIB_EXT" +Copy-Item -Path "$SRC_DIR\lib\resources\llvm\$LLVM_LIB.$LIB_EXT" -Destination "$OUT_BIN_DIR\libllvm-disas.$LIB_EXT"