diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d4081f3..ff1f2f7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 @@ -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 }} @@ -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 @@ -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 * diff --git a/.gitignore b/.gitignore index ff9d93b..c805909 100644 --- a/.gitignore +++ b/.gitignore @@ -17,6 +17,7 @@ bin/ # DUB .dub +dub.*.json docs.json __dummy.html docs/ diff --git a/dub.json b/dub.json index 5186ba0..1a95c0d 100644 --- a/dub.json +++ b/dub.json @@ -7,6 +7,9 @@ "authors": [ "Matheus Catarino França" ], + "dependencies": { + "requests": "~>2.2.0" + }, "dflags": [ "-preview=dip1000", "-preview=dip1008", @@ -44,4 +47,4 @@ ] } } -} \ No newline at end of file +} diff --git a/source/impl.d b/source/impl.d index cbcd193..fdfe69d 100644 --- a/source/impl.d +++ b/source/impl.d @@ -1,5 +1,7 @@ module impl; +import requests; + public import std; enum OS : string @@ -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) @@ -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("tag:github.com,2008:Grit::Commit/")[1].split( - "")[0][0 .. 8].to!string : response.to!string.strip; + "")[0][0 .. 8].to!string : response.strip; log("Resolved %s version: ldc2-%s", releaseType, dversion); return "ldc2-" ~ dversion; } @@ -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["); @@ -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 @@ -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; }