forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathrebuild.ps1
executable file
·119 lines (105 loc) · 3.97 KB
/
rebuild.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
# 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"