Skip to content

Commit a550b9a

Browse files
committed
build: Fix building for windows.
1 parent d7494a4 commit a550b9a

File tree

10 files changed

+35
-13
lines changed

10 files changed

+35
-13
lines changed

.github/workflows/tests.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ jobs:
4040
shell: bash
4141
run: |
4242
mkdir -p dockcross
43-
sudo docker run --rm dockcross/windows-x64 > dockcross-windows-x64
43+
sudo docker run --rm dockcross/windows-static-64-posix > dockcross-windows-x64
4444
cat dockcross-windows-x64
4545
chmod +x dockcross-windows-x64
46-
wget https://curl.haxx.se/download/curl-7.69.1.tar.gz
46+
wget https://curl.haxx.se/download/curl-7.76.0.tar.gz
4747
tar xzf curl-*
4848
CURL_SRC=curl-*
49-
./dockcross-windows-x64 bash -c 'cd '"$CURL_SRC"' && ./configure --prefix="/work/deps/curl" --host=x86_64-w64-mingw32.static --with-winssl --disable-dependency-tracking --disable-pthreads --disable-pthreads --enable-threaded-resolver'
49+
./dockcross-windows-x64 bash -c 'cd '"$CURL_SRC"' && ./configure --prefix="/work/deps/curl" --host=x86_64-w64-mingw32.static --with-winssl --disable-dependency-tracking --disable-pthreads --enable-threaded-resolver --disable-imap --disable-pop3 --disable-smpt --disable-ldap --disable-mqtt --disable-smb'
5050
./dockcross-windows-x64 bash -c 'cd '"$CURL_SRC"' && make'
5151
./dockcross-windows-x64 bash -c 'cd '"$CURL_SRC"' && make install'
5252
- name: Run Tests

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ clib-build
1212
clib-update
1313
clib-upgrade
1414
clib-uninstall
15+
*.exe
1516

1617
test/package/package-*
1718
!test/package/package-*.c

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ OBJS = $(DEPS:.c=.o)
2121

2222
export CC
2323

24-
CFLAGS += -std=c99 -U__STRICT_ANSI__ -Ideps -Isrc/common -Isrc/repository -Isrc/registry $(shell curl-config --cflags)
24+
CFLAGS += -std=c99 -U__STRICT_ANSI__ -Ideps -Isrc/common -Isrc/repository -Isrc/registry
2525
CFLAGS += -g -Wall -Werror=return-type -Wno-unused-function -Werror=implicit-function-declaration
2626

2727
ifdef STATIC

deps/strdup/strdup.c

+14-1
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88

99
#ifndef HAVE_STRDUP
1010

11+
#include "strdup.h"
1112
#include <stdlib.h>
1213
#include <string.h>
13-
#include "strdup.h"
1414

1515
#ifndef strdup
1616

@@ -30,6 +30,19 @@ strdup(const char *str) {
3030
return buf;
3131
}
3232

33+
char* strndup(const char *str, size_t len) {
34+
if (NULL == (char *) str) {
35+
return NULL;
36+
}
37+
38+
char *buf = malloc(len+1);
39+
40+
if (buf) {
41+
memset(buf, 0, len+1);
42+
memcpy(buf, str, len);
43+
}
44+
return buf;
45+
}
3346
#endif
3447

3548
#endif /* HAVE_STRDUP */

deps/strdup/strdup.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
* Returns a pointer to the newly allocated
1818
* copy of `str`, or `NULL` on failure.
1919
*/
20-
20+
#include <stddef.h>
2121
#ifndef strdup
22-
char *
23-
strdup(const char *str);
22+
char * strdup(const char *str);
23+
char * strndup(const char *str, size_t len);
2424
#endif
2525

2626
#endif /* HAVE_STRDUP */

scripts/feature-test-pthreads

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
echo '#include <pthread.h>' &&
55
echo 'void *f(void *a) { return 0; }' &&
66
echo 'int main(void) { pthread_t t; return pthread_create(&t, 0, f, 0); }';
7-
} | ${CC:-cc} -o /dev/null -xc -pthread - 2>/dev/null
7+
} | ${CC:-cc} -o pthread_test -xc -pthread - 2>/dev/null || rm pthread_test
88
exit $?

src/clib-search.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ int main(int argc, char *argv[]) {
182182
clib_secrets_t secrets = clib_secrets_load_from_file("clib_secrets.json");
183183

184184
clib_package_t *package = clib_package_load_local_manifest(0);
185-
registries_t registries = registry_manager_init_registries(package->registries, secrets);
185+
registries_t registries = registry_manager_init_registries(package ? package->registries : NULL, secrets);
186186
registry_manager_fetch_registries(registries);
187187

188188
// TODO, implement caching for the new registries.

src/common/clib-package-installer.c

+7
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@
2323
#include <limits.h>
2424
#include <strdup/strdup.h>
2525

26+
#if defined(_WIN32) || defined(WIN32) || defined(__MINGW32__) || \
27+
defined(__MINGW64__) || defined(__CYGWIN__)
28+
#define setenv(k, v, _) _putenv_s(k, v)
29+
#define realpath(a, b) _fullpath(a, b, strlen(a))
30+
#endif
31+
2632
CURLSH *clib_package_curl_share;
2733
//TODO, cleanup somewhere curl_share_cleanup(clib_package_curl_share);
2834

@@ -375,6 +381,7 @@ int clib_package_install(clib_package_t *pkg, const char *dir, int verbose) {
375381
_debug("mkdir -p %s", pkg_dir);
376382
// create directory for pkg
377383
if (-1 == mkdirp(pkg_dir, 0777)) {
384+
logger_error("error", "Could not create directory %s", pkg_dir);
378385
rc = -1;
379386
goto cleanup;
380387
}

src/registry/gitlab-registry.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
// MIT licensed
66
//
77
#include "gitlab-registry.h"
8-
#include "gumbo-get-element-by-id/get-element-by-id.h"
98
#include "http-get/http-get.h"
109
#include "registry-internal.h"
1110
#include <curl/curl.h>
1211
#include <string.h>
12+
#include <strdup/strdup.h>
1313

1414
/**
1515
* Parse a list of packages from the given `html`
@@ -19,9 +19,9 @@ static list_t *gitlab_registry_parse(const char *hostname, const char *html) {
1919

2020
// Try to parse the markdown file.
2121
char *input = strdup(html);
22-
char *line;
22+
char *line = input;
2323
char *category = NULL;
24-
while ((line = strsep(&input, "\n"))) {
24+
while ((line = strtok(line, "\n"))) {
2525
char *dash_position = strstr(line, "-");
2626
// The line starts with a dash, so we expect a package.
2727
if (dash_position != NULL && dash_position - line < 4) {

src/repository/repository.c

+1
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ static void *fetch_package_file_thread(void *arg) {
206206
int rc = fetch_package_file_work(data->url, data->dir, data->file, data->secret);
207207
*status = rc;
208208
pthread_exit((void *) status);
209+
return status;
209210
}
210211
#endif
211212

0 commit comments

Comments
 (0)