Add musl support

This commit is contained in:
Ganesh Viswanathan 2020-10-02 17:46:27 -05:00
commit 60cc0d26ef
4 changed files with 50 additions and 39 deletions

View file

@ -75,7 +75,7 @@ proc getGccLibPaths*(mode: string): seq[string] =
when defined(osx): when defined(osx):
result.add "/usr/lib" result.add "/usr/lib"
proc getGccInfo*(): tuple[arch, os, compiler, version: string] = proc getGccInfo*(): tuple[arch, os, compiler, version, libc: string] =
let let
(outp, _) = execAction(&"{getCompiler()} -v") (outp, _) = execAction(&"{getCompiler()} -v")
for line in outp.splitLines(): for line in outp.splitLines():
@ -101,3 +101,5 @@ proc getGccInfo*(): tuple[arch, os, compiler, version: string] =
result.compiler = "clang" result.compiler = "clang"
else: else:
result.compiler = "gcc" result.compiler = "gcc"
if "musl" in outp:
result.libc = "musl"

View file

@ -16,6 +16,8 @@ type
channel*: string channel*: string
recipes*: OrderedTableRef[string, seq[ConanBuild]] recipes*: OrderedTableRef[string, seq[ConanBuild]]
arch*, os*, compiler*, compversion*: string
bhash*: string bhash*: string
shared*: bool shared*: bool
sharedLibs*: seq[string] sharedLibs*: seq[string]
@ -89,6 +91,11 @@ proc `==`*(pkg1, pkg2: ConanPackage): bool =
pkg1.user == pkg2.user and pkg1.user == pkg2.user and
pkg1.channel == pkg2.channel and pkg1.channel == pkg2.channel and
pkg1.arch == pkg2.arch and
pkg1.os == pkg2.os and
pkg1.compiler == pkg2.compiler and
pkg1.compversion == pkg2.compversion and
pkg1.bhash == pkg2.bhash and pkg1.bhash == pkg2.bhash and
pkg1.shared == pkg2.shared) pkg1.shared == pkg2.shared)
@ -101,6 +108,15 @@ proc newConanPackage*(name, version, user = "_", channel = "_", bhash = "", shar
result.channel = channel result.channel = channel
result.recipes = newOrderedTable[string, seq[ConanBuild]](2) result.recipes = newOrderedTable[string, seq[ConanBuild]](2)
let
(arch, os, compiler, compversion, libc) = getGccInfo()
doAssert libc != "musl", "Conan does not provide precompiled binaries using musl"
result.arch = arch
result.os = os
result.compiler = compiler
result.compversion = compversion
result.bhash = bhash result.bhash = bhash
result.shared = shared result.shared = shared
@ -189,9 +205,7 @@ proc getConanBuilds*(pkg: ConanPackage, filter = "") =
## `filter` can be used to tweak search terms ## `filter` can be used to tweak search terms
## e.g. build_type=Debug&compiler=clang ## e.g. build_type=Debug&compiler=clang
let let
(arch, os, compiler, version) = getGccInfo() vsplit = pkg.compversion.split('.')
vsplit = version.split('.')
vfilter = vfilter =
when defined(OSX): when defined(OSX):
@ -203,18 +217,18 @@ proc getConanBuilds*(pkg: ConanPackage, filter = "") =
if pkg.bhash.Bl: if pkg.bhash.Bl:
block: block:
var var
query = &"?q=arch={arch}&os={os.capitalizeAscii()}" query = &"?q=arch={pkg.arch}&os={pkg.os.capitalizeAscii()}"
if "build_type" notin filter: if "build_type" notin filter:
query &= "&build_type=Release" query &= "&build_type=Release"
if "shared=" notin filter: if "shared=" notin filter:
query &= &"&options.shared={($pkg.shared).capitalizeAscii()}" query &= &"&options.shared={($pkg.shared).capitalizeAscii()}"
if filter.nBl: if filter.nBl:
query &= &"&{filter}" query &= &"&{filter}"
if "compiler=" notin filter and os != "windows": if "compiler=" notin filter and pkg.os != "windows":
query &= &"&compiler={compiler}&compiler.version=" & vfilter query &= &"&compiler={pkg.compiler}&compiler.version=" & vfilter
if "compiler.runtime=" notin filter and os == "windows": if "compiler.runtime=" notin filter and pkg.os == "windows":
query &= &"&compiler.runtime=MD" query &= &"&compiler.runtime=MD"
if "compiler.version=" notin filter and os == "windows": if "compiler.version=" notin filter and pkg.os == "windows":
query &= &"&compiler.version=14" query &= &"&compiler.version=14"
query.replace("&", "%20and%20") query.replace("&", "%20and%20")

View file

@ -17,6 +17,8 @@ type
url*: string # Download URL url*: string # Download URL
arch*, os*, libc*: string # Target
sharedLibs*: seq[string] sharedLibs*: seq[string]
staticLibs*: seq[string] staticLibs*: seq[string]
requires*: seq[JBBPackage] requires*: seq[JBBPackage]
@ -39,7 +41,11 @@ proc `==`*(pkg1, pkg2: JBBPackage): bool =
## Check if two JBBPackage objects are equal ## Check if two JBBPackage objects are equal
(not pkg1.isNil and not pkg2.isNil and (not pkg1.isNil and not pkg2.isNil and
pkg1.name == pkg2.name and pkg1.name == pkg2.name and
pkg1.version == pkg2.version) pkg1.version == pkg2.version and
pkg1.arch == pkg2.arch and
pkg1.os == pkg2.os and
pkg1.libc == pkg2.libc)
proc newJBBPackage*(name, version: string): JBBPackage = proc newJBBPackage*(name, version: string): JBBPackage =
## Create a new JBBPackage with specified name and version ## Create a new JBBPackage with specified name and version
@ -49,6 +55,12 @@ proc newJBBPackage*(name, version: string): JBBPackage =
result.baseUrl = jbbBaseUrl result.baseUrl = jbbBaseUrl
result.isGit = true result.isGit = true
let
(arch, os, _, _, libc) = getGccInfo()
result.arch = arch
result.os = os
result.libc = libc
proc parseJBBProject(pkg: JBBPackage, outdir: string) = proc parseJBBProject(pkg: JBBPackage, outdir: string) =
# Get all dependencies from Project.toml # Get all dependencies from Project.toml
let let
@ -87,8 +99,6 @@ proc parseJBBArtifacts(pkg: JBBPackage, outdir: string) =
let let
file = outdir / jbbArtifacts file = outdir / jbbArtifacts
(arch, os, _, _) = getGccInfo()
if fileExists(file): if fileExists(file):
let let
data = readFile(file) data = readFile(file)
@ -109,12 +119,14 @@ proc parseJBBArtifacts(pkg: JBBPackage, outdir: string) =
# Match arch, os and glibc on Linux to find download URL # Match arch, os and glibc on Linux to find download URL
case name case name
of "arch": of "arch":
if val == arch and not found: found = true if val == pkg.arch and not found: found = true
of "os": of "os":
if val != os and found: found = false if val != pkg.os and found: found = false
of "libc": of "libc":
when defined(Linux): when defined(Linux):
if val != "glibc" and found: found = false if found:
let libc = if pkg.libc.nBl: pkg.libc else: "glibc"
if val != libc: found = false
of "url": of "url":
if found: if found:
pkg.url = val pkg.url = val
@ -125,7 +137,7 @@ proc parseJBBArtifacts(pkg: JBBPackage, outdir: string) =
proc findJBBLibs(pkg: JBBPackage, outdir: string) = proc findJBBLibs(pkg: JBBPackage, outdir: string) =
pkg.sharedLibs = findFiles("(bin|lib)[\\\\/].*\\.(so|dll|dylib)[0-9.]*", outdir) pkg.sharedLibs = findFiles("(bin|lib)[\\\\/].*\\.(so|dll|dylib)[0-9.]*", outdir)
for lib in findFiles("lib[\\\\/].*\\.(a|lib)$", outdir): for lib in findFiles("lib[\\\\/].*\\.(a|lib)", outdir):
if not lib.endsWith(".dll.a"): if not lib.endsWith(".dll.a"):
pkg.staticLibs.add lib pkg.staticLibs.add lib

View file

@ -414,22 +414,8 @@ proc findFiles*(file: string, dir: string, recurse = true, regex = false): seq[s
## ##
## Turn off recursive search with `recurse` ## Turn off recursive search with `recurse`
var var
cmd = cmd = "nimgrep --follow --filenames --oneline --nocolor $1 \"$2\" $3"
when defined(Windows): recursive = if recurse: "--recursive" else: ""
"nimgrep --filenames --oneline --nocolor $1 \"$2\" $3"
elif defined(linux):
"find $3 $1 -regextype egrep -regex $2"
elif defined(osx) or defined(FreeBSD):
"find -E $3 $1 -regex $2"
recursive = ""
if recurse:
when defined(Windows):
recursive = "--recursive"
else:
when not defined(Windows):
recursive = "-maxdepth 1"
var var
dir = dir dir = dir
@ -443,20 +429,17 @@ proc findFiles*(file: string, dir: string, recurse = true, regex = false): seq[s
file = file.extractFilename file = file.extractFilename
cmd = cmd % [recursive, (".*[\\\\/]" & file & "$").quoteShell, dir.sanitizePath] cmd = cmd % [recursive, (".*[\\\\/]" & file & "$"), dir.sanitizePath]
let let
(files, ret) = execAction(cmd, die = false) (files, ret) = execAction(cmd, die = false)
if ret == 0: if ret == 0:
for line in files.splitLines(): for line in files.splitLines():
let f = let f =
when defined(Windows):
if ": " in line: if ": " in line:
line.split(": ", maxsplit = 1)[1] line.split(": ", maxsplit = 1)[1]
else: else:
"" ""
else:
line
if f.len != 0: if f.len != 0:
result.add f result.add f