rustc-version.sh 598 B

1234567891011121314151617181920212223242526
  1. #!/bin/sh
  2. # SPDX-License-Identifier: GPL-2.0
  3. #
  4. # Usage: $ ./rustc-version.sh rustc
  5. #
  6. # Print the Rust compiler version in a 6 or 7-digit form.
  7. # Convert the version string x.y.z to a canonical up-to-7-digits form.
  8. #
  9. # Note that this function uses one more digit (compared to other
  10. # instances in other version scripts) to give a bit more space to
  11. # `rustc` since it will reach 1.100.0 in late 2026.
  12. get_canonical_version()
  13. {
  14. IFS=.
  15. set -- $1
  16. echo $((100000 * $1 + 100 * $2 + $3))
  17. }
  18. if output=$("$@" --version 2>/dev/null); then
  19. set -- $output
  20. get_canonical_version $2
  21. else
  22. echo 0
  23. exit 1
  24. fi