From 9aa099840718c20625124faee40afdcfb87d9416 Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Thu, 19 Sep 2024 11:17:47 +0800 Subject: [PATCH 1/2] drop analytics deps and staticBuild deps --- choosenim.nimble | 3 +- src/choosenim.nim | 13 ++-- src/choosenim.nims | 7 +- src/choosenimpkg/builder.nim | 13 ++-- src/choosenimpkg/cliparams.nim | 4 +- src/choosenimpkg/download.nim | 7 +- src/choosenimpkg/telemetry.nim | 118 ++++++++++++++++----------------- 7 files changed, 86 insertions(+), 79 deletions(-) diff --git a/choosenim.nimble b/choosenim.nimble index 86244ca..f95f330 100644 --- a/choosenim.nimble +++ b/choosenim.nimble @@ -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" diff --git a/src/choosenim.nim b/src/choosenim.nim index dbba962..3306e01 100644 --- a/src/choosenim.nim +++ b/src/choosenim.nim @@ -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 @@ -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) = @@ -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": @@ -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() diff --git a/src/choosenim.nims b/src/choosenim.nims index ed80270..f2df08a 100644 --- a/src/choosenim.nims +++ b/src/choosenim.nims @@ -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") diff --git a/src/choosenimpkg/builder.nim b/src/choosenimpkg/builder.nim index fd3119c..898a88c 100644 --- a/src/choosenimpkg/builder.nim +++ b/src/choosenimpkg/builder.nim @@ -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 @@ -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() @@ -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. @@ -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) diff --git a/src/choosenimpkg/cliparams.nim b/src/choosenimpkg/cliparams.nim index a4b998c..070e7e7 100644 --- a/src/choosenimpkg/cliparams.nim +++ b/src/choosenimpkg/cliparams.nim @@ -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 @@ -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 diff --git a/src/choosenimpkg/download.nim b/src/choosenimpkg/download.nim index 687d8cb..450f3db 100644 --- a/src/choosenimpkg/download.nim +++ b/src/choosenimpkg/download.nim @@ -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" @@ -218,7 +219,7 @@ 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) @@ -226,7 +227,7 @@ proc downloadFile*(url, outputPath: string, params: CliParams) = 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 = diff --git a/src/choosenimpkg/telemetry.nim b/src/choosenimpkg/telemetry.nim index fa23bcc..e04b5ae 100644 --- a/src/choosenimpkg/telemetry.nim +++ b/src/choosenimpkg/telemetry.nim @@ -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 @@ -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.", @@ -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: @@ -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) From 1434f3db387200177d461637828dde968fcd44e4 Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Thu, 19 Sep 2024 11:20:31 +0800 Subject: [PATCH 2/2] -d:release -d:staticBuild --- .github/workflows/release_build.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/release_build.yml b/.github/workflows/release_build.yml index 4015da8..b66af69 100644 --- a/.github/workflows/release_build.yml +++ b/.github/workflows/release_build.yml @@ -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 @@ -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 @@ -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 @@ -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 @@ -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