dev-package-for-linux.sh 2.7 KB

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