local-package-for-macos.sh 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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, and compresses it into a zip.
  5. #
  6. # It’s *mostly* the same as dev-package-for-linux.sh, except with some
  7. # Mach-specific things (otool instead of ldd), BSD-coreutils-specific things,
  8. # and it doesn’t run the xtests.
  9. # Virtualising macOS is a legal minefield, so this script is ‘local’ instead
  10. # of ‘dev’: I run it from my actual machine, rather than from a VM.
  11. uname=`uname -s`
  12. if [[ "$uname" != "Darwin" ]]; then
  13. echo "Gotta be on Darwin to run this (detected '$uname')!"
  14. exit 1
  15. fi
  16. # First, we need to get the version number to figure out what to call the zip.
  17. # We do this by getting the first line from the Cargo.toml that matches
  18. # /version/, removing its whitespace, and building a command out of it, so the
  19. # shell executes something like `exa_version="0.8.0"`, which it understands as
  20. # a variable definition. Hey, it’s not a hack if it works.
  21. #
  22. # Because this can’t use the absolute /vagrant path, this has to use what this
  23. # SO answer calls a “quoting disaster”: https://stackoverflow.com/a/20196098/3484614
  24. # You will also need GNU coreutils: https://stackoverflow.com/a/4031502/3484614
  25. exa_root="$(dirname "$(dirname "$(greadlink -fm "$0")")")"
  26. toml_file="$exa_root"/Cargo.toml
  27. eval exa_$(grep version $toml_file | head -n 1 | sed "s/ //g")
  28. if [ -z "$exa_version" ]; then
  29. echo "Failed to parse version number! Can't build exa!"
  30. exit 1
  31. else
  32. echo "Building exa v$exa_version"
  33. fi
  34. # Compilation is done in --release mode, which takes longer but produces a
  35. # faster binary.
  36. echo -e "\n\033[4mCompiling release version of exa...\033[0m"
  37. exa_macos_binary="$exa_root/exa-macos-x86_64"
  38. rm -vf "$exa_macos_binary" | sed 's/^/removing /'
  39. cargo build --release --manifest-path "$toml_file"
  40. cargo test --release --manifest-path "$toml_file" --lib -- --quiet
  41. # we can’t run the xtests outside the VM!
  42. #/vagrant/xtests/run.sh --release
  43. cp "$exa_root"/target/release/exa "$exa_macos_binary"
  44. # Stripping the binary before distributing it removes a bunch of debugging
  45. # symbols, saving some space.
  46. echo -e "\n\033[4mStripping binary...\033[0m"
  47. strip "$exa_macos_binary"
  48. echo "strip $exa_macos_binary"
  49. # Compress the binary for upload. The ‘-j’ flag is necessary to avoid the
  50. # current path being in the zip too. Only the zip gets the version number, so
  51. # the binaries can have consistent names, and it’s still possible to tell
  52. # different *downloads* apart.
  53. echo -e "\n\033[4mZipping binary...\033[0m"
  54. exa_macos_zip="$exa_root/exa-macos-x86_64-${exa_version}.zip"
  55. rm -vf "$exa_macos_zip" | sed 's/^/removing /'
  56. zip -j "$exa_macos_zip" "$exa_macos_binary"
  57. # There was a problem a while back where a library was getting unknowingly
  58. # *dynamically* linked, which broke the whole ‘self-contained binary’ concept.
  59. # So dump the linker table, in case anything unscrupulous shows up.
  60. echo -e "\n\033[4mLibraries linked:\033[0m"
  61. otool -L "$exa_macos_binary" | sed 's/^[[:space:]]*//'
  62. # Might as well use it to test itself, right?
  63. echo -e "\n\033[4mAll done! Files produced:\033[0m"
  64. "$exa_macos_binary" "$exa_macos_binary" "$exa_macos_zip" -lB