diff --git a/commands/setup-environment-commands b/commands/setup-environment-commands index 0d85e2a48..33b6fea88 100755 --- a/commands/setup-environment-commands +++ b/commands/setup-environment-commands @@ -104,7 +104,8 @@ export APPIMAGE_HOME="${APPIMAGE_HOME:-"$HOME/Applications"}" # reset paths and flags export PATH="$DOROTHY/commands:$XDG_BIN_HOME:/usr/sbin:/usr/bin:/sbin:/bin:$PATH" # $PATH last to make sure we inherit operating-system specific paths, such as WSL paths, and let the deduplicator later trim out duplicates in preferred order -export MANPATH='/usr/share/man' INFOPATH='/usr/share/info' CLASSPATH='' LDFLAGS='' CPPFLAGS='' PKG_CONFIG_PATH='' +export MANPATH INFOPATH CLASSPATH PKG_CONFIG_PATH # don't wipe, as we want to inherit +export LDFLAGS='' CPPFLAGS='' CC='' CXX='' # do wipe as don't have duplicate prevention # local vars p='' @@ -165,14 +166,38 @@ if test -z "${GNUPGHOME-}"; then fi fi -# Apple Command Line Tools -if test -d '/Library/Developer/CommandLineTools/usr/bin'; then - PATH="/Library/Developer/CommandLineTools/usr/bin:$PATH" -fi - # Xcode -if test -d '/Applications/Xcode.app/Contents/Developer/usr/bin'; then - PATH="/Applications/Xcode.app/Contents/Developer/usr/bin:$PATH" +if test -d '/Applications/Xcode.app'; then + # Apple Command Line Tools + if test -d '/Library/Developer/CommandLineTools/usr/bin'; then + PATH="/Library/Developer/CommandLineTools/usr/bin:$PATH" + fi + + # Xcode Command Line Tools + if test -d '/Applications/Xcode.app/Contents/Developer/usr/bin'; then + PATH="/Applications/Xcode.app/Contents/Developer/usr/bin:$PATH" + fi + + # Xcode Toolchain + if test -d '/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/'; then + PATH="/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/:$PATH" + CC='/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang' # xcrun --find clang + CXX='/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++' # xcrun --find clang++ + fi + + # Xcode LLVM + # /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk => /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk => xcrun --sdk macosx --show-sdk-pa + p='/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk' + if test -d "$p/usr/lib"; then + LDFLAGS="-L$p/usr/lib $LDFLAGS" + fi + if test -d "$p/usr/include"; then + CPPFLAGS="-I$p/usr/include $CPPFLAGS" + fi + if test -d "$p/System/Library/Frameworks"; then + # https://stackoverflow.com/a/68766210 + LDFLAGS="-F$p/System/Library/Frameworks/ $LDFLAGS" + fi fi # Snap @@ -219,9 +244,21 @@ fi if test -d '/usr/local/sbin'; then PATH="/usr/local/sbin:$PATH" fi +if test -d '/usr/share/man'; then + MANPATH="/usr/share/man:$MANPATH" +fi if test -d '/usr/local/man'; then MANPATH="/usr/local/man:$MANPATH" fi +if test -d '/usr/share/info'; then + INFOPATH="/usr/share/info:$INFOPATH" +fi +if test -d '/usr/lib'; then + LDFLAGS="-L/usr/lib $LDFLAGS" +fi +if test -d '/usr/lib/pkgconfig'; then + PKG_CONFIG_PATH="/usr/lib/pkgconfig:$PKG_CONFIG_PATH" +fi # Homebrew if is-mac; then @@ -282,7 +319,7 @@ if test -x "${HOMEBREW_PREFIX-}/bin/brew"; then INFOPATH="$HOMEBREW_PREFIX/share/info:$INFOPATH" fi - # for compilers to find homebrew + # for compilers to find llvm if test -d "$HOMEBREW_PREFIX/lib"; then LDFLAGS="-L$HOMEBREW_PREFIX/lib $LDFLAGS" fi @@ -585,6 +622,14 @@ fi # Generics: XDG, always add, even if not existent, in case it is created later PATH="$XDG_BIN_HOME:$PATH" +# GO LLVM +# https://stackoverflow.com/a/58488820 +if test -n "${GOPATH-}"; then + export CGO_CPPFLAGS CGO_LDFLAGS + CGO_CPPFLAGS="$CPPFLAGS -O2 -g -Wno-nullability-completeness" + CGO_LDFLAGS="$LDFLAGS -O2 -g" +fi + # Scripts before_dorothy_paths PATH="$DOROTHY/commands:$PATH" diff --git a/commands/setup-go b/commands/setup-go index 1f3569afc..3616fda68 100755 --- a/commands/setup-go +++ b/commands/setup-go @@ -93,18 +93,7 @@ function setup_go() ( # if yes, then install the linting tools if test "$GO_LINTING_INSTALL" = 'yes'; then - # https://github.com/golang/vscode-go/blob/master/docs/tools.md - # https://github.com/golang/tools/blob/master/gopls/README.md - GO_INSTALL+=( - golang.org/x/tools/gopls - github.com/go-delve/delve/cmd/dlv - # github.com/uudashr/gopkgs/cmd/gopkgs - github.com/ramya-rao-a/go-outline - # github.com/haya14busa/goplay/cmd/goplay - github.com/fatih/gomodifytags - github.com/josharian/impl - github.com/cweill/gotests/... - ) + setup-util-golint fi # ===================================== @@ -112,16 +101,6 @@ function setup_go() ( setup-util --installer=GO -- "${GO_INSTALL[@]}" - # ===================================== - # Extras - - # If gometalinter exists, complete its installation. - if command-exists gometalinter; then - echo-segment --h2="[gometalinter] dependencies" - eval-helper --quiet -- gometalinter --install || : - echo-segment --g2="[gometalinter] dependencies" - fi - # ===================================== # Configure diff --git a/commands/setup-util-golint b/commands/setup-util-golint new file mode 100755 index 000000000..fe93e7d6c --- /dev/null +++ b/commands/setup-util-golint @@ -0,0 +1,160 @@ +#!/usr/bin/env bash + +# https://github.com/golangci/golangci-lint/releases + +# golangci-lint-1.55.2-darwin-amd64.tar.gz +# golangci-lint-1.55.2-darwin-arm64.tar.gz +# golangci-lint-1.55.2-freebsd-386.tar.gz +# golangci-lint-1.55.2-freebsd-amd64.tar.gz +# golangci-lint-1.55.2-freebsd-armv6.tar.gz +# golangci-lint-1.55.2-freebsd-armv7.tar.gz +# golangci-lint-1.55.2-illumos-amd64.tar.gz +# golangci-lint-1.55.2-linux-386.deb +# golangci-lint-1.55.2-linux-386.rpm +# golangci-lint-1.55.2-linux-386.tar.gz +# golangci-lint-1.55.2-linux-amd64.deb +# golangci-lint-1.55.2-linux-amd64.rpm +# golangci-lint-1.55.2-linux-amd64.tar.gz +# golangci-lint-1.55.2-linux-arm64.deb +# golangci-lint-1.55.2-linux-arm64.rpm +# golangci-lint-1.55.2-linux-arm64.tar.gz +# golangci-lint-1.55.2-linux-armv6.deb +# golangci-lint-1.55.2-linux-armv6.rpm +# golangci-lint-1.55.2-linux-armv6.tar.gz +# golangci-lint-1.55.2-linux-armv7.deb +# golangci-lint-1.55.2-linux-armv7.rpm +# golangci-lint-1.55.2-linux-armv7.tar.gz +# golangci-lint-1.55.2-linux-loong64.deb +# golangci-lint-1.55.2-linux-loong64.rpm +# golangci-lint-1.55.2-linux-loong64.tar.gz +# golangci-lint-1.55.2-linux-mips64.deb +# golangci-lint-1.55.2-linux-mips64.rpm +# golangci-lint-1.55.2-linux-mips64.tar.gz +# golangci-lint-1.55.2-linux-mips64le.deb +# golangci-lint-1.55.2-linux-mips64le.rpm +# golangci-lint-1.55.2-linux-mips64le.tar.gz +# golangci-lint-1.55.2-linux-ppc64le.deb +# golangci-lint-1.55.2-linux-ppc64le.rpm +# golangci-lint-1.55.2-linux-ppc64le.tar.gz +# golangci-lint-1.55.2-linux-riscv64.deb +# golangci-lint-1.55.2-linux-riscv64.rpm +# golangci-lint-1.55.2-linux-riscv64.tar.gz +# golangci-lint-1.55.2-linux-s390x.deb +# golangci-lint-1.55.2-linux-s390x.rpm +# golangci-lint-1.55.2-linux-s390x.tar.gz +# golangci-lint-1.55.2-netbsd-386.tar.gz +# golangci-lint-1.55.2-netbsd-amd64.tar.gz +# golangci-lint-1.55.2-netbsd-armv6.tar.gz +# golangci-lint-1.55.2-netbsd-armv7.tar.gz +# golangci-lint-1.55.2-source.tar.gz +# golangci-lint-1.55.2-windows-386.zip +# golangci-lint-1.55.2-windows-amd64.zip +# golangci-lint-1.55.2-windows-arm64.zip +# golangci-lint-1.55.2-windows-armv6.zip +# golangci-lint-1.55.2-windows-armv7.zip + +function setup_util_golint() ( + source "$DOROTHY/sources/bash.bash" + local arch options=() + + # only install official linting tools + # https://github.com/golang/vscode-go/blob/master/docs/tools.md + + # ensure dev tools are installed + setup-util-devel --quiet + + # https://github.com/golang/tools/blob/master/gopls/README.md + # _cgo_export.c:3:10: fatal error: 'stdlib.h' file not found + options=( + --cli='gopls' + "$@" + GO='golang.org/x/tools/gopls' + ) + setup-util "${options[@]}" + + # https://github.com/go-delve/delve/tree/master/Documentation/installation + # _cgo_export.c:3:10: fatal error: 'stdlib.h' file not found + options=( + --name='Delve' + --cli='dlv' + "$@" + GO='github.com/go-delve/delve/cmd/dlv' + ) + setup-util "${options[@]}" + + # golangci-lint + options=( + --cli='golangci-lint' + "$@" + BREW='golangci-lint' + ) + function get_github_asset_url { + github-download \ + --dry \ + --slug='golangci/golangci-lint' \ + --release='latest' \ + --asset-filter="$(echo-escape-regex -- "$1")$" | echo-first-line || : + } + function add_download_option { + options+=( + DOWNLOAD="$(get_github_asset_url "$1")" + DOWNLOAD_UNZIP_FILTER="*/$2" + ) + } + function add_deb_option { + options+=( + DEB="$(get_github_asset_url "$1")" + ) + } + function add_rpm_option { + options+=( + RPM="$(get_github_asset_url "$1")" + ) + } + arch="$(get-arch)" + if is-mac; then + if test "$arch" = 'a64'; then + add_download_option '-darwin-arm64.tar.gz' 'golangci-lint' + elif test "$arch" = 'x64'; then + add_download_option '-darwin-amd64.tar.gz' 'golangci-lint' + fi + elif is-linux; then + if test "$arch" = 'a64'; then + add_deb_option '-linux-arm64.deb' + add_rpm_option '-linux-arm64.rpm' + add_download_option '-linux-arm64.tar.gz' 'golangci-lint' + elif test "$arch" = 'a32'; then + add_deb_option '-linux-armv7.deb' + add_rpm_option '-linux-armv7.rpm' + add_download_option '-linux-armv7.tar.gz' 'golangci-lint' + elif test "$arch" = 'x64'; then + add_deb_option '-linux-amd64.deb' + add_rpm_option '-linux-amd64.rpm' + add_download_option '-linux-amd64.tar.gz' 'golangci-lint' + elif test "$arch" = 'x32'; then + add_deb_option '-linux-386.deb' + add_rpm_option '-linux-386.rpm' + add_download_option '-linux-386.tar.gz' 'golangci-lint' + elif test "$arch" = 'r64'; then + add_deb_option '-linux-riscv64.deb' + add_rpm_option '-linux-riscv64.rpm' + add_download_option '-linux-riscv64.tar.gz' 'golangci-lint' + fi + elif is-wsl; then + if test "$arch" = 'a64'; then + add_download_option '-windows-arm64.zip' 'golangci-lint.exe' + elif test "$arch" = 'a32'; then + add_download_option '-windows-armv7.zip' 'golangci-lint.exe' + elif test "$arch" = 'x64'; then + add_download_option '-windows-amd64.zip' 'golangci-lint.exe' + elif test "$arch" = 'x32'; then + add_download_option '-windows-386.zip' 'golangci-lint.exe' + fi + fi + setup-util "${options[@]}" +) + +# fire if invoked standalone +if test "$0" = "${BASH_SOURCE[0]}"; then + setup_util_golint "$@" +fi