test_crosscompile.sh 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #!/usr/bin/env sh
  2. # Test script checking that all expected os/arch compile properly.
  3. # Does not actually test the logic, just the compilation so we make sure we don't break code depending on the lib.
  4. echo2() {
  5. echo $@ >&2
  6. }
  7. trap end 0
  8. end() {
  9. [ "$?" = 0 ] && echo2 "Pass." || (echo2 "Fail."; exit 1)
  10. }
  11. cross() {
  12. os=$1
  13. shift
  14. echo2 "Build for $os."
  15. for arch in $@; do
  16. echo2 " - $os/$arch"
  17. GOOS=$os GOARCH=$arch go build
  18. done
  19. echo2
  20. }
  21. set -e
  22. cross linux amd64 386 arm arm64 ppc64 ppc64le s390x mips mipsle mips64 mips64le
  23. cross darwin amd64 arm64
  24. cross freebsd amd64 386 arm arm64
  25. cross netbsd amd64 386 arm arm64
  26. cross openbsd amd64 386 arm arm64
  27. cross dragonfly amd64
  28. cross solaris amd64
  29. # Not expected to work but should still compile.
  30. cross windows amd64 386 arm
  31. # TODO: Fix compilation error on openbsd/arm.
  32. # TODO: Merge the solaris PR.
  33. # Some os/arch require a different compiler. Run in docker.
  34. if ! hash docker; then
  35. # If docker is not present, stop here.
  36. return
  37. fi
  38. echo2 "Build for linux."
  39. echo2 " - linux/riscv"
  40. docker build -t creack-pty-test -f Dockerfile.riscv .
  41. # Golang dropped support for darwin 32bits since go1.15. Make sure the lib still compile with go1.14 on those archs.
  42. echo2 "Build for darwin (32bits)."
  43. echo2 " - darwin/386"
  44. docker build -t creack-pty-test -f Dockerfile.golang --build-arg=GOVERSION=1.14 --build-arg=GOOS=darwin --build-arg=GOARCH=386 .
  45. echo2 " - darwin/arm"
  46. docker build -t creack-pty-test -f Dockerfile.golang --build-arg=GOVERSION=1.14 --build-arg=GOOS=darwin --build-arg=GOARCH=arm .
  47. # Run a single test for an old go version. Would be best with go1.0, but not available on Dockerhub.
  48. # Using 1.6 as it is the base version for the RISCV compiler.
  49. # Would also be better to run all the tests, not just one, need to refactor this file to allow for specifc archs per version.
  50. echo2 "Build for linux - go1.6."
  51. echo2 " - linux/amd64"
  52. docker build -t creack-pty-test -f Dockerfile.golang --build-arg=GOVERSION=1.6 --build-arg=GOOS=linux --build-arg=GOARCH=amd64 .