-
Notifications
You must be signed in to change notification settings - Fork 190
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improves nim installation by using csources (same as atlas) (#1233)
* draft: improves nim installation by using csources (same as atlas) Notice when SAT is enabled, csources is stored in the cache. Missing: -- Proper reporting -- Handle special versions (assume csources_2?). We could have special cases for #version-x - Refactor to another file (nimble.nim is crazy big already) * progress * refactor: extract file nimenv * Fixes an issue where the packageCache wasnt being shared in local mode * [Green]Should be able to install different Nim versions * fix warnings * missing display * fix typo * Remove nimble from nim compilation Fixes #1175
- Loading branch information
Showing
18 changed files
with
308 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
import std/[strscans, os, strutils, strformat] | ||
import version, nimblesat, cli, common, options | ||
|
||
when defined(windows): | ||
const | ||
BatchFile = """ | ||
@echo off | ||
set PATH="$1";%PATH% | ||
""" | ||
else: | ||
const | ||
ShellFile = "export PATH=$1:$$PATH\n" | ||
|
||
const ActivationFile = | ||
when defined(windows): "activate.bat" else: "activate.sh" | ||
|
||
proc infoAboutActivation(nimDest, nimVersion: string) = | ||
when defined(windows): | ||
display("Info", nimDest & "installed; activate with 'nim-" & nimVersion & "activate.bat'") | ||
else: | ||
display("Info", nimDest & "installed; activate with 'source nim-" & nimVersion & "activate.sh'") | ||
|
||
proc compileNim*(options: Options, nimDest: string, v: VersionRange) = | ||
let keepCsources = options.useSatSolver #SAT Solver has a cache instead of a temp dir for downloads | ||
template exec(command: string) = | ||
let cmd = command # eval once | ||
if os.execShellCmd(cmd) != 0: | ||
display("Error", "Failed to execute: $1" % cmd, Error, HighPriority) | ||
return | ||
let nimVersion = v.getNimVersion() | ||
let workspace = nimDest.parentDir() | ||
if dirExists(workspace / nimDest): | ||
if not fileExists(nimDest / ActivationFile): | ||
display("Info", &"Directory {nimDest} already exists; remove or rename and try again") | ||
else: | ||
infoAboutActivation nimDest, $nimVersion | ||
return | ||
|
||
var major, minor, patch: int | ||
if not nimVersion.isSpecial: | ||
if not scanf($nimVersion, "$i.$i.$i", major, minor, patch): | ||
display("Error", "cannot parse version requirement", Error) | ||
return | ||
let csourcesVersion = | ||
#TODO We could test special against the special versionn-x branch to get the right csources | ||
if nimVersion.isSpecial or (major == 1 and minor >= 9) or major >= 2: | ||
# already uses csources_v2 | ||
"csources_v2" | ||
elif major == 0: | ||
"csources" # has some chance of working | ||
else: | ||
"csources_v1" | ||
cd workspace: | ||
echo "Entering CSOURCES", csourcesVersion, " exists ", dirExists(csourcesVersion) | ||
if not dirExists(csourcesVersion): | ||
exec "git clone https://github.com/nim-lang/" & csourcesVersion | ||
|
||
cd workspace / csourcesVersion: | ||
when defined(windows): | ||
exec "build.bat" | ||
else: | ||
let makeExe = findExe("make") | ||
if makeExe.len == 0: | ||
exec "sh build.sh" | ||
else: | ||
exec "make" | ||
let nimExe0 = ".." / csourcesVersion / "bin" / "nim".addFileExt(ExeExt) | ||
cd nimDest: | ||
let nimExe = "bin" / "nim".addFileExt(ExeExt) | ||
copyFileWithPermissions nimExe0, nimExe | ||
exec nimExe & " c --noNimblePath --skipUserCfg --skipParentCfg --hints:off koch" | ||
let kochExe = when defined(windows): "koch.exe" else: "./koch" | ||
exec kochExe & " boot -d:release --skipUserCfg --skipParentCfg --hints:off" | ||
exec kochExe & " tools --skipUserCfg --skipParentCfg --hints:off" | ||
# unless --keep is used delete the csources because it takes up about 2GB and | ||
# is not necessary afterwards: | ||
if not keepCsources: | ||
removeDir workspace / csourcesVersion / "c_code" | ||
let pathEntry = workspace / nimDest / "bin" | ||
#remove nimble so it doesnt interfer with the current one: | ||
removeFile "bin" / "nimble".addFileExt(ExeExt) | ||
when defined(windows): | ||
writeFile "activate.bat", BatchFile % pathEntry.replace('/', '\\') | ||
else: | ||
writeFile "activate.sh", ShellFile % pathEntry | ||
infoAboutActivation nimDest, $nimVersion | ||
|
||
|
||
proc useNimFromDir*(options: var Options, realDir: string, v: VersionRange, tryCompiling = false) = | ||
const binaryName = when defined(windows): "nim.exe" else: "nim" | ||
|
||
let | ||
nim = realDir / "bin" / binaryName | ||
fileExists = fileExists(options.nimBin) | ||
|
||
if not fileExists(nim): | ||
if tryCompiling and options.prompt("Develop version of nim was found but it is not compiled. Compile it now?"): | ||
compileNim(options, realDir, v) | ||
else: | ||
raise nimbleError("Trying to use nim from $1 " % realDir, | ||
"If you are using develop mode nim make sure to compile it.") | ||
|
||
options.nimBin = nim | ||
let separator = when defined(windows): ";" else: ":" | ||
|
||
putEnv("PATH", realDir / "bin" & separator & getEnv("PATH")) | ||
if fileExists: | ||
display("Info:", "switching to $1 for compilation" % options.nim, priority = HighPriority) | ||
else: | ||
display("Info:", "using $1 for compilation" % options.nim, priority = HighPriority) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Package | ||
|
||
version = "0.1.0" | ||
author = "jmgomez" | ||
description = "A new awesome nimble package" | ||
license = "MIT" | ||
srcDir = "src" | ||
|
||
|
||
# Dependencies | ||
|
||
requires "nim == 1.6.20" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# This is just an example to get you started. A typical library package | ||
# exports the main API in this file. Note that you cannot rename this file | ||
# but you can remove it if you wish. | ||
|
||
proc add*(x, y: int): int = | ||
## Adds two numbers together. | ||
return x + y |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# This is just an example to get you started. Users of your library will | ||
# import this file by writing ``import nim1620/submodule``. Feel free to rename or | ||
# remove this file altogether. You may create additional modules alongside | ||
# this file as required. | ||
|
||
type | ||
Submodule* = object | ||
name*: string | ||
|
||
proc initSubmodule*(): Submodule = | ||
## Initialises a new ``Submodule`` object. | ||
Submodule(name: "Anonymous") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# This is just an example to get you started. You may wish to put all of your | ||
# tests into a single file, or separate them into multiple `test1`, `test2` | ||
# etc. files (better names are recommended, just make sure the name starts with | ||
# the letter 't'). | ||
# | ||
# To run these tests, simply execute `nimble test`. | ||
|
||
import unittest | ||
|
||
import nim1620 | ||
test "can add": | ||
check add(5, 5) == 10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Package | ||
|
||
version = "0.1.0" | ||
author = "jmgomez" | ||
description = "A new awesome nimble package" | ||
license = "MIT" | ||
srcDir = "src" | ||
|
||
|
||
# Dependencies | ||
|
||
requires "nim == 2.0.4" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# This is just an example to get you started. A typical library package | ||
# exports the main API in this file. Note that you cannot rename this file | ||
# but you can remove it if you wish. | ||
|
||
proc add*(x, y: int): int = | ||
## Adds two numbers together. | ||
return x + y |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# This is just an example to get you started. Users of your library will | ||
# import this file by writing ``import nim204/submodule``. Feel free to rename or | ||
# remove this file altogether. You may create additional modules alongside | ||
# this file as required. | ||
|
||
type | ||
Submodule* = object | ||
name*: string | ||
|
||
proc initSubmodule*(): Submodule = | ||
## Initialises a new ``Submodule`` object. | ||
Submodule(name: "Anonymous") |
Oops, something went wrong.