-
Notifications
You must be signed in to change notification settings - Fork 191
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improves nim installation by using csources (same as atlas) #1233
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
1db4482
draft: improves nim installation by using csources (same as atlas)
jmgomez bd8a44d
progress
jmgomez d8dc108
refactor: extract file nimenv
jmgomez 164d5dc
Fixes an issue where the packageCache wasnt being shared in local mode
jmgomez d6bf2ae
[Green]Should be able to install different Nim versions
jmgomez 4219920
fix warnings
jmgomez 3eddde6
missing display
jmgomez 06cbbb8
fix typo
jmgomez 72d9879
Remove nimble from nim compilation Fixes #1175
jmgomez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More future proof would be:
But it's also somewhat risky to predict the future this far.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok but It's an easy enough change to do when
csources
is increased as there is a test already that uses it in thenimble
ci