|
| 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" |
0 commit comments