Skip to content

Commit

Permalink
Linux build, windows init.sh fixes (#238)
Browse files Browse the repository at this point in the history
  • Loading branch information
genotrance authored Oct 29, 2020
1 parent ae67c60 commit edc69bd
Show file tree
Hide file tree
Showing 10 changed files with 91 additions and 88 deletions.
7 changes: 6 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ os:
language: c

env:
- BRANCH=1.2.6
- BRANCH=1.2.8

cache:
directories:
Expand All @@ -18,6 +18,11 @@ addons:
packages:
- musl-tools

# Don't rebuild autotagged
branches:
except:
- /^v[0-9.]+-[0-9]+-[0-9a-f]+$/

script:
- source ./scripts/build.sh

Expand Down
6 changes: 1 addition & 5 deletions choosenim.nimble
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Package

version = "0.7.4"
version = "0.7.5"
author = "Dominik Picheta"
description = "The Nim toolchain installer."
license = "MIT"
Expand All @@ -18,7 +18,3 @@ requires "nimterop >= 0.6.12", "nimarchive >= 0.5.3"
#requires "libcurl >= 1.0.0" - OSX now uses httpclient
requires "analytics >= 0.2.0"
requires "osinfo >= 0.3.0"

task test, "Run the choosenim tester!":
withDir "tests":
exec "nim c -r tester"
97 changes: 47 additions & 50 deletions scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,63 +6,60 @@ source travis.sh

# Skip building autotagged version
export COMMIT_TAG=`git tag --points-at HEAD | head -n 1`
export COMMIT_HASH=`git rev-parse --short HEAD`
export CURRENT_BRANCH="${TRAVIS_BRANCH}"
echo "Commit tag: ${COMMIT_TAG}"
echo "Commit hash: ${COMMIT_HASH}"
echo "Current branch: ${CURRENT_BRANCH}"
if [[ "${COMMIT_TAG}" =~ ^v[0-9.]+-[0-9]+$ ]]; then
echo "Skipping build since autotagged version"

# Environment vars
if [[ "$TRAVIS_OS_NAME" == "windows" ]]; then
export EXT=".exe"
else
# Environment vars
if [[ "$TRAVIS_OS_NAME" == "windows" ]]; then
export EXT=".exe"
else
export EXT=""
fi
export EXT=""
fi

if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
export OSNAME="macosx"
else
export OSNAME="$TRAVIS_OS_NAME"
fi
if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
export OSNAME="macosx"
else
export OSNAME="$TRAVIS_OS_NAME"
fi

# Build and test
nimble install -y -d
nim c src/choosenim
# Build release version
nimble build -y -d:release -d:staticBuild

# Set version and tag info
export CHOOSENIM_VERSION="$(./src/choosenim --version | cut -f2,2 -d' ' | sed 's/v//')"
echo "Version: v${CHOOSENIM_VERSION}"
if [[ -z "${COMMIT_TAG}" ]]; then
# Create tag with date, not an official tagged release
export VERSION_TAG="${CHOOSENIM_VERSION}-$(date +'%Y%m%d')"
if [[ "${CURRENT_BRANCH}" == "master" ]]; then
# Deploy only on main branch
export TRAVIS_TAG="v${VERSION_TAG}"
export PRERELEASE=true
fi
elif [[ "${COMMIT_TAG}" == "v${CHOOSENIM_VERSION}" ]]; then
# Official tagged release
export VERSION_TAG="${CHOOSENIM_VERSION}"
export TRAVIS_TAG="${COMMIT_TAG}"
else
echo "Tag does not match choosenim version"
echo " Commit tag: ${COMMIT_TAG}"
echo " Version: v${CHOOSENIM_VERSION}"
echo " Current branch: ${CURRENT_BRANCH}"
travis_terminate 1
# Set version and tag info
export CHOOSENIM_VERSION="$(./bin/choosenim --version | cut -f2,2 -d' ' | sed 's/v//')"
echo "Version: v${CHOOSENIM_VERSION}"
if [[ -z "${COMMIT_TAG}" ]]; then
# Create tag with date and hash, not an official tagged release
export VERSION_TAG="${CHOOSENIM_VERSION}-$(date +'%Y%m%d')-${COMMIT_HASH}"
if [[ "${CURRENT_BRANCH}" == "master" ]]; then
# Deploy only on main branch
export TRAVIS_TAG="v${VERSION_TAG}"
export PRERELEASE=true
fi
echo "Travis tag: ${TRAVIS_TAG}"
echo "Prerelease: ${PRERELEASE}"
export FILENAME="bin/choosenim-${VERSION_TAG}_${OSNAME}_${TRAVIS_CPU_ARCH}"
echo "Filename: ${FILENAME}"
elif [[ "${COMMIT_TAG}" == "v${CHOOSENIM_VERSION}" ]]; then
# Official tagged release
export VERSION_TAG="${CHOOSENIM_VERSION}"
export TRAVIS_TAG="${COMMIT_TAG}"
else
# Other tag, mostly autotagged rebuild
export VERSION_TAG="${COMMIT_TAG:1}"
export TRAVIS_TAG="${COMMIT_TAG}"
export PRERELEASE=true
fi
echo "Travis tag: ${TRAVIS_TAG}"
echo "Prerelease: ${PRERELEASE}"
export FILENAME="bin/choosenim-${VERSION_TAG}_${OSNAME}_${TRAVIS_CPU_ARCH}"
echo "Filename: ${FILENAME}"

# Run tests
nimble test
yes | ./bin/choosenim stable # Workaround tester overwriting our Nimble install.
mv "bin/choosenim${EXT}" "${FILENAME}_debug${EXT}"
# Run tests
nimble test -d:release -d:staticBuild
strip "bin/choosenim${EXT}"
mv "bin/choosenim${EXT}" "${FILENAME}${EXT}"

# Build release version
nimble build -d:release
strip "bin/choosenim${EXT}"
mv "bin/choosenim${EXT}" "${FILENAME}${EXT}"
fi
# Build debug version
nimble build -g -d:staticBuild
./bin/choosenim${EXT} -v
mv "bin/choosenim${EXT}" "${FILENAME}_debug${EXT}"
17 changes: 5 additions & 12 deletions scripts/choosenim-unix-init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,16 @@ install() {
fi
local filename="choosenim-$stable_version"_"$platform"
local url="$url_prefix"v"$stable_version/$filename"
local ext=""

case $platform in
*macosx_amd64* | *linux_amd64* )
;;
*windows_amd64* )
# Download ZIP for Windows
local filename="$filename.zip"
local url="$url.zip"
local ext=".exe"
local filename="$filename$ext"
local url="$url$ext"
;;
* )
say_err "Sorry, your platform ($platform) is not supported by choosenim."
Expand All @@ -61,11 +63,6 @@ install() {
wget -qO "$temp_prefix/$filename" "$url"
fi
chmod +x "$temp_prefix/$filename"
if [ "$platform" = "windows_amd64" ]; then
# Extract ZIP for Windows
unzip -j -o -d $temp_prefix/choosenim $temp_prefix/$filename
local filename="choosenim/choosenim.exe"
fi

if [ "$need_tty" = "yes" ]; then
# The installer is going to want to ask for confirmation by
Expand All @@ -84,11 +81,7 @@ install() {

# Copy choosenim binary to Nimble bin.
local nimbleBinDir=`"$temp_prefix/$filename" --getNimbleBin`
if [ "$platform" = "windows_amd64" ]; then
cp "$temp_prefix/$filename" "$nimbleBinDir/."
else
cp "$temp_prefix/$filename" "$nimbleBinDir/choosenim"
fi
cp "$temp_prefix/$filename" "$nimbleBinDir/choosenim$ext"
say "ChooseNim installed in $nimbleBinDir"
say "You must now ensure that the Nimble bin dir is in your PATH."
if [ "$platform" != "windows_amd64" ]; then
Expand Down
17 changes: 4 additions & 13 deletions src/choosenim.nims
Original file line number Diff line number Diff line change
@@ -1,23 +1,14 @@
when findExe("musl-gcc").len != 0:
# Use musl-gcc when available
putEnv("CC", "musl-gcc")
switch("gcc.exe", "musl-gcc")
switch("gcc.linkerexe", "musl-gcc")

# Statically linking everything
when not defined(OSX):
switch("passL", "-static")

switch("define", "ssl")

when defined(windows):
# TODO: change once issue nim#15520 is resolved
# TODO: change once issue nim#15220 is resolved
switch("define", "noOpenSSLHacks")
switch("dynlibOverride", "ssl-")
switch("dynlibOverride", "crypto-")
switch("define", "sslVersion:(")

switch("passL", "-lws2_32")
else:
switch("dynlibOverride", "ssl")
switch("dynlibOverride", "crypto")

when defined(staticBuild):
import "choosenimpkg/proxyexe.nims"
2 changes: 1 addition & 1 deletion src/choosenimpkg/common.nim
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ type
ChooseNimError* = object of NimbleError

const
chooseNimVersion* = "0.7.4"
chooseNimVersion* = "0.7.5"

proxies* = [
"nim",
Expand Down
7 changes: 7 additions & 0 deletions src/choosenimpkg/proxyexe.nims
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
when defined(staticBuild):
when defined(linux):
putEnv("CC", "musl-gcc")
switch("gcc.exe", "musl-gcc")
switch("gcc.linkerexe", "musl-gcc")
when not defined(OSX):
switch("passL", "-static")
10 changes: 9 additions & 1 deletion src/choosenimpkg/ssl.nim
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{.used}

import strutils

import nimterop/[build, cimport]
import nimterop/build

# Download openssl from JuliaBinaryWrappers
setDefines(@[
Expand All @@ -18,3 +20,9 @@ const

# Link static binaries
{.passL: sslLPath & " " & cryptoLPath.}

# Deps for openssl
when defined(linux):
{.passL: "-lpthread".}
elif defined(windows):
{.passL: "-lws2_32".}
2 changes: 2 additions & 0 deletions src/choosenimpkg/switcher.nim
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ proc compileProxyexe() =
var cmd = "nim c"
when defined(release):
cmd.add " -d:release"
when defined(staticBuild):
cmd.add " -d:staticBuild"
cmd.add " proxyexe"
let (output, exitCode) = gorgeEx(cmd)
doAssert exitCode == 0, $(output, cmd)
Expand Down
14 changes: 9 additions & 5 deletions tests/tester.nim
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Copyright (C) Dominik Picheta. All rights reserved.
# BSD-3-Clause License. Look at license.txt for more info.
import osproc, streams, unittest, strutils, os, sequtils, future
import osproc, streams, unittest, strutils, os, sequtils, sugar

var rootDir = getCurrentDir().parentDir()
var rootDir = getCurrentDir()
var exePath = rootDir / "bin" / addFileExt("choosenim", ExeExt)
var nimbleDir = rootDir / "tests" / "nimbleDir"
var choosenimDir = rootDir / "tests" / "choosenimDir"
Expand Down Expand Up @@ -107,9 +107,13 @@ proc hasLine(lines: seq[string], line: string): bool =
if i.normalize.strip() == line.normalize(): return true

test "can compile choosenim":
cd "..":
let (_, exitCode) = exec("build", exe="nimble", global=true, liveOutput=true)
check exitCode == QuitSuccess
var args = @["build"]
when defined(release):
args.add "-d:release"
when defined(staticBuild):
args.add "-d:staticBuild"
let (_, exitCode) = exec(args, exe="nimble", global=true, liveOutput=true)
check exitCode == QuitSuccess

test "refuses invalid path":
beginTest()
Expand Down

0 comments on commit edc69bd

Please sign in to comment.