Slide 1

Slide 1 text

@jrbowes Compile Lots, Write Once, Run Anywhere

Slide 2

Slide 2 text

@jrbowes Write Once, Run Anywhere

Slide 3

Slide 3 text

@jrbowes Write Once, Run Anywhere

Slide 4

Slide 4 text

@jrbowes

Slide 5

Slide 5 text

@jrbowes

Slide 6

Slide 6 text

@jrbowes

Slide 7

Slide 7 text

@jrbowes

Slide 8

Slide 8 text

@jrbowes

Slide 9

Slide 9 text

@jrbowes

Slide 10

Slide 10 text

@jrbowes

Slide 11

Slide 11 text

@jrbowes

Slide 12

Slide 12 text

@jrbowes

Slide 13

Slide 13 text

@jrbowes

Slide 14

Slide 14 text

@jrbowes

Slide 15

Slide 15 text

@jrbowes Good Multi-Platform Distribution ★ Support For Platforms You Care About ★ Simple To Package And Ship ★ No Extra Dependencies ★ Broadly Compatible

Slide 16

Slide 16 text

@jrbowes ★ Support For Platforms You Care About $> go tool dist list | column aix/ppc64 dragonfly/amd64 linux/arm64 nacl/amd64p32 openbsd/arm64 android/386 freebsd/386 linux/mips nacl/arm plan9/386 android/amd64 freebsd/amd64 linux/mips64 netbsd/386 plan9/amd64 android/arm freebsd/arm linux/mips64le netbsd/amd64 plan9/arm android/arm64 illumos/amd64 linux/mipsle netbsd/arm solaris/amd64 darwin/386 js/wasm linux/ppc64 netbsd/arm64 windows/386 darwin/amd64 linux/386 linux/ppc64le openbsd/386 windows/amd64 darwin/arm linux/amd64 linux/s390x openbsd/amd64 windows/arm darwin/arm64 linux/arm nacl/386 openbsd/arm

Slide 17

Slide 17 text

@jrbowes ★ Support For Platforms You Care About $> go tool dist list | column aix/ppc64 dragonfly/amd64 linux/arm64 nacl/amd64p32 openbsd/arm64 android/386 freebsd/386 linux/mips nacl/arm plan9/386 android/amd64 freebsd/amd64 linux/mips64 netbsd/386 plan9/amd64 android/arm freebsd/arm linux/mips64le netbsd/amd64 plan9/arm android/arm64 illumos/amd64 linux/mipsle netbsd/arm solaris/amd64 darwin/386 js/wasm linux/ppc64 netbsd/arm64 windows/386 darwin/amd64 linux/386 linux/ppc64le openbsd/386 windows/amd64 darwin/arm linux/amd64 linux/s390x openbsd/amd64 windows/arm darwin/arm64 linux/arm nacl/386 openbsd/arm

Slide 18

Slide 18 text

@jrbowes ★ Support For Platforms You Care About $> go tool dist list | column aix/ppc64 dragonfly/amd64 linux/arm64 nacl/amd64p32 openbsd/arm64 android/386 freebsd/386 linux/mips nacl/arm plan9/386 android/amd64 freebsd/amd64 linux/mips64 netbsd/386 plan9/amd64 android/arm freebsd/arm linux/mips64le netbsd/amd64 plan9/arm android/arm64 illumos/amd64 linux/mipsle netbsd/arm solaris/amd64 darwin/386 js/wasm linux/ppc64 netbsd/arm64 windows/386 darwin/amd64 linux/386 linux/ppc64le openbsd/386 windows/amd64 darwin/arm linux/amd64 linux/s390x openbsd/amd64 windows/arm darwin/arm64 linux/arm nacl/386 openbsd/arm

Slide 19

Slide 19 text

@jrbowes Good Multi-Platform Distribution ★ Support For Platforms You Care About ★ Simple To Package And Ship ★ No Extra Dependencies ★ Broadly Compatible

Slide 20

Slide 20 text

@jrbowes Good Multi-Platform Distribution ★ Support For Platforms You Care About ★ Simple To Package And Ship ★ No Extra Dependencies ★ Broadly Compatible

Slide 21

Slide 21 text

@jrbowes ★ Simple To Package And Ship

Slide 22

Slide 22 text

@jrbowes ★ Simple To Package And Ship $> go build -o mybin .

Slide 23

Slide 23 text

@jrbowes ★ Simple To Package And Ship $> go build -o mybin . $> file mybin mybin: Mach-O 64-bit executable x86_64

Slide 24

Slide 24 text

@jrbowes ★ Simple To Package And Ship $> go build -o mybin . $> file mybin mybin: Mach-O 64-bit executable x86_64 $> go env | grep -e ARCH= -e OS=

Slide 25

Slide 25 text

@jrbowes ★ Simple To Package And Ship $> go build -o mybin . $> file mybin mybin: Mach-O 64-bit executable x86_64 $> go env | grep -e ARCH= -e OS= GOARCH="amd64" GOHOSTARCH="amd64" GOHOSTOS="darwin" GOOS="darwin"

Slide 26

Slide 26 text

@jrbowes ★ Simple To Package And Ship

Slide 27

Slide 27 text

@jrbowes ★ Simple To Package And Ship $> GOOS=linux GOARCH=386 go build -o mybin .

Slide 28

Slide 28 text

@jrbowes ★ Simple To Package And Ship $> GOOS=linux GOARCH=386 go build -o mybin . $> file mybin mybin: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), statically linked, Go BuildID=BsI7W6-gfNe589qm79AK/ HNGwNEScRjtQ48lwr1I_/gaYHO-EnYpDZEfeZfj5y/ mucU2QyPI7SKOAIiU0Ip, not stripped

Slide 29

Slide 29 text

@jrbowes Use GoReleaser

Slide 30

Slide 30 text

@jrbowes Use GoReleaser QR Codes: Created in 1994

Slide 31

Slide 31 text

@jrbowes

Slide 32

Slide 32 text

@jrbowes

Slide 33

Slide 33 text

@jrbowes $> GOOS=linux GOARCH=amd64 go build -o mybin .

Slide 34

Slide 34 text

@jrbowes $> GOOS=linux GOARCH=amd64 go build -o mybin . $> cat Dockerfile FROM ubuntu ENTRYPOINT ["/mybin"] COPY mybin /

Slide 35

Slide 35 text

@jrbowes $> GOOS=linux GOARCH=amd64 go build -o mybin . $> cat Dockerfile FROM ubuntu ENTRYPOINT ["/mybin"] COPY mybin / $> docker build -t mybin .

Slide 36

Slide 36 text

@jrbowes Good Multi-Platform Distribution ★ Support For Platforms You Care About ★ Simple To Package And Ship ★ No Extra Dependencies ★ Broadly Compatible

Slide 37

Slide 37 text

@jrbowes Good Multi-Platform Distribution ★ Support For Platforms You Care About ★ Simple To Package And Ship ★ No Extra Dependencies ★ Broadly Compatible

Slide 38

Slide 38 text

@jrbowes ★ No Extra Dependencies • Compiles to native code — no interpreter or VM • Statically linked — everything in one binary

Slide 39

Slide 39 text

@jrbowes ★ No Extra Dependencies • Compiles to native code — no interpreter or VM • Statically linked — everything in one binary

Slide 40

Slide 40 text

@jrbowes Asset Bundling

Slide 41

Slide 41 text

@jrbowes Asset Bundling

Slide 42

Slide 42 text

@jrbowes Asset Bundling

Slide 43

Slide 43 text

@jrbowes Asset Bundling

Slide 44

Slide 44 text

@jrbowes Try Pkger

Slide 45

Slide 45 text

@jrbowes Try Pkger Mark Bates: Also created in 1994

Slide 46

Slide 46 text

@jrbowes Static Compilation

Slide 47

Slide 47 text

@jrbowes Static Compilation $> GOOS=linux GOARCH=amd64 go build -o mybin .

Slide 48

Slide 48 text

@jrbowes Static Compilation $> GOOS=linux GOARCH=amd64 go build -o mybin . $> file mybin

Slide 49

Slide 49 text

@jrbowes Static Compilation $> GOOS=linux GOARCH=amd64 go build -o mybin . $> file mybin mybin: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, Go BuildID=9o-4CdGfdGNZI6qjvI3f/ NQvS9hSCir0F4HyOUCfA/NPmlomWGgx9zKs2QPYAW/ dOg15syGcYsIpCSJeV6o, not stripped

Slide 50

Slide 50 text

@jrbowes Static Compilation $> GOOS=linux GOARCH=amd64 go build -o mybin . $> file mybin mybin: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, Go BuildID=9o-4CdGfdGNZI6qjvI3f/ NQvS9hSCir0F4HyOUCfA/NPmlomWGgx9zKs2QPYAW/ dOg15syGcYsIpCSJeV6o, not stripped $> GOOS=linux GOARCH=amd64 go build -o mybin-native .

Slide 51

Slide 51 text

@jrbowes Static Compilation $> GOOS=linux GOARCH=amd64 go build -o mybin . $> file mybin mybin: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, Go BuildID=9o-4CdGfdGNZI6qjvI3f/ NQvS9hSCir0F4HyOUCfA/NPmlomWGgx9zKs2QPYAW/ dOg15syGcYsIpCSJeV6o, not stripped $> GOOS=linux GOARCH=amd64 go build -o mybin-native . $> file mybin-native

Slide 52

Slide 52 text

@jrbowes Static Compilation $> GOOS=linux GOARCH=amd64 go build -o mybin . $> file mybin mybin: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, Go BuildID=9o-4CdGfdGNZI6qjvI3f/ NQvS9hSCir0F4HyOUCfA/NPmlomWGgx9zKs2QPYAW/ dOg15syGcYsIpCSJeV6o, not stripped $> GOOS=linux GOARCH=amd64 go build -o mybin-native . $> file mybin-native mybin-native: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux- x86-64.so.2, Go BuildID=qUlaMGoOyhvXwZau-GGh/ ItQcRvmsh30mFD0AG_Ze/SDeNJVYSF_TOVHk-06Dt/ BTU4CSv7GAsNuZKMxoIq, not stripped

Slide 53

Slide 53 text

@jrbowes Static Compilation $> GOOS=linux GOARCH=amd64 go build -o mybin . $> file mybin mybin: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, Go BuildID=9o-4CdGfdGNZI6qjvI3f/ NQvS9hSCir0F4HyOUCfA/NPmlomWGgx9zKs2QPYAW/ dOg15syGcYsIpCSJeV6o, not stripped $> GOOS=linux GOARCH=amd64 go build -o mybin-native . $> file mybin-native mybin-native: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux- x86-64.so.2, Go BuildID=qUlaMGoOyhvXwZau-GGh/ ItQcRvmsh30mFD0AG_Ze/SDeNJVYSF_TOVHk-06Dt/ BTU4CSv7GAsNuZKMxoIq, not stripped

Slide 54

Slide 54 text

@jrbowes Static Compilation $> GOOS=linux GOARCH=amd64 go build -o mybin . $> file mybin mybin: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, Go BuildID=9o-4CdGfdGNZI6qjvI3f/ NQvS9hSCir0F4HyOUCfA/NPmlomWGgx9zKs2QPYAW/ dOg15syGcYsIpCSJeV6o, not stripped $> GOOS=linux GOARCH=amd64 go build -o mybin-native . $> file mybin-native mybin-native: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux- x86-64.so.2, Go BuildID=qUlaMGoOyhvXwZau-GGh/ ItQcRvmsh30mFD0AG_Ze/SDeNJVYSF_TOVHk-06Dt/ BTU4CSv7GAsNuZKMxoIq, not stripped

Slide 55

Slide 55 text

@jrbowes (Not So) Static Compilation $> ldd mybin linux-vdso.so.1 (0x00007fff55fd1000) libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 … libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 … /lib64/ld-linux-x86-64.so.2 (0x00007f9574ffe000)

Slide 56

Slide 56 text

@jrbowes (Not So) Static Compilation $> ldd mybin linux-vdso.so.1 (0x00007fff55fd1000) libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 … libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 … /lib64/ld-linux-x86-64.so.2 (0x00007f9574ffe000)

Slide 57

Slide 57 text

@jrbowes (Not So) Static Compilation $> ldd mybin linux-vdso.so.1 (0x00007fff55fd1000) libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 … libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 … /lib64/ld-linux-x86-64.so.2 (0x00007f9574ffe000)

Slide 58

Slide 58 text

@jrbowes (Not So) Static Compilation $> ldd mybin linux-vdso.so.1 (0x00007fff55fd1000) libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 … libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 … /lib64/ld-linux-x86-64.so.2 (0x00007f9574ffe000)

Slide 59

Slide 59 text

@jrbowes (Not So) Static Compilation

Slide 60

Slide 60 text

@jrbowes (Not So) Static Compilation $> ./my-bin

Slide 61

Slide 61 text

@jrbowes (Not So) Static Compilation $> ./my-bin /bin/sh: ./mybin: not found

Slide 62

Slide 62 text

@jrbowes (Not So) Static Compilation $> ./my-bin /bin/sh: ./mybin: not found $> ./not-real

Slide 63

Slide 63 text

@jrbowes (Not So) Static Compilation $> ./my-bin /bin/sh: ./mybin: not found $> ./not-real /bin/sh: ./not-real: not found

Slide 64

Slide 64 text

@jrbowes (Not So) Static Compilation

Slide 65

Slide 65 text

@jrbowes (Not So) Static Compilation $> file mybin

Slide 66

Slide 66 text

@jrbowes (Not So) Static Compilation $> file mybin mybin: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, Go BuildID=qUlaMGoOyhvXwZau-GGh/ItQcRvmsh30mFD0AG_Ze/ SDeNJVYSF_TOVHk-06Dt/BTU4CSv7GAsNuZKMxoIq, not stripped

Slide 67

Slide 67 text

@jrbowes (Not So) Static Compilation $> file mybin mybin: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, Go BuildID=qUlaMGoOyhvXwZau-GGh/ItQcRvmsh30mFD0AG_Ze/ SDeNJVYSF_TOVHk-06Dt/BTU4CSv7GAsNuZKMxoIq, not stripped

Slide 68

Slide 68 text

@jrbowes Static Compilation “The cgo tool is enabled by default for native builds on systems where it is expected to work.”

Slide 69

Slide 69 text

@jrbowes Disable cgo for easier distribution $> CGO_ENABLED=0 GOOS=linux GOARCH=386 \ go build -o mybin .

Slide 70

Slide 70 text

@jrbowes Good Multi-Platform Distribution ★ Support For Platforms You Care About ★ Simple To Package And Ship ★ No Extra Dependencies ★ Broadly Compatible

Slide 71

Slide 71 text

@jrbowes Good Multi-Platform Distribution ★ Support For Platforms You Care About ★ Simple To Package And Ship ★ No Extra Dependencies ★ Broadly Compatible

Slide 72

Slide 72 text

@jrbowes ★ Broadly Compatible • Consistent behaviour across platforms • Consistent support for features and packages

Slide 73

Slide 73 text

@jrbowes ★ Broadly Compatible The bright side of Not Invented Here syndrome

Slide 74

Slide 74 text

@jrbowes Platform Specific Logic

Slide 75

Slide 75 text

@jrbowes Platform Specific Logic func (c *Certificate) Verify(opts VerifyOptions)(chains [][]*Certificate, err error)

Slide 76

Slide 76 text

@jrbowes Platform Specific Logic func (c *Certificate) Verify(opts VerifyOptions)(chains [][]*Certificate, err error) type VerifyOptions struct { DNSName string Intermediates *CertPool Roots *CertPool // if nil, the system roots are used …

Slide 77

Slide 77 text

@jrbowes Platform Specific Logic // Use Windows's own verification and chain building. if opts.Roots == nil && runtime.GOOS == "windows" { return c.systemVerify(&opts) }

Slide 78

Slide 78 text

@jrbowes Platform Specific Logic // root_unix.go func (c *Certificate) systemVerify(opts *VerifyOptions) (chains [][]*Certificate, err error) { return nil, nil } // root_windows.go // systemVerify is like Verify, except that it uses CryptoAPI calls // to build certificate chains and verify them. func (c *Certificate) systemVerify(opts *VerifyOptions) (chains [][]*Certificate, err error) { hasDNSName := opts != nil && len(opts.DNSName) > 0 storeCtx, err := createStoreContext(c, opts) …

Slide 79

Slide 79 text

@jrbowes Build Tags • Implicit: GOOS, GOARCH, go version… • Explicit: go build -tags 'mytag'

Slide 80

Slide 80 text

@jrbowes Build Tags // root_unix.go func (c *Certificate) systemVerify(opts *VerifyOptions) (chains [][]*Certificate, err error) { return nil, nil } // root_windows.go // systemVerify is like Verify, except that it uses CryptoAPI calls // to build certificate chains and verify them. func (c *Certificate) systemVerify(opts *VerifyOptions) (chains [][]*Certificate, err error) { hasDNSName := opts != nil && len(opts.DNSName) > 0 storeCtx, err := createStoreContext(c, opts) …

Slide 81

Slide 81 text

@jrbowes

Slide 82

Slide 82 text

@jrbowes

Slide 83

Slide 83 text

@jrbowes Build Tags

Slide 84

Slide 84 text

@jrbowes Build Tags // spaces are OR // +build linux solaris

Slide 85

Slide 85 text

@jrbowes Build Tags // spaces are OR // +build linux solaris // ! is NOT // +build !darwin

Slide 86

Slide 86 text

@jrbowes Build Tags // spaces are OR // +build linux solaris // ! is NOT // +build !darwin // , is AND // +build linux,cgo

Slide 87

Slide 87 text

@jrbowes Build Tags // spaces are OR // +build linux solaris // ! is NOT // +build !darwin // , is AND // +build linux,cgo // multi lines are AND // +build linux,darwin // +build cgo

Slide 88

Slide 88 text

@jrbowes Build Tags

Slide 89

Slide 89 text

@jrbowes Build Tags // +build aix dragonfly freebsd js,wasm linux nacl netbsd openbsd solaris

Slide 90

Slide 90 text

@jrbowes Good Multi-Platform Distribution ★ Support For Platforms You Care About ★ Simple To Package And Ship ★ No Extra Dependencies ★ Broadly Compatible

Slide 91

Slide 91 text

@jrbowes Good Multi-Platform Distribution ★ Support For Platforms You Care About ★ Simple To Package And Ship ★ No Extra Dependencies ★ Broadly Compatible

Slide 92

Slide 92 text

@jrbowes Go: Thumbs up!

Slide 93

Slide 93 text

@jrbowes Go: Thumbs up!

Slide 94

Slide 94 text

@jrbowes Thank you! FIND ME github.com/jbowes twitter.com/jrbowes manifold.co