Skip to content

Commit 5569b4e

Browse files
committed
rebuild: add xous-specific build scripts
Signed-off-by: Sean Cross <[email protected]>
1 parent 35892e9 commit 5569b4e

File tree

2 files changed

+212
-0
lines changed

2 files changed

+212
-0
lines changed

rebuild.ps1

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
# Everything you push to main will do a test build, and let you know if it breaks.
2+
#
3+
# Things only get released if you tag it. And the actual build is based on the tag.
4+
# Without tagging it, nothing is released and it doesn't affect anyone at all, aside
5+
# from people building it from source.
6+
#
7+
# Look at the list of tags:
8+
#
9+
# https://github.com/betrusted-io/rust/tags
10+
#
11+
# 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:
12+
#
13+
# git tag -a 1.59.0.3 # Commit a message, indicating what you've changed
14+
# git push --tags
15+
#
16+
# That would build and release a new version.
17+
18+
$ErrorActionPreference = "Stop"
19+
20+
Function Test-CommandExists {
21+
Param ($command)
22+
$oldPreference = $ErrorActionPreference
23+
$ErrorActionPreference = 'stop'
24+
try { if (Get-Command $command) { return $true } }
25+
Catch { return $false }
26+
Finally { $ErrorActionPreference = $oldPreference }
27+
} #end function test-CommandExists
28+
29+
#$env:RUST_TARGET_PATH = $(rustc --print sysroot)
30+
$rust_sysroot = $(rustc --print sysroot)
31+
32+
$env:RUST_COMPILER_RT_ROOT = "$(Get-Location)\src\llvm-project\compiler-rt"
33+
$env:CARGO_PROFILE_RELEASE_DEBUG = 0
34+
$env:CARGO_PROFILE_RELEASE_OPT_LEVEL = ""
35+
$env:CARGO_PROFILE_RELEASE_DEBUG_ASSERTIONS = "true"
36+
$env:RUSTC_BOOTSTRAP = 1
37+
$env:RUSTFLAGS = "-Cforce-unwind-tables=yes -Cembed-bitcode=yes -Zforce-unstable-if-unmarked"
38+
$env:__CARGO_DEFAULT_LIB_METADATA = "stablestd"
39+
40+
# Set up the C compiler. We need to explicitly specify these variables
41+
# because the `cc` package obviously doesn't recognize our target triple.
42+
if (Test-CommandExists riscv32-unknown-elf-gcc) {
43+
$env:CC = "riscv32-unknown-elf-gcc"
44+
$env:AR = "riscv32-unknown-elf-ar"
45+
}
46+
elseif (Test-CommandExists riscv-none-embed-gcc) {
47+
$env:CC = "riscv-none-embed-gcc"
48+
$env:AR = "riscv-none-embed-ar"
49+
}
50+
elseif (Test-CommandExists riscv-none-elf-gcc) {
51+
$env:CC = "riscv-none-elf-gcc"
52+
$env:AR = "riscv-none-elf-ar"
53+
}
54+
elseif (Test-CommandExists riscv64-unknown-elf-gcc) {
55+
$env:CC = "riscv64-unknown-elf-gcc"
56+
$env:AR = "riscv64-unknown-elf-ar"
57+
}
58+
else {
59+
throw "No C compiler found for riscv"
60+
}
61+
62+
$src_path = ".\library\target\riscv32imac-unknown-xous-elf\release\deps"
63+
$dest_path = "$rust_sysroot\lib\rustlib\riscv32imac-unknown-xous-elf"
64+
$dest_lib_path = "$dest_path\lib"
65+
function Get-ItemBaseName {
66+
param ($ItemName)
67+
# Write-Host "Item name: $ItemName"
68+
$sub_strings = $ItemName -split "-"
69+
$last_string_count = $sub_strings.Count
70+
$ItemName -replace "-$($sub_strings[$last_string_count-1])", ""
71+
# return $result
72+
}
73+
74+
if (-Not( Test-Path $dest_lib_path)) {
75+
New-Item -Path $dest_lib_path -ItemType Directory
76+
}
77+
78+
$(rustc --version).split(" ")[1] | New-Item -Path "$dest_path\RUST_VERSION" -force
79+
80+
# Remove stale objects
81+
Remove-Item "$dest_lib_path\*.rlib"
82+
83+
$previous_libraries = @{}
84+
85+
if (Test-Path $src_path) {
86+
ForEach ($item in Get-ChildItem "$src_path\*.rlib") {
87+
$base_string = Get-ItemBaseName ($item.Name)
88+
# Write-Output "Base string is $base_string"
89+
if ($previous_libraries.ContainsKey($base_string)) {
90+
if (-not $base_string -like "libcfg_if*") {
91+
throw "There is a duplicate of $base_string!"
92+
}
93+
} else {
94+
$previous_libraries.add($base_string, $item.Name)
95+
}
96+
}
97+
}
98+
99+
cargo build `
100+
--target riscv32imac-unknown-xous-elf `
101+
-Zbinary-dep-depinfo `
102+
--release `
103+
--features "panic-unwind compiler-builtins-c compiler-builtins-mem" `
104+
--manifest-path "library/sysroot/Cargo.toml"
105+
if ($LastExitCode -ne 0) {
106+
"Cargo exited with $LastExitCode"
107+
}
108+
109+
ForEach ($item in Get-ChildItem "$src_path\*.rlib") {
110+
$base_string = Get-ItemBaseName ($item.Name)
111+
# Write-Output "Base string is $base_string"
112+
if ($previous_libraries.ContainsKey($base_string)) {
113+
if ($previous_libraries[$base_string] -ne $item.Name) {
114+
Remove-Item "$src_path\$($previous_libraries[$base_string])"
115+
}
116+
}
117+
}
118+
119+
Copy-Item "$src_path\*.rlib" "$dest_lib_path"

rebuild.sh

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
#!/usr/bin/env bash
2+
# Everything you push to main will do a test build, and let you know if it breaks.
3+
#
4+
# Things only get released if you tag it. And the actual build is based on the tag.
5+
# Without tagging it, nothing is released and it doesn't affect anyone at all, aside
6+
# from people building it from source.
7+
#
8+
# Look at the list of tags:
9+
#
10+
# https://github.com/betrusted-io/rust/tags
11+
#
12+
# 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:
13+
#
14+
# git tag -a 1.59.0.3 # Commit a message, indicating what you've changed
15+
# git push --tags
16+
#
17+
# That would build and release a new version.
18+
19+
if [ -z $RUST_TOOLCHAIN ]
20+
then
21+
RUST_TOOLCHAIN=""
22+
fi
23+
24+
set -e
25+
set -u
26+
# set -x
27+
set -o pipefail
28+
29+
rust_sysroot=$(rustc $RUST_TOOLCHAIN --print sysroot)
30+
31+
export RUST_COMPILER_RT_ROOT="$(pwd)/src/llvm-project/compiler-rt"
32+
export CARGO_PROFILE_RELEASE_DEBUG=0
33+
export CARGO_PROFILE_RELEASE_OPT_LEVEL="3"
34+
export CARGO_PROFILE_RELEASE_DEBUG_ASSERTIONS="true"
35+
export RUSTC_BOOTSTRAP=1
36+
export RUSTFLAGS="-Cforce-unwind-tables=yes -Cembed-bitcode=yes -Zforce-unstable-if-unmarked"
37+
export __CARGO_DEFAULT_LIB_METADATA="stablestd"
38+
39+
command_exists() {
40+
which $1 &> /dev/null && $1 --version 2>&1 > /dev/null
41+
}
42+
43+
# Set up the C compiler. We need to explicitly specify these variables
44+
# because the `cc` package obviously doesn't recognize our target triple.
45+
if [ ! -z $CC ]
46+
then
47+
echo "Using compiler $CC"
48+
elif command_exists riscv32-unknown-elf-gcc
49+
then
50+
export CC="riscv32-unknown-elf-gcc"
51+
export AR="riscv32-unknown-elf-ar"
52+
elif command_exists riscv-none-embed-gcc
53+
then
54+
export CC ="riscv-none-embed-gcc"
55+
export AR ="riscv-none-embed-ar"
56+
elif command_exists riscv64-unknown-elf-gcc
57+
then
58+
export CC="riscv64-unknown-elf-gcc"
59+
export AR="riscv64-unknown-elf-ar"
60+
else
61+
echo "No C compiler found for riscv" 1>&2
62+
exit 1
63+
fi
64+
65+
src_path="./library/target/riscv32imac-unknown-xous-elf/release/deps"
66+
dest_path="$rust_sysroot/lib/rustlib/riscv32imac-unknown-xous-elf"
67+
dest_lib_path="$dest_path/lib"
68+
69+
mkdir -p $dest_lib_path
70+
71+
rustc $RUST_TOOLCHAIN --version | awk '{print $2}' > "$dest_path/RUST_VERSION"
72+
73+
# Remove stale objects
74+
rm -f $dest_lib_path/*.rlib
75+
76+
# TODO: Use below to remove duplicates
77+
# previous_libraries=$(ls -1 $src_path/*.rlib)
78+
79+
cargo $RUST_TOOLCHAIN build \
80+
--target riscv32imac-unknown-xous-elf \
81+
-Zbinary-dep-depinfo \
82+
--release \
83+
--features "panic-unwind compiler-builtins-c compiler-builtins-mem" \
84+
--manifest-path "library/sysroot/Cargo.toml" || exit 1
85+
86+
# TODO: Remove duplicates here by comparing it with $previous_libraries
87+
for new_item in $(ls -1 $src_path/*.rlib)
88+
do
89+
file=$(basename $new_item)
90+
base_string=$(echo $file | rev | cut -d- -f2- | rev)
91+
done
92+
93+
cp $src_path/*.rlib "$dest_lib_path"

0 commit comments

Comments
 (0)