summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: 3f9eab263f38a261a8326c61a2bb23c10897ec0b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# Maintainer: pingplug <pingplug@foxmail.com>
# Contributor: Johannes Löthberg <johannes@kyriasis.com>
# Contributor: Alexander F Rødseth <xyproto@archlinux.org>
# Contributor: Daniel Micay <danielmicay@gmail.com>
# Contributor: userwithuid <userwithuid@gmail.com>

pkgname=mingw-w64-rust
_pkgname=rust
pkgver=1.23.0
pkgrel=1
pkgdesc="rust language prebuilt toolchain with mingw target (mingw-w64)"
arch=('any')
url='https://www.rust-lang.org/'
license=('MIT' 'Apache' 'custom')
depends=('gcc-libs' 'curl' 'libgit2' 'mingw-w64-gcc')
optdepends=('wine: for cargo test support')
options=(!emptydirs staticlibs !strip)
provides=()
conflicts=('mingw-w64-rust-bin')
replaces=('mingw-w64-rust-bin')
makedepends=('rust' 'libffi' 'perl' 'python2' 'nodejs' 'cmake')

source=("https://static.rust-lang.org/dist/rustc-$pkgver-src.tar.gz"{,.asc}
        mingw-config.toml)

sha256sums=('7464953871dcfdfa8afcc536916a686dd156a83339d8ec4d5cb4eb2fe146cb91'
            'SKIP'
            '4a63841b4c3be5de4ff11241bc45a4ac7ab03889af4f7ed64442c524be7f5d74')
validpgpkeys=('108F66205EAEB0AAA8DD5E1C85AB96E6FA1BE5FE') # Rust Language (Tag and Release Signing Key) <rust-key@rust-lang.org>

backup=("opt/${_pkgname}/cargo/config")

prepare() {
  cd "rustc-$pkgver-src"

  cp "$srcdir"/mingw-config.toml config.toml
  sed -i "s|\@PREFIX\@|/opt/${_pkgname}|" config.toml
}

build() {
  cd "rustc-$pkgver-src"

  unset LDFLAGS
  export CFLAGS="-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions --param=ssp-buffer-size=4"
  export CXXFLAGS="-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions --param=ssp-buffer-size=4"
  python2 ./x.py build
}

package() {
  cd "rustc-$pkgver-src"

  unset LDFLAGS
  export CFLAGS="-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions --param=ssp-buffer-size=4"
  export CXXFLAGS="-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions --param=ssp-buffer-size=4"
  DESTDIR="$pkgdir" python2 ./x.py install

  # license
  install -dm755 "${pkgdir}/usr/share/licenses/${pkgname}/"{rust,cargo}
  mv "${pkgdir}"/opt/${_pkgname}/share/doc/rust/LICENSE-*.old "${pkgdir}/usr/share/licenses/${pkgname}/cargo/"
  rename '.old' '' "${pkgdir}/usr/share/licenses/${pkgname}/cargo/"*
  mv "${pkgdir}"/opt/${_pkgname}/share/doc/rust/{LICENSE-*,COPYRIGHT} "${pkgdir}/usr/share/licenses/${pkgname}/rust/"

  # remove unused files, rust-doc, rls, rustfmt, rust-analysis, rust-src
  rm -r "${pkgdir}/etc/"
  rm -r "${pkgdir}/opt/${_pkgname}/share"
  rm "${pkgdir}/opt/${_pkgname}/bin/"{rls,rustfmt}
  rm -r "${pkgdir}/opt/${_pkgname}/lib/rustlib/"{i686,x86_64}-pc-windows-gnu/analysis
  rm -r "${pkgdir}/opt/${_pkgname}/lib/rustlib/"x86_64-unknown-linux-gnu/analysis
  rm "${pkgdir}/opt/${_pkgname}/lib/rustlib/"{manifest-*,install.log,uninstall.sh,components,rust-installer-version}
  rm -r "${pkgdir}/opt/${_pkgname}/lib/rustlib/src"

  # link shared libraries
  pushd "${pkgdir}/opt/${_pkgname}/lib"
  ln -sf "rustlib/x86_64-unknown-linux-gnu/lib/"*.so .
  popd
  pushd "${pkgdir}"
  install -dm755 "${pkgdir}/usr/i686-w64-mingw32/bin"
  ln -sf "opt/${_pkgname}/lib/rustlib/i686-pc-windows-gnu/lib/"*.dll "usr/i686-w64-mingw32/bin"
  install -dm755 "${pkgdir}/usr/x86_64-w64-mingw32/bin"
  ln -sf "opt/${_pkgname}/lib/rustlib/x86_64-pc-windows-gnu/lib/"*.dll "usr/x86_64-w64-mingw32/bin"
  popd

  # strip
  strip --strip-all "${pkgdir}/opt/${_pkgname}/bin/"{cargo,rustc,rustdoc}
  strip --strip-unneeded "${pkgdir}/opt/${_pkgname}/lib/rustlib/x86_64-unknown-linux-gnu/lib/"*.so
  i686-w64-mingw32-strip --strip-unneeded "${pkgdir}/opt/${_pkgname}/lib/rustlib/i686-pc-windows-gnu/lib/"*.dll
  x86_64-w64-mingw32-strip --strip-unneeded "${pkgdir}/opt/${_pkgname}/lib/rustlib/x86_64-pc-windows-gnu/lib/"*.dll

  # config
  install -dm777 "${pkgdir}/opt/${_pkgname}/cargo"
  cat << EOF >> "${pkgdir}/opt/${_pkgname}/cargo/config"
[target.i686-pc-windows-gnu]
linker = "/usr/bin/i686-w64-mingw32-gcc"
ar = "/usr/i686-w64-mingw32/bin/ar"
EOF
  if pacman -T "wine" ; then
    cat << EOF >> "${pkgdir}/opt/${_pkgname}/cargo/config"
runner = "wine"
EOF
  fi

  cat << EOF >> "${pkgdir}/opt/${_pkgname}/cargo/config"

[target.x86_64-pc-windows-gnu]
linker = "/usr/bin/x86_64-w64-mingw32-gcc"
ar = "/usr/x86_64-w64-mingw32/bin/ar"
EOF
  if pacman -T "wine" ; then
    cat << EOF >> "${pkgdir}/opt/${_pkgname}/cargo/config"
runner = "wine"
EOF
  fi
  if pacman -T "mingw-w64-crt>5.0.3.20171219" ; then
    cat << EOF >> "${pkgdir}/opt/${_pkgname}/cargo/config"
rustflags = ["-C", "link-arg=-lmsvcrt"]
EOF
  fi
}

# vim:set ts=2 sw=2 et: