dev-package-for-linux.sh 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. set -e
  2. # This script builds a publishable release-worthy version of exa.
  3. # It gets the version number, builds exa using cargo, tests it, strips the
  4. # binary, compresses it into a zip, then puts it in /vagrant so it’s
  5. # accessible from the host machine.
  6. #
  7. # If you’re in the VM, you can run it using the ‘package-exa’ command.
  8. # First, we need to get the version number to figure out what to call the zip.
  9. # We do this by getting the first line from the Cargo.toml that matches
  10. # /version/, removing its whitespace, and building a command out of it, so the
  11. # shell executes something like `exa_version="0.8.0"`, which it understands as
  12. # a variable definition. Hey, it’s not a hack if it works.
  13. toml_file="/vagrant/Cargo.toml"
  14. eval exa_$(grep version $toml_file | head -n 1 | sed "s/ //g")
  15. if [ -z "$exa_version" ]; then
  16. echo "Failed to parse version number! Can't build exa!"
  17. exit
  18. else
  19. echo "Building exa v$exa_version"
  20. fi
  21. # Compilation is done in --release mode, which takes longer but produces a
  22. # faster binary. This binary gets built to a different place, so the extended
  23. # tests script needs to be told which one to use.
  24. echo -e "\n\033[4mCompiling release version of exa...\033[0m"
  25. exa_linux_binary="/vagrant/exa-linux-x86_64"
  26. rm -vf "$exa_linux_binary"
  27. cargo build --release --manifest-path "$toml_file"
  28. cargo test --release --manifest-path "$toml_file" --lib -- --quiet
  29. /vagrant/xtests/run.sh --release
  30. cp /home/ubuntu/target/release/exa "$exa_linux_binary"
  31. # Stripping the binary before distributing it removes a bunch of debugging
  32. # symbols, saving some space.
  33. echo -e "\n\033[4mStripping binary...\033[0m"
  34. strip -v "$exa_linux_binary"
  35. # Compress the binary for upload. The ‘-j’ flag is necessary to avoid the
  36. # /vagrant path being in the zip too. Only the zip gets the version number, so
  37. # the binaries can have consistent names, but it’s still possible to tell
  38. # different *downloads* apart.
  39. echo -e "\n\033[4mZipping binary...\033[0m"
  40. exa_linux_zip="/vagrant/exa-linux-x86_64-${exa_version}.zip"
  41. rm -vf "$exa_linux_zip"
  42. zip -j "$exa_linux_zip" "$exa_linux_binary"
  43. # There was a problem a while back where a library was getting unknowingly
  44. # *dynamically* linked, which broke the whole ‘self-contained binary’ concept.
  45. # So dump the linker table, in case anything unscrupulous shows up.
  46. echo -e "\n\033[4mLibraries linked:\033[0m"
  47. ldd "$exa_linux_binary" | sed "s/\t//"
  48. # Might as well use it to test itself, right?
  49. echo -e "\n\033[4mAll done! Files produced:\033[0m"
  50. "$exa_linux_binary" "$exa_linux_binary" "$exa_linux_zip" -lB