build 4.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #!/bin/bash
  2. [% c("var/set_default_env") -%]
  3. distdir=/var/tmp/dist/[% project %]
  4. mkdir -p /var/tmp/dist
  5. [% IF c("var/linux") %]
  6. # Config options for hardening-wrapper
  7. export DEB_BUILD_HARDENING=1
  8. export DEB_BUILD_HARDENING_STACKPROTECTOR=1
  9. export DEB_BUILD_HARDENING_FORTIFY=1
  10. export DEB_BUILD_HARDENING_FORMAT=1
  11. export DEB_BUILD_HARDENING_PIE=1
  12. [% END %]
  13. mkdir -p /var/tmp/build
  14. # Building go 1.4.x
  15. # This is needed to bootstrap the go that we actually use
  16. # https://golang.org/doc/install/source#go14
  17. tar -C /var/tmp/build --transform='s,^go\>,go1.4,' -xf $rootdir/[% c('input_files_by_name/go14') %]
  18. cd /var/tmp/build/go1.4/src
  19. # Disable cgo to avoid conflicts with newer GCC. cgo is not needed for the bootstrap go.
  20. # https://github.com/golang/go/issues/13114#issuecomment-186922245
  21. # Disable CC etc. that are set up for cross builds.
  22. CGO_ENABLED=0 CC= CFLAGS= LDFLAGS= ./make.bash
  23. export GOROOT_BOOTSTRAP="/var/tmp/build/go1.4"
  24. cd $rootdir
  25. [% IF ! c("var/linux") || c("var/linux-cross") %]
  26. [% pc(c('var/compiler'), 'var/setup', { compiler_tarfile => c('input_files_by_name/' _ c('var/compiler')) }) %]
  27. # http://golang.org/doc/install/source#environment
  28. export GOOS=[% c("var/GOOS") %]
  29. export GOARCH=[% c("var/GOARCH") %]
  30. [% END %]
  31. # Building go
  32. # http://golang.org/doc/install/source#environment
  33. tar -C /var/tmp/dist -xf $rootdir/[% c('input_files_by_name/go') %]
  34. export GOROOT="$distdir"
  35. cd /var/tmp/dist/go/src
  36. [% IF c("var/linux") -%]
  37. [% IF c("var/linux-cross") -%]
  38. # Create a cc-for-target script that closes over CC, CFLAGS, and LDFLAGS.
  39. # Go's CC_FOR_TARGET only allows a command name, not a command with arguments.
  40. # https://github.com/golang/go/issues/15457
  41. CC_FOR_TARGET="$(pwd)/cc-for-target"
  42. echo "#!/bin/sh" > "$CC_FOR_TARGET"
  43. echo "exec [% c("var/crosstarget") %]-gcc [% c("var/CFLAGS") %] [% c("var/LDFLAGS") %] \"\$@\"" >> "$CC_FOR_TARGET"
  44. chmod +x "$CC_FOR_TARGET"
  45. # http://golang.org/doc/install/source#environment
  46. export GOOS=[% c("GOOS") %]
  47. export GOARCH=[% c("var/GOARCH") %]
  48. CGO_ENABLED=1 CC_FOR_TARGET="$CC_FOR_TARGET" CC= CFLAGS= LDFLAGS= ./make.bash
  49. [% ELSE -%]
  50. ./make.bash
  51. [% END -%]
  52. [% ELSIF c("var/osx") -%]
  53. unset LDFLAGS
  54. rm -Rf $clangdir/helpers
  55. export CC="$clangdir/bin/clang [% c("var/FLAGS") %]"
  56. # Create a cc-for-target script that closes over CC, CFLAGS, and LDFLAGS.
  57. # Go's CC_FOR_TARGET only allows a command name, not a command with arguments.
  58. # https://github.com/golang/go/issues/15457
  59. CC_FOR_TARGET="$(pwd)/cc-for-target"
  60. echo "#!/bin/sh" > "$CC_FOR_TARGET"
  61. echo "exec $CC $CFLAGS $LDFLAGS \"\$@\"" >> "$CC_FOR_TARGET"
  62. chmod +x "$CC_FOR_TARGET"
  63. # faketime is needed because clang 3.9.1 on Darwin embeds the timestamps of
  64. # certain intermediate object files (including those that arise here while
  65. # compiling the Go runtime itself). Without this, variable timestamps would
  66. # end up in snowflake-client.
  67. # https://github.com/golang/go/issues/9206#issuecomment-310476743
  68. CGO_ENABLED=1 CC_FOR_TARGET="$CC_FOR_TARGET" CC= CFLAGS= LDFLAGS= [% c("var/faketime") %] ./make.bash
  69. [% ELSIF c("var/windows") -%]
  70. # Create a cc-for-target script that closes over CC, CFLAGS, and LDFLAGS.
  71. # Go's CC_FOR_TARGET only allows a command name, not a command with arguments.
  72. # https://github.com/golang/go/issues/15457
  73. CC_FOR_TARGET="$(pwd)/cc-for-target"
  74. echo "#!/bin/sh" > "$CC_FOR_TARGET"
  75. echo "exec [% c("arch") %]-w64-mingw32-gcc [% c("var/CFLAGS") %] [% c("var/LDFLAGS") %] \"\$@\"" >> "$CC_FOR_TARGET"
  76. chmod +x "$CC_FOR_TARGET"
  77. CGO_ENABLED=1 CC_FOR_TARGET="$CC_FOR_TARGET" CC= CFLAGS= LDFLAGS= ./make.bash
  78. [% ELSIF c("var/android") -%]
  79. patch -p2 < $rootdir/0001-Use-fixed-go-build-tmp-directory.patch
  80. CGO_ENABLED=1 CC_FOR_TARGET=[% c("var/CC") %] CGO_CFLAGS='-D__ANDROID_API__=[% c("var/android_min_api") %]' CC= CFLAGS= LDFLAGS= ./make.bash
  81. [% END -%]
  82. # This directory is non-reproducible and doesn't exist in official Go releases,
  83. # so remove it to preserve reproducibility of the output.
  84. rm -rf /var/tmp/dist/go/pkg/obj/go-build/
  85. cd /var/tmp/dist
  86. [% c('tar', {
  87. tar_src => [ project ],
  88. tar_args => '-czf ' _ dest_dir _ '/' _ c('filename'),
  89. }) %]