Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,26 @@ jobs:
with:
compiler: ldc-latest
- uses: ilammy/msvc-dev-cmd@v1
if: matrix.os == 'windows-11-arm'
if: runner.os == 'Windows'
with:
arch: amd64_${{ matrix.arch }}
arch: ${{ matrix.arch }}
- name: Set CURL_CA_BUNDLE for Windows
if: runner.os == 'Windows'
shell: pwsh
run: |
Invoke-WebRequest -Uri https://curl.se/ca/cacert.pem -OutFile curl-ca-bundle.crt
echo "CURL_CA_BUNDLE=$($PWD.Path)\curl-ca-bundle.crt" >> $env:GITHUB_ENV
- name: Set DUB_ARCH for windows-11-arm
if: matrix.os == 'windows-11-arm'
shell: bash
run: |
echo "DUB_ARCH=--arch=arm64-windows-msvc" >> $GITHUB_ENV
echo "CC=cl.exe" >> $GITHUB_ENV
echo "CXX=cl.exe" >> $GITHUB_ENV
echo "CXX=cl.exe" >> $GITHUB_ENV
- name: Build
run: |
dub -b release ${{ env.DUB_ARCH }}
- name: Tests
if: matrix.os != 'windows-11-arm'
run: |
dub -b release ${{ env.DUB_ARCH }} -- install -v
dub -b release ${{ env.DUB_ARCH }} -- install ldc2-master -v
Expand Down Expand Up @@ -99,16 +104,16 @@ jobs:
dub -b release -- uninstall ldc2-1.41.0 -v
dub -b release -- list -v
dub -b release -- run -v -- --version
tar -cJf bin/ldcup-freebsd14.2-${{ matrix.arch }}.tar.xz -C bin .
tar -cJf bin/ldcup-freebsd14.3-${{ matrix.arch }}.tar.xz -C bin .
- uses: actions/upload-artifact@v4
if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/')
with:
name: ldcup-freebsd-14.2-amd64
path: bin/ldcup-freebsd14.2-${{ matrix.arch }}.tar.xz
name: ldcup-freebsd-14.3-amd64
path: bin/ldcup-freebsd14.3-${{ matrix.arch }}.tar.xz
- uses: softprops/action-gh-release@v2
if: startsWith(github.ref, 'refs/tags/')
with:
files: 'bin/ldcup-freebsd14.2-${{ matrix.arch }}.tar.xz'
files: 'bin/ldcup-freebsd14.3-${{ matrix.arch }}.tar.xz'
prerelease: true
token: ${{ secrets.GITHUB_TOKEN }}

Expand All @@ -130,6 +135,9 @@ jobs:
run: |
apk update
apk add --no-cache ldc dub clang xz
- name: "Build Flags environment"
run: |
echo "LDFLAGS=-static" >> $GITHUB_ENV
- name: Build
run: |
dub -b release
Expand All @@ -141,7 +149,6 @@ jobs:
source $HOME/.profile
dub -b release -- install redub -v
dub -b release -- run -v -- --version
redub --version
- name: Compress artifacts
run: |
cd bin && tar -cJf ldcup-alpine-${{ matrix.arch }}.tar.xz *
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ bin/

# DUB
.dub
dub.*.json
docs.json
__dummy.html
docs/
Expand Down
5 changes: 4 additions & 1 deletion dub.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
"authors": [
"Matheus Catarino França"
],
"dependencies": {
"requests": "~>2.2.0"
},
"dflags": [
"-preview=dip1000",
"-preview=dip1008",
Expand Down Expand Up @@ -44,4 +47,4 @@
]
}
}
}
}
77 changes: 44 additions & 33 deletions source/impl.d
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module impl;

import requests;

public import std;

enum OS : string
Expand Down Expand Up @@ -147,7 +149,8 @@ public:
auto rootPath = environment.get("LDC2_PATH", compilerPath);
log("Installing redub to %s", rootPath);

version (AArch64) currentArch = Arch.arm64;
version (AArch64)
currentArch = Arch.arm64;

string redubFile;
if (currentOS == OS.freebsd)
Expand Down Expand Up @@ -502,10 +505,17 @@ public:

try
{
auto response = get(url);
auto rq = Request();
version (Windows)
rq.sslSetCaCert(environment.get("CURL_CA_BUNDLE"));
else
rq.sslSetVerifyPeer(false);
auto res = rq.get(url);
enforce(res.code / 100 == 2, format("HTTP request returned status code %s", res.code));
string response = cast(string) res.responseBody.data;
string dversion = releaseType == ReleaseType.nightly ?
response.split("<id>tag:github.com,2008:Grit::Commit/")[1].split(
"</id>")[0][0 .. 8].to!string : response.to!string.strip;
"</id>")[0][0 .. 8].to!string : response.strip;
log("Resolved %s version: ldc2-%s", releaseType, dversion);
return "ldc2-" ~ dversion;
}
Expand Down Expand Up @@ -538,26 +548,30 @@ public:
throw new Exception("Unknown compiler: %s".format(compilerSpec));
}

private void download(ref string url, string fileName) @trusted
private void download(string url, string fileName) @trusted
{
log("Downloading from URL: " ~ url);
auto buf = appender!(ubyte[])();
size_t contentLength;

auto http = HTTP(url); // unsafe/@system (need libcurl)
http.method = HTTP.Method.get;
http.onReceiveHeader((in k, in v) {
if (k == "content-length")
contentLength = to!size_t(v);
});
auto rq = Request();
rq.useStreaming = true;
version (Windows)
rq.sslSetCaCert(environment.get("CURL_CA_BUNDLE"));
else
rq.sslSetVerifyPeer(false);
auto res = rq.get(url);
enforce(res.code / 100 == 2, format("HTTP request returned status code %s", res.code));
size_t contentLength = res.contentLength;

// Progress bar
auto file = File(fileName, "wb");
size_t received = 0;
int barWidth = 50;
http.onReceive((data) {
buf.put(data);

foreach (ubyte[] data; res.receiveAsRange())
{
file.rawWrite(data);
received += data.length;
if (contentLength > 0)
{
float progress = cast(float) buf.data.length / contentLength;
float progress = cast(float) received / contentLength;
int pos = cast(int)(barWidth * progress);

write("\r[");
Expand All @@ -570,23 +584,13 @@ public:
else
write(" ");
}

writef("] %d%%", cast(int)(progress * 100));
stdout.flush();
}
return data.length;
});

http.dataTimeout = dur!"msecs"(0);
http.perform();
immutable sc = http.statusLine().code;
enforce(sc / 100 == 2 || sc == 302,
format("HTTP request returned status code %s", sc));
log("\nDownload complete");

auto file = File(fileName, "wb");
scope (success)
file.close();
file.rawWrite(buf.data);
}
writeln();
log("Download complete");
}

void downloadAndExtract(string url, string targetPath) @safe
Expand Down Expand Up @@ -661,14 +665,21 @@ public:
int page = 1;
while (true)
{
auto response = get(format("%s?per_page=100&page=%s", baseURL, page++));
auto json = parseJSON(response).array;
auto rq = Request();
version (Windows)
rq.sslSetCaCert(environment.get("CURL_CA_BUNDLE"));
else
rq.sslSetVerifyPeer(false);
auto res = rq.get(format("%s?per_page=100&page=%s", baseURL, page++));
enforce(res.code / 100 == 2, format("HTTP request returned status code %s", res.code));
auto json = parseJSON(cast(string) res.responseBody.data).array;
if (json.empty)
break;
results ~= json;
if (json.length < 100)
break;
}

return results;
}

Expand Down