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