Skip to content

Commit

Permalink
Merge pull request #33 from nim-lang/pr_staticBuild
Browse files Browse the repository at this point in the history
drop analytics deps and staticBuild deps and use release
  • Loading branch information
ringabout authored Sep 19, 2024
2 parents 81863fc + 1434f3d commit 1b74468
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 84 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/release_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
ls -lah
cd choosenim
nimble install -y
nimble build --path:$NIMPATH
nimble build --path:$NIMPATH -d:release -d:staticBuild
ls bin/*
- name: Write release version
Expand Down Expand Up @@ -63,7 +63,7 @@ jobs:
- name: Build binary
run: |
nimble install -y
nimble build
nimble build -d:release -d:staticBuild
dir bin/*
- name: Write release version
Expand Down Expand Up @@ -94,7 +94,7 @@ jobs:
- name: Build binary
run: |
nimble install -y
nimble build
nimble build -d:release -d:staticBuild
dir bin/*
mkdir zipfile
mkdir zipfile/choosenim
Expand Down Expand Up @@ -130,7 +130,7 @@ jobs:
run: |
git config --global --add safe.directory /__w/choosenim/choosenim
nimble install -y
nimble build
nimble build -d:release -d:staticBuild
ls bin/*
- name: Write release version
Expand Down Expand Up @@ -159,7 +159,7 @@ jobs:
run: |
git config --global --add safe.directory /__w/choosenim/choosenim
nimble install -y
nimble build
nimble build -d:release -d:staticBuild
ls bin/*
- name: Write release version
Expand Down
3 changes: 1 addition & 2 deletions choosenim.nimble
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@ requires "nim", "nimble#ed0b6ee"
when defined(macosx):
requires "libcurl >= 1.0.0"

requires "analytics >= 0.3.0"
requires "osinfo"
requires "zippy >= 0.7.2"
when defined(windows):
requires "puppy >= 1.5.4"

task release, "Build a release binary":
exec "nimble build -d:release"
exec "nimble build -d:release -d:staticBuild"
13 changes: 7 additions & 6 deletions src/choosenim.nim
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import nimblepkg/common as nimbleCommon
from nimblepkg/tools import getNameVersionChecksum

import choosenimpkg/[download, builder, switcher, common, cliparams, versions]
import choosenimpkg/[utils, channel, telemetry]
import choosenimpkg/[utils, channel]
# import choosenimpkg/telemetry

when defined(windows):
import choosenimpkg/env
Expand Down Expand Up @@ -56,7 +57,7 @@ proc safeSwitchTo(version: Version, params: CliParams, wasInstalled: bool) =
display("Warning:", "Cleaning failed: " & exc.msg, Warning)

# Report telemetry.
report(initEvent(ErrorEvent, label=exc.msg), params)
# report(initEvent(ErrorEvent, label=exc.msg), params)
raise newException(ChooseNimError, "Installation failed")

proc chooseVersion(version: string, params: CliParams) =
Expand Down Expand Up @@ -325,7 +326,7 @@ proc remove(params: CliParams) =

proc performAction(params: CliParams) =
# Report telemetry.
report(initEvent(ActionEvent), params)
# report(initEvent(ActionEvent), params)

case params.command.normalize
of "update":
Expand All @@ -346,14 +347,14 @@ when isMainModule:
try:
parseCliParams(params)
createDir(params.chooseNimDir)
discard loadAnalytics(params)
# discard loadAnalytics(params)
performAction(params)
except NimbleError:
let currentExc = (ref NimbleError)(getCurrentException())
(error, hint) = getOutputInfo(currentExc)
# Report telemetry.
report(currentExc, params)
report(initEvent(ErrorEvent, label=currentExc.msg), params)
# report(currentExc, params)
# report(initEvent(ErrorEvent, label=currentExc.msg), params)

if error.len > 0:
displayTip()
Expand Down
7 changes: 6 additions & 1 deletion src/choosenim.nims
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,9 @@ when defined(macosx) and isAppleSilicon():
switch("passC", "-Wno-incompatible-function-pointer-types")

when defined(staticBuild):
import "choosenimpkg/proxyexe.nims"
when defined(linux):
putEnv("CC", "musl-gcc")
switch("gcc.exe", "musl-gcc")
switch("gcc.linkerexe", "musl-gcc")
when not defined(OSX):
switch("passL", "-static")
13 changes: 7 additions & 6 deletions src/choosenimpkg/builder.nim
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import os, times
import nimblepkg/[version, cli]
import nimblepkg/common as nimble_common

import cliparams, download, utils, common, telemetry
import cliparams, download, utils, common
# import telemetry

when defined(windows):
import switcher
Expand Down Expand Up @@ -109,7 +110,7 @@ proc setPermissions() =

proc build*(extractDir: string, version: Version, params: CliParams) =
# Report telemetry.
report(initEvent(BuildEvent), params)
# report(initEvent(BuildEvent), params)
let startTime = epochTime()

let currentDir = getCurrentDir()
Expand Down Expand Up @@ -162,8 +163,8 @@ proc build*(extractDir: string, version: Version, params: CliParams) =
display("Warning:", "Cleaning c_code failed: " & exc.msg, Warning)

# Report telemetry.
report(initEvent(BuildSuccessEvent), params)
report(initTiming(BuildTime, $version, startTime, $LabelSuccess), params)
# report(initEvent(BuildSuccessEvent), params)
# report(initTiming(BuildTime, $version, startTime, $LabelSuccess), params)

if not success and not params.skipClean:
# Perform clean up.
Expand All @@ -176,5 +177,5 @@ proc build*(extractDir: string, version: Version, params: CliParams) =
display("Warning:", "Cleaning failed: " & exc.msg, Warning)

# Report telemetry.
report(initEvent(BuildFailureEvent), params)
report(initTiming(BuildTime, $version, startTime, $LabelFailure), params)
# report(initEvent(BuildFailureEvent), params)
# report(initTiming(BuildTime, $version, startTime, $LabelFailure), params)
4 changes: 2 additions & 2 deletions src/choosenimpkg/cliparams.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import parseopt, strutils, os

import nimblepkg/[cli, options, config]
import nimblepkg/common as nimble_common
import analytics
# import analytics

import common

Expand All @@ -13,7 +13,7 @@ type
choosenimDir*: string
firstInstall*: bool
nimbleOptions*: Options
analytics*: PuppyAnalytics
# analytics*: PuppyAnalytics
pendingReports*: int ## Count of pending telemetry reports.
force*: bool
latest*: bool
Expand Down
7 changes: 4 additions & 3 deletions src/choosenimpkg/download.nim
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import nimblepkg/[version, cli]
when defined(curl):
import libcurl except Version

import cliparams, common, telemetry, utils
import cliparams, common, utils
# import telemetry

const
githubTagReleasesUrl = "https://api.github.com/repos/nim-lang/Nim/tags"
Expand Down Expand Up @@ -218,15 +219,15 @@ proc downloadFile*(url, outputPath: string, params: CliParams) =
let msg = "Couldn't download file from $1.\nResponse was: $2" %
[url, getCurrentExceptionMsg()]
display("Info:", msg, Warning, MediumPriority)
report(initTiming(DownloadTime, url, startTime, $LabelFailure), params)
# report(initTiming(DownloadTime, url, startTime, $LabelFailure), params)
raise

moveFile(tempOutputPath, outputPath)

showBar(1, 0)
echo("")

report(initTiming(DownloadTime, url, startTime, $LabelSuccess), params)
# report(initTiming(DownloadTime, url, startTime, $LabelSuccess), params)

proc needsDownload(params: CliParams, downloadUrl: string,
outputPath: var string): bool =
Expand Down
118 changes: 59 additions & 59 deletions src/choosenimpkg/telemetry.nim
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

import os, strutils, options, times, asyncdispatch

import analytics, nimblepkg/cli
# import analytics
import nimblepkg/cli

when defined(windows):
import osinfo/win
Expand Down Expand Up @@ -65,39 +66,38 @@ proc promptCustom(msg: string, params: CliParams): string =
else:
return promptCustom(msg, "")

proc analyticsPrompt(params: CliParams) =
let msg = ("Can choosenim record and send anonymised telemetry " &
"data? [y/n]\n" &
"Anonymous aggregate user analytics allow us to prioritise\n" &
"fixes and features based on how, where and when people " &
"use Nim.\n" &
"For more details see: https://goo.gl/NzUEPf.")

let resp = promptCustom(msg, params)
let analyticsFile = params.getAnalyticsFile()
case resp.normalize
of "y", "yes":
let clientID = analytics.genClientID()
writeFile(analyticsFile, clientID)
display("Info:", "Your client ID is " & clientID, priority=LowPriority)
of "n", "no":
# Write an empty file to signify that the user answered "No".
writeFile(analyticsFile, "")
return
else:
# Force the user to answer.
analyticsPrompt(params)

proc report*(obj: Event | Timing | ref Exception, params: CliParams)
proc loadAnalytics*(params: CliParams): bool =
## Returns ``true`` if ``analytics`` object has been loaded successfully.
display("Info:",
"Not sending analytics because they are currently disabled. If turned back on in a future update your preference is to " &
(if getEnv("CHOOSENIM_NO_ANALYTICS") == "1" or getEnv("DO_NOT_TRACK") == "1": "not send" else: "send") & " analytics.",
priority=MediumPriority)
return false

when false: # TODO: Re-enable once analytics is set up again
when false: # TODO: Re-enable once analytics is set up again
proc analyticsPrompt(params: CliParams) =
let msg = ("Can choosenim record and send anonymised telemetry " &
"data? [y/n]\n" &
"Anonymous aggregate user analytics allow us to prioritise\n" &
"fixes and features based on how, where and when people " &
"use Nim.\n" &
"For more details see: https://goo.gl/NzUEPf.")

let resp = promptCustom(msg, params)
let analyticsFile = params.getAnalyticsFile()
case resp.normalize
of "y", "yes":
let clientID = analytics.genClientID()
writeFile(analyticsFile, clientID)
display("Info:", "Your client ID is " & clientID, priority=LowPriority)
of "n", "no":
# Write an empty file to signify that the user answered "No".
writeFile(analyticsFile, "")
return
else:
# Force the user to answer.
analyticsPrompt(params)

proc report*(obj: Event | Timing | ref Exception, params: CliParams)
proc loadAnalytics*(params: CliParams): bool =
## Returns ``true`` if ``analytics`` object has been loaded successfully.
display("Info:",
"Not sending analytics because they are currently disabled. If turned back on in a future update your preference is to " &
(if getEnv("CHOOSENIM_NO_ANALYTICS") == "1" or getEnv("DO_NOT_TRACK") == "1": "not send" else: "send") & " analytics.",
priority=MediumPriority)

if getEnv("CHOOSENIM_NO_ANALYTICS") == "1" or getEnv("DO_NOT_TRACK") == "1":
display("Info:",
"Not sending analytics because either CHOOSENIM_NO_ANALYTICS or DO_NOT_TRACK is set.",
Expand Down Expand Up @@ -125,8 +125,8 @@ proc loadAnalytics*(params: CliParams): bool =
return false

params.analytics = newPuppyAnalytics("UA-105812497-1", clientID, "choosenim",
chooseNimVersion, proxy = getProxy(),
timeout=5)
chooseNimVersion, proxy = getProxy(),
timeout=5)

# Report OS info only once.
if prompted:
Expand All @@ -149,29 +149,29 @@ proc reportAsyncError(fut: Future[void], params: CliParams) =

proc hasPendingReports*(params: CliParams): bool = params.pendingReports > 0


proc report*(obj: Event | Timing | ref Exception, params: CliParams) =
try:
if not loadAnalytics(params):
when false:
proc report*(obj: Event | Timing | ref Exception, params: CliParams) =
try:
if not loadAnalytics(params):
return
except Exception as exc:
display("Warning:", "Could not load analytics reporter due to error:" &
exc.msg, Warning, MediumPriority)
return
except Exception as exc:
display("Warning:", "Could not load analytics reporter due to error:" &
exc.msg, Warning, MediumPriority)
return

displayDebug("Reporting to analytics...")

try:
when obj is Event:
params.analytics.reportEvent($obj.category, obj.action,
obj.label, obj.value)
elif obj is Timing:
params.analytics.reportTiming($obj.category, obj.name,
obj.time, obj.label)
else:
params.analytics.reportException(obj.msg)

except Exception as exc:
display("Warning:", "Could not report to analytics due to error:" &
exc.msg, Warning, MediumPriority)
displayDebug("Reporting to analytics...")

try:
when obj is Event:
params.analytics.reportEvent($obj.category, obj.action,
obj.label, obj.value)
elif obj is Timing:
params.analytics.reportTiming($obj.category, obj.name,
obj.time, obj.label)
else:
params.analytics.reportException(obj.msg)

except Exception as exc:
display("Warning:", "Could not report to analytics due to error:" &
exc.msg, Warning, MediumPriority)

0 comments on commit 1b74468

Please sign in to comment.