Created
January 21, 2021 12:42
-
-
Save drygdryg/a04e1560ad12377a4964deca18a0dc20 to your computer and use it in GitHub Desktop.
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
from macros import error, hint | |
from os import `/`, splitFile | |
import strutils | |
import distros | |
when defined(release): | |
switch("checks", "off") | |
switch("assertions", "off") | |
switch("debuginfo", "off") | |
switch("stackTrace", "off") | |
switch("lineTrace", "off") | |
when defined(musl): | |
when not defined(Linux): | |
error("Statically linking with musl is only avaliable on Linux") | |
var muslGccPath: string | |
hint("[-d:musl] building a static binary using musl") | |
muslGccPath = findExe("musl-gcc") | |
# echo "debug: " & muslGccPath | |
if muslGccPath == "": | |
if detectOs(ArchLinux): | |
foreignDep "musl" | |
error("'musl-gcc' binary was not found in PATH") | |
putEnv("CC", "musl-gcc -static -idirafter /usr/include/ -idirafter /usr/include/x86_64-linux-gnu/") | |
when defined(openssl): | |
hint("OpenSSL TLS implementation used") | |
let | |
openSslVersion = getEnv("OPENSSLVER", "1.1.1i") | |
openSslSourceDir = "openssl-" & openSslVersion | |
openSslArchiveFile = openSslSourceDir & ".tar.gz" | |
openSslDownloadLink = "https://www.openssl.org/source/" & openSslArchiveFile | |
openSslInstallDir = (thisDir() / "openssl/") & openSslVersion | |
openSslConfigureCmd = ["./config", "no-shared", "no-zlib", "no-async", | |
"no-tests", "-fPIC", "-DOPENSSL_NO_SECURE_MEMORY", "--prefix=" & openSslInstallDir] | |
sslLibDir = openSslInstallDir / "lib" | |
openSslLibFile = sslLibDir / "libssl.a" | |
openCryptoLibFile = sslLibDir / "libcrypto.a" | |
sslIncludeDir = openSslInstallDir / "include/openssl" | |
# Build OpenSSL with musl if doesn't exist | |
if (not fileExists(openSslLibFile)) or (not fileExists(openCryptoLibFile)): | |
if not dirExists(openSslSourceDir): | |
if not fileExists(openSslArchiveFile): | |
exec("curl -LO " & openSslDownloadLink) | |
exec("tar xf " & openSslArchiveFile) | |
exec("rm " & openSslArchiveFile) | |
else: | |
hint("OpenSSL lib source dir " & openSslSourceDir & " already exists") | |
withDir openSslSourceDir: | |
exec(openSslConfigureCmd.join(" ")) | |
putEnv("C_INCLUDE_PATH", sslIncludeDir) | |
hint("The insecure switch -DOPENSSL_NO_SECURE_MEMORY is needed so that OpenSSL can be compiled using MUSL.") | |
exec("make -j`nproc --all` depend") | |
exec("make -j`nproc --all`") | |
exec("make install_sw") | |
else: | |
hint(openSslLibFile & " already exists") | |
switch("passL", "-lssl") | |
switch("passL", "-lcrypto") | |
else: | |
hint("wolfSSL TLS implementation used") | |
let | |
wolfSslVersion = getEnv("WOLFSSLVER", "4.6.0") | |
wolfSslSourceDir = "wolfssl-" & wolfSslVersion & "-stable" | |
wolfSslArchiveFile = "v" & wolfSslVersion & "-stable.tar.gz" | |
wolfSslDownloadLink = "https://github.com/wolfSSL/wolfssl/archive/" & wolfSslArchiveFile | |
wolfSslInstallDir = (thisDir() / "wolfssl/") & wolfSslVersion | |
wolfSslConfigureCmd = ["./configure ", "--enable-static", | |
"--enable-opensslextra", "--prefix=" & wolfSslInstallDir] | |
sslLibDir = wolfSslInstallDir / "lib" | |
wolfSslLibFile = sslLibDir / "libwolfssl.a" | |
sslIncludeDir = wolfSslInstallDir / "include/wolfssl" | |
if not fileExists(wolfSslLibFile): | |
if not dirExists(wolfSslSourceDir): | |
if not fileExists(wolfSslArchiveFile): | |
exec("curl -LO " & wolfSslDownloadLink) | |
exec("tar xf " & wolfSslArchiveFile) | |
exec("rm " & wolfSslArchiveFile) | |
else: | |
hint("wolfSSL lib source dir " & wolfSslSourceDir & " already exists") | |
withDir wolfSslSourceDir: | |
exec("./autogen.sh") | |
exec(wolfSslConfigureCmd.join(" ")) | |
putEnv("C_INCLUDE_PATH", sslIncludeDir) | |
exec("make -j`nproc --all`") | |
exec("make install") | |
else: | |
hint(wolfSslLibFile & " already exists") | |
switch("passL", "-lwolfssl") | |
switch("passC", "-I" & sslIncludeDir) # So that ssl.h is found when running the musl task | |
switch("passL", "-L" & sslLibDir) | |
switch("dynlibOverride", "ssl") | |
switch("dynlibOverride", "crypto") | |
switch("gcc.exe", muslGccPath) | |
switch("gcc.linkerexe", muslGccPath) | |
switch("passL", "-static") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment