From 32b913166cb7a278c866bec8476c5eb9dbfed40b Mon Sep 17 00:00:00 2001 From: Sean Cross Date: Tue, 7 Nov 2023 12:32:27 +0800 Subject: [PATCH] rebuild: add xous-specific build scripts Signed-off-by: Sean Cross --- rebuild.ps1 | 119 ++++++++++++++++++++++++++++++++++++++++++++++++++++ rebuild.sh | 93 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 212 insertions(+) create mode 100755 rebuild.ps1 create mode 100755 rebuild.sh diff --git a/rebuild.ps1 b/rebuild.ps1 new file mode 100755 index 0000000000000..b55d592a128d3 --- /dev/null +++ b/rebuild.ps1 @@ -0,0 +1,119 @@ +# Everything you push to main will do a test build, and let you know if it breaks. +# +# Things only get released if you tag it. And the actual build is based on the tag. +# Without tagging it, nothing is released and it doesn't affect anyone at all, aside +# from people building it from source. +# +# Look at the list of tags: +# +# https://github.com/betrusted-io/rust/tags +# +# We increment the 4th decimal. So far with the 1.59.0 branch, we've had two releases: 1.59.0.1 and 1.59.0.2. If you decided to release a new version of libstd, you would do: +# +# git tag -a 1.59.0.3 # Commit a message, indicating what you've changed +# git push --tags +# +# That would build and release a new version. + +$ErrorActionPreference = "Stop" + +Function Test-CommandExists { + Param ($command) + $oldPreference = $ErrorActionPreference + $ErrorActionPreference = 'stop' + try { if (Get-Command $command) { return $true } } + Catch { return $false } + Finally { $ErrorActionPreference = $oldPreference } +} #end function test-CommandExists + +#$env:RUST_TARGET_PATH = $(rustc --print sysroot) +$rust_sysroot = $(rustc --print sysroot) + +$env:RUST_COMPILER_RT_ROOT = "$(Get-Location)\src\llvm-project\compiler-rt" +$env:CARGO_PROFILE_RELEASE_DEBUG = 0 +$env:CARGO_PROFILE_RELEASE_OPT_LEVEL = "" +$env:CARGO_PROFILE_RELEASE_DEBUG_ASSERTIONS = "true" +$env:RUSTC_BOOTSTRAP = 1 +$env:RUSTFLAGS = "-Cforce-unwind-tables=yes -Cembed-bitcode=yes" +$env:__CARGO_DEFAULT_LIB_METADATA = "stablestd" + +# Set up the C compiler. We need to explicitly specify these variables +# because the `cc` package obviously doesn't recognize our target triple. +if (Test-CommandExists riscv32-unknown-elf-gcc) { + $env:CC = "riscv32-unknown-elf-gcc" + $env:AR = "riscv32-unknown-elf-ar" +} +elseif (Test-CommandExists riscv-none-embed-gcc) { + $env:CC = "riscv-none-embed-gcc" + $env:AR = "riscv-none-embed-ar" +} +elseif (Test-CommandExists riscv-none-elf-gcc) { + $env:CC = "riscv-none-elf-gcc" + $env:AR = "riscv-none-elf-ar" +} +elseif (Test-CommandExists riscv64-unknown-elf-gcc) { + $env:CC = "riscv64-unknown-elf-gcc" + $env:AR = "riscv64-unknown-elf-ar" +} +else { + throw "No C compiler found for riscv" +} + +$src_path = ".\library\target\riscv32imac-unknown-xous-elf\release\deps" +$dest_path = "$rust_sysroot\lib\rustlib\riscv32imac-unknown-xous-elf" +$dest_lib_path = "$dest_path\lib" +function Get-ItemBaseName { + param ($ItemName) + # Write-Host "Item name: $ItemName" + $sub_strings = $ItemName -split "-" + $last_string_count = $sub_strings.Count + $ItemName -replace "-$($sub_strings[$last_string_count-1])", "" + # return $result +} + +if (-Not( Test-Path $dest_lib_path)) { + New-Item -Path $dest_lib_path -ItemType Directory +} + +$(rustc --version).split(" ")[1] | New-Item -Path "$dest_path\RUST_VERSION" -force + +# Remove stale objects +Remove-Item "$dest_lib_path\*.rlib" + +$previous_libraries = @{} + +if (Test-Path $src_path) { + ForEach ($item in Get-ChildItem "$src_path\*.rlib") { + $base_string = Get-ItemBaseName ($item.Name) + # Write-Output "Base string is $base_string" + if ($previous_libraries.ContainsKey($base_string)) { + if (-not $base_string -like "libcfg_if*") { + throw "There is a duplicate of $base_string!" + } + } else { + $previous_libraries.add($base_string, $item.Name) + } + } +} + +cargo build ` + --target riscv32imac-unknown-xous-elf ` + -Zbinary-dep-depinfo ` + --release ` + --features "panic-unwind compiler-builtins-c compiler-builtins-mem" ` + --manifest-path "library/sysroot/Cargo.toml" +if ($LastExitCode -ne 0) { + "Cargo exited with $LastExitCode" +} + +ForEach ($item in Get-ChildItem "$src_path\*.rlib") { + $base_string = Get-ItemBaseName ($item.Name) + # Write-Output "Base string is $base_string" + if ($previous_libraries.ContainsKey($base_string)) { + if ($previous_libraries[$base_string] -ne $item.Name) { + Remove-Item "$src_path\$($previous_libraries[$base_string])" + } + } +} + +Copy-Item "$src_path\*.rlib" "$dest_lib_path" diff --git a/rebuild.sh b/rebuild.sh new file mode 100755 index 0000000000000..a0d1b765d96db --- /dev/null +++ b/rebuild.sh @@ -0,0 +1,93 @@ +#!/usr/bin/env bash +# Everything you push to main will do a test build, and let you know if it breaks. +# +# Things only get released if you tag it. And the actual build is based on the tag. +# Without tagging it, nothing is released and it doesn't affect anyone at all, aside +# from people building it from source. +# +# Look at the list of tags: +# +# https://github.com/betrusted-io/rust/tags +# +# We increment the 4th decimal. So far with the 1.59.0 branch, we've had two releases: 1.59.0.1 and 1.59.0.2. If you decided to release a new version of libstd, you would do: +# +# git tag -a 1.59.0.3 # Commit a message, indicating what you've changed +# git push --tags +# +# That would build and release a new version. + +if [ -z $RUST_TOOLCHAIN ] +then + RUST_TOOLCHAIN="" +fi + +set -e +set -u +# set -x +set -o pipefail + +rust_sysroot=$(rustc $RUST_TOOLCHAIN --print sysroot) + +export RUST_COMPILER_RT_ROOT="$(pwd)/src/llvm-project/compiler-rt" +export CARGO_PROFILE_RELEASE_DEBUG=0 +export CARGO_PROFILE_RELEASE_OPT_LEVEL="3" +export CARGO_PROFILE_RELEASE_DEBUG_ASSERTIONS="true" +export RUSTC_BOOTSTRAP=1 +export RUSTFLAGS="-Cforce-unwind-tables=yes -Cembed-bitcode=yes" +export __CARGO_DEFAULT_LIB_METADATA="stablestd" + +command_exists() { + which $1 &> /dev/null && $1 --version 2>&1 > /dev/null +} + +# Set up the C compiler. We need to explicitly specify these variables +# because the `cc` package obviously doesn't recognize our target triple. +if [ ! -z $CC ] +then + echo "Using compiler $CC" +elif command_exists riscv32-unknown-elf-gcc +then + export CC="riscv32-unknown-elf-gcc" + export AR="riscv32-unknown-elf-ar" +elif command_exists riscv-none-embed-gcc +then + export CC ="riscv-none-embed-gcc" + export AR ="riscv-none-embed-ar" +elif command_exists riscv64-unknown-elf-gcc +then + export CC="riscv64-unknown-elf-gcc" + export AR="riscv64-unknown-elf-ar" +else + echo "No C compiler found for riscv" 1>&2 + exit 1 +fi + +src_path="./library/target/riscv32imac-unknown-xous-elf/release/deps" +dest_path="$rust_sysroot/lib/rustlib/riscv32imac-unknown-xous-elf" +dest_lib_path="$dest_path/lib" + +mkdir -p $dest_lib_path + +rustc $RUST_TOOLCHAIN --version | awk '{print $2}' > "$dest_path/RUST_VERSION" + +# Remove stale objects +rm -f $dest_lib_path/*.rlib + +# TODO: Use below to remove duplicates +# previous_libraries=$(ls -1 $src_path/*.rlib) + +cargo $RUST_TOOLCHAIN build \ + --target riscv32imac-unknown-xous-elf \ + -Zbinary-dep-depinfo \ + --release \ + --features "panic-unwind compiler-builtins-c compiler-builtins-mem" \ + --manifest-path "library/sysroot/Cargo.toml" || exit 1 + +# TODO: Remove duplicates here by comparing it with $previous_libraries +for new_item in $(ls -1 $src_path/*.rlib) +do + file=$(basename $new_item) + base_string=$(echo $file | rev | cut -d- -f2- | rev) +done + +cp $src_path/*.rlib "$dest_lib_path"