Skip to content

Commit

Permalink
ci: add Windows builds
Browse files Browse the repository at this point in the history
Add automated Windows builds and tests.

Use curl-for-win with llvm + mingw64, and a minimal libcurl build with
no external dependencies to build x64, ARM64 and x86 `trurl.exe`.

Boost build performance by not building the curl tool [EXPERIMENTAL].
Use a customized curl-for-win build with disabled TLS to further reduce
footprint and build time.

Non-UNITY libcurl builds can make turl binaries about 120KB smaller, but
they require 2x build times (4m vs. 2m), so opted not to use those here.

Also enable tests and fix issues along the way:
- libcurl with IDN support cannot be used because trurl itself lacks
  UNICODE support and thus fails to accept non-ASCII strings via the
  command-line.
  ```
  expected:
  'https://xn--rksmrgs-5wao1o.se/\n'
  got:
  ''
  104: failed 'https://räksmörgås.se' -g '{puny:host}'
  ```
  Ref: https://github.com/curl/trurl/actions/runs/6863796328/job/18664263891#step:3:4406
- add `test.py` support for a runner like `wine`.
  Via `--runner=<bin>`
  option. This disables `valgrind` tests.
- add `test.py` to override the default `trurl` binary to test.
  Via `--trurl=<bin>` option.
- skip `stderr` tests when using a runner.
  (`wine` does trash `stderr` output)
- fix to enable `punycode2idn` only when libcurl has IDN support.
- delete line-ending spaces from `test.json`.
- add `--keep-port` to 6 tests to avoid relying on libcurl builds with
  specific protocols enabled, such as HTTPS or FTP.
- add a new test with default-port using http/80.
- update 4 tests to use http/imap instead of https/imaps to make them
  work with no-TLS libcurl.
- build libcurl with IMAP to make 'options' URL field extraction work in
  tests.

Fixes #109
Closes #249
  • Loading branch information
vszakats committed Nov 14, 2023
1 parent c31f64f commit bc67bb6
Show file tree
Hide file tree
Showing 4 changed files with 155 additions and 53 deletions.
56 changes: 56 additions & 0 deletions .github/workflows/curl-for-win.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Copyright (C) Viktor Szakats. See LICENSE.md
# SPDX-License-Identifier: curl
---
name: curl-for-win

on:
push:
branches: ["master"]
pull_request:
branches: ["master"]

permissions: {}

env:
CW_GET: 'curl'
CW_MAP: '0'
CW_JOBS: '3'
CW_PKG_NODELETE: '1'
CW_PKG_FLATTEN: '1'
DOCKER_CONTENT_TRUST: '1'

jobs:
win-llvm:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
path: 'trurl'
fetch-depth: 8
- name: 'build'
env:
CW_LLVM_MINGW_DL: '1'
CW_LLVM_MINGW_ONLY: '0'
CW_TURL_TEST: '1'
run: |
git clone --depth 1 https://github.com/curl/curl-for-win
mv curl-for-win/* .
export CW_CONFIG='-dev-zero-imap-osnotls-osnoidn-nocurltool-win'
export CW_REVISION='${{ github.sha }}'
. ./_versions.sh
docker trust inspect --pretty "${DOCKER_IMAGE}"
time docker pull "${DOCKER_IMAGE}"
docker images --digests
time docker run --volume "$(pwd):$(pwd)" --workdir "$(pwd)" \
--env-file <(env | grep -a -E \
'^(CW_|GITHUB_)') \
"${DOCKER_IMAGE}" \
sh -c ./_ci-linux-debian.sh
- name: 'list dependencies'
run: cat urls.txt
- uses: actions/upload-artifact@v3
with:
name: 'trurl-windows'
retention-days: 5
path: curl-*-*-*/trurl*
79 changes: 50 additions & 29 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ def testComponent(value, exp):


class TestCase:
def __init__(self, testIndex, baseCmd, **testCase):
def __init__(self, testIndex, runnerCmd, baseCmd, **testCase):
self.testIndex = testIndex
self.runnerCmd = runnerCmd
self.baseCmd = baseCmd
self.arguments = testCase["input"]["arguments"]
self.expected = testCase["expected"]
Expand All @@ -74,7 +75,10 @@ def runCommand(self, cmdfilter: Optional[str], runWithValgrind: bool):

cmd = [self.baseCmd]
args = self.arguments
if runWithValgrind:
if self.runnerCmd != "":
cmd = [self.runnerCmd]
args = [self.baseCmd] + self.arguments
elif runWithValgrind:
cmd = [VALGRINDTEST]
args = VALGRINDARGS + [self.baseCmd] + self.arguments

Expand All @@ -96,6 +100,11 @@ def runCommand(self, cmdfilter: Optional[str], runWithValgrind: bool):
# assume stderr is always going to be string
stderr = output.stderr

# runners (e.g. wine) spill their own output into stderr,
# ignore stderr tests when using a runner.
if self.runnerCmd != "" and "stderr" in self.expected:
stderr = self.expected["stderr"]

self.commandOutput = CommandOutput(stdout, output.returncode, stderr)
return True

Expand Down Expand Up @@ -161,41 +170,53 @@ def main(argc, argv):
# the .exe on the end is necessary when using absolute paths
if sys.platform == "win32" or sys.platform == "cygwin":
baseCmd += ".exe"

with open(path.join(baseDir, TESTFILE), "r") as file:
allTests = json.load(file)
testIndexesToRun = []

# if argv[1] exists and starts with int
cmdfilter = ""
testIndexesToRun = list(range(len(allTests)))
runWithValgrind = False
verboseDetail = False
runnerCmd = ""

if argc > 1:
for arg in argv[1:]:
if arg[0].isnumeric():
# run only test cases separated by ","
testIndexesToRun = []

for caseIndex in arg.split(","):
testIndexesToRun.append(int(caseIndex))
elif arg == "--with-valgrind":
runWithValgrind = True
elif arg == "--verbose":
verboseDetail = True
elif arg.startswith("--trurl="):
baseCmd = arg[len("--trurl="):]
elif arg.startswith("--runner="):
runnerCmd = arg[len("--runner="):]
else:
cmdfilter = argv[1]

# check if the trurl executable exists
if path.isfile(baseCmd):
# get the version info for the feature list
args = ["--version"]
if runnerCmd != "":
cmd = [runnerCmd]
args = [baseCmd] + args
else:
cmd = [baseCmd]
output = run(
[baseCmd, "--version"],
cmd + args,
stdout=PIPE, stderr=PIPE,
encoding="utf-8"
)
features = output.stdout.split('\n')[1].split()[1:]

with open(path.join(baseDir, TESTFILE), "r") as file:
allTests = json.load(file)
testIndexesToRun = []

# if argv[1] exists and starts with int
cmdfilter = ""
testIndexesToRun = list(range(len(allTests)))
runWithValgrind = False
verboseDetail = False

if argc > 1:
for arg in argv[1:]:
if arg[0].isnumeric():
# run only test cases separated by ","
testIndexesToRun = []

for caseIndex in arg.split(","):
testIndexesToRun.append(int(caseIndex))
elif arg == "--with-valgrind":
runWithValgrind = True
elif arg == "--verbose":
verboseDetail = True
else:
cmdfilter = argv[1]

numTestsFailed = 0
numTestsPassed = 0
numTestsSkipped = 0
Expand All @@ -208,7 +229,7 @@ def main(argc, argv):
numTestsSkipped += 1
continue

test = TestCase(testIndex + 1, baseCmd, **allTests[testIndex])
test = TestCase(testIndex + 1, runnerCmd, baseCmd, **allTests[testIndex])

if test.runCommand(cmdfilter, runWithValgrind):
if test.test(): # passed
Expand Down
54 changes: 37 additions & 17 deletions tests.json
Original file line number Diff line number Diff line change
Expand Up @@ -260,20 +260,36 @@
{
"input": {
"arguments": [
"http://curl.se:22/",
"-s",
"port=80"
]
},
"expected": {
"stdout": "http://curl.se/\n",
"stderr": "",
"returncode": 0
}
},
{
"input": {
"arguments": [
"--keep-port",
"https://curl.se:22/",
"-s",
"port=443"
]
},
"expected": {
"stdout": "https://curl.se/\n",
"stdout": "https://curl.se:443/\n",
"stderr": "",
"returncode": 0
}
},
{
"input": {
"arguments": [
"--keep-port",
"https://curl.se:22/",
"-s",
"port=443",
Expand All @@ -282,7 +298,7 @@
]
},
"expected": {
"stdout": "https://curl.se/\n",
"stdout": "https://curl.se:443/\n",
"stderr": "",
"returncode": 0
}
Expand All @@ -307,13 +323,13 @@
"arguments": [
"--default-port",
"--url",
"https://curl.se/we/are.html",
"http://curl.se/we/are.html",
"--get",
"{port}"
]
},
"expected": {
"stdout": "443\n",
"stdout": "80\n",
"stderr": "",
"returncode": 0
}
Expand Down Expand Up @@ -489,13 +505,13 @@
"input": {
"arguments": [
"--url",
"https://curl.se/we/are.html",
"http://curl.se/we/are.html",
"-g",
"{default:port}"
]
},
"expected": {
"stdout": "443\n",
"stdout": "80\n",
"stderr": "",
"returncode": 0
}
Expand Down Expand Up @@ -846,23 +862,25 @@
{
"input": {
"arguments": [
"--keep-port",
"https://hello:443/foo"
]
},
"expected": {
"stdout": "https://hello/foo\n",
"stdout": "https://hello:443/foo\n",
"stderr": "",
"returncode": 0
}
},
{
"input": {
"arguments": [
"--keep-port",
"ftp://hello:21/foo"
]
},
"expected": {
"stdout": "ftp://hello/foo\n",
"stdout": "ftp://hello:21/foo\n",
"stderr": "",
"returncode": 0
}
Expand All @@ -884,13 +902,14 @@
{
"input": {
"arguments": [
"--keep-port",
"ftp://hello:443/foo",
"-s",
"scheme=https"
]
},
"expected": {
"stdout": "https://hello/foo\n",
"stdout": "https://hello:443/foo\n",
"stderr": "",
"returncode": 0
}
Expand Down Expand Up @@ -1191,6 +1210,7 @@
{
"input": {
"arguments": [
"--keep-port",
"https://curl.se",
"--iterate",
"port=80 81 443"
Expand All @@ -1199,7 +1219,7 @@
"expected": {
"stderr": "",
"returncode": 0,
"stdout": "https://curl.se:80/\nhttps://curl.se:81/\nhttps://curl.se/\n"
"stdout": "https://curl.se:80/\nhttps://curl.se:81/\nhttps://curl.se:443/\n"
}
},
{
Expand Down Expand Up @@ -1656,17 +1676,17 @@
{
"input": {
"arguments": [
"imaps://user:password;crazy@[ff00::1234%hello]:1234/path?a=b&c=d#fragment",
"imap://user:password;crazy@[ff00::1234%hello]:1234/path?a=b&c=d#fragment",
"--json"
]
},
"expected": {
"returncode": 0,
"stdout": [
{
"url": "imaps://user:password;crazy@[ff00::1234%25hello]:1234/path?a=b&c=d#fragment",
"url": "imap://user:password;crazy@[ff00::1234%25hello]:1234/path?a=b&c=d#fragment",
"parts": {
"scheme": "imaps",
"scheme": "imap",
"user": "user",
"password": "password",
"options": "crazy",
Expand Down Expand Up @@ -2014,7 +2034,7 @@
"returncode": 0,
"stderr": ""
}
},
},
{
"input" : {
"arguments": [
Expand All @@ -2040,7 +2060,7 @@
}
]
}
]
]
}
},
{
Expand Down Expand Up @@ -2068,7 +2088,7 @@
}
]
}
]
]
}
},
{
Expand Down Expand Up @@ -2096,7 +2116,7 @@
}
]
}
]
]
}
},
{
Expand Down
Loading

0 comments on commit bc67bb6

Please sign in to comment.