-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.ps1
142 lines (126 loc) · 4.72 KB
/
build.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# 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)\rust\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 -Zforce-unstable-if-unmarked=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"
}
$rustc_version = $(rustc +nightly --version).Split(" ")[1]
$rustc_hash = $(rustc +nightly --version).Split("(")[1].Split(" ")[0]
Write-Output "Building Rust $rustc_version, hash $rustc_hash"
Set-Location .\rust
Write-Output "git checkout $rustc_hash"
git checkout $rustc_hash
if ($LastExitCode -ne 0) {
throw "checkout: git exited $LastExitCode"
}
Write-Output "git branch -D build"
git branch -D build
Write-Output "git checkout -b build"
git checkout -b build
if ($LastExitCode -ne 0) {
throw "branch: git exited $LastExitCode"
}
Get-ChildItem ..\*.patch | ForEach-Object { git am $_.FullName }
if ($LastExitCode -ne 0) {
throw "patch: git exited $LastExitCode"
}
git submodule update --init --recursive
$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
}
Write-Output $rustc_version | 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 +nightly 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"