Skip to content

Commit 07ea71e

Browse files
committed
Add Windows support and improve CI coverage handling
- Add Windows endian compatibility to fastpbkdf2_wrapper - Define Windows-specific endian macros (always little-endian on x86/x64) - Prevent endian.h include on Windows using __GNUC__ technique - Update coverage job to run even if some test matrix jobs fail - This should resolve Windows compilation issues while maintaining cross-platform compatibility
1 parent b5ad714 commit 07ea71e

File tree

4 files changed

+94
-32
lines changed

4 files changed

+94
-32
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ jobs:
7474
coverage:
7575
runs-on: ubuntu-latest
7676
needs: test
77+
if: always() # Run even if some test jobs fail
7778

7879
steps:
7980
- uses: actions/checkout@v4
@@ -83,6 +84,7 @@ jobs:
8384
with:
8485
name: coverage-report
8586
path: coverage/
87+
continue-on-error: true # In case no coverage artifact was uploaded
8688

8789
- name: Upload coverage to Qlty
8890
uses: qltysh/qlty-action/coverage@v1

ext/fastpbkdf2/endian.h

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* endian.h - Cross-platform endian compatibility header
3+
*
4+
* This file provides endian.h compatibility for platforms that don't have it
5+
* (like Windows and macOS). It gets included by fastpbkdf2.c when __GNUC__ is defined.
6+
*/
7+
8+
#ifndef FASTPBKDF2_ENDIAN_H
9+
#define FASTPBKDF2_ENDIAN_H
10+
11+
#ifdef __APPLE__
12+
/* macOS approach: use system headers to define endian macros */
13+
#include <machine/endian.h>
14+
#include <libkern/OSByteOrder.h>
15+
16+
/* Define the Linux-style endian macros that fastpbkdf2.c expects */
17+
#ifndef __BYTE_ORDER
18+
#define __BYTE_ORDER BYTE_ORDER
19+
#endif
20+
#ifndef __LITTLE_ENDIAN
21+
#define __LITTLE_ENDIAN LITTLE_ENDIAN
22+
#endif
23+
#ifndef __BIG_ENDIAN
24+
#define __BIG_ENDIAN BIG_ENDIAN
25+
#endif
26+
27+
#elif defined(_WIN32)
28+
/* Windows doesn't have endian.h, but it's always little-endian on x86/x64 */
29+
#ifndef __BYTE_ORDER
30+
#define __BYTE_ORDER 1234
31+
#endif
32+
#ifndef __LITTLE_ENDIAN
33+
#define __LITTLE_ENDIAN 1234
34+
#endif
35+
#ifndef __BIG_ENDIAN
36+
#define __BIG_ENDIAN 4321
37+
#endif
38+
39+
#else
40+
/* Linux and other Unix systems - include the real system endian.h */
41+
#if __has_include(<endian.h>)
42+
#include_next <endian.h>
43+
#elif __has_include(<sys/endian.h>)
44+
#include <sys/endian.h>
45+
#else
46+
/* Fallback definitions for systems without endian headers */
47+
#ifndef __BYTE_ORDER
48+
#ifdef __BYTE_ORDER__
49+
#define __BYTE_ORDER __BYTE_ORDER__
50+
#else
51+
#define __BYTE_ORDER 1234 /* Assume little-endian */
52+
#endif
53+
#endif
54+
#ifndef __LITTLE_ENDIAN
55+
#ifdef __ORDER_LITTLE_ENDIAN__
56+
#define __LITTLE_ENDIAN __ORDER_LITTLE_ENDIAN__
57+
#else
58+
#define __LITTLE_ENDIAN 1234
59+
#endif
60+
#endif
61+
#ifndef __BIG_ENDIAN
62+
#ifdef __ORDER_BIG_ENDIAN__
63+
#define __BIG_ENDIAN __ORDER_BIG_ENDIAN__
64+
#else
65+
#define __BIG_ENDIAN 4321
66+
#endif
67+
#endif
68+
#endif
69+
#endif
70+
71+
#endif /* FASTPBKDF2_ENDIAN_H */

ext/fastpbkdf2/fastpbkdf2_wrapper.c

Lines changed: 6 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,37 +5,12 @@
55
* without modifying the upstream source files.
66
*/
77

8-
/* Set up platform-specific environment before including fastpbkdf2.c */
9-
#ifdef __APPLE__
10-
/* On macOS, we need to provide the endian.h functionality */
11-
#include <machine/endian.h>
12-
#include <libkern/OSByteOrder.h>
13-
14-
/* Define the Linux-style endian macros that fastpbkdf2.c expects */
15-
#ifndef __BYTE_ORDER
16-
#define __BYTE_ORDER BYTE_ORDER
17-
#endif
18-
#ifndef __LITTLE_ENDIAN
19-
#define __LITTLE_ENDIAN LITTLE_ENDIAN
20-
#endif
21-
#ifndef __BIG_ENDIAN
22-
#define __BIG_ENDIAN BIG_ENDIAN
23-
#endif
24-
25-
/* Redefine __GNUC__ temporarily to prevent endian.h include in fastpbkdf2.c */
26-
#ifdef __GNUC__
27-
#define __FASTPBKDF2_SAVED_GNUC__ __GNUC__
28-
#undef __GNUC__
29-
#endif
30-
#endif
8+
/*
9+
* fastpbkdf2_wrapper.c - Cross-platform wrapper for fastpbkdf2.c
10+
*
11+
* This wrapper includes fastpbkdf2.c with cross-platform endian compatibility.
12+
* The local endian.h file handles platform differences automatically.
13+
*/
3114

3215
/* Now include the actual fastpbkdf2.c implementation */
3316
#include "../../vendor/fastpbkdf2/fastpbkdf2.c"
34-
35-
#ifdef __APPLE__
36-
/* Restore __GNUC__ if it was defined */
37-
#ifdef __FASTPBKDF2_SAVED_GNUC__
38-
#define __GNUC__ __FASTPBKDF2_SAVED_GNUC__
39-
#undef __FASTPBKDF2_SAVED_GNUC__
40-
#endif
41-
#endif

ext/fastpbkdf2/fastpbkdf2_wrapper.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#ifndef FASTPBKDF2_WRAPPER_H
99
#define FASTPBKDF2_WRAPPER_H
1010

11-
/* macOS/Apple platform compatibility fixes */
11+
/* Platform-specific compatibility fixes */
1212
#ifdef __APPLE__
1313
/* On macOS, we have __GNUC__ but don't want to use the GCC-specific
1414
* endian.h and __BYTE_ORDER checks. Let's define the endian macros
@@ -28,6 +28,20 @@
2828
#endif
2929
#endif
3030

31+
/* Windows platform compatibility fixes */
32+
#ifdef _WIN32
33+
/* Windows doesn't have endian.h, but it's always little-endian on x86/x64 */
34+
#ifndef __BYTE_ORDER
35+
#define __BYTE_ORDER 1234
36+
#endif
37+
#ifndef __LITTLE_ENDIAN
38+
#define __LITTLE_ENDIAN 1234
39+
#endif
40+
#ifndef __BIG_ENDIAN
41+
#define __BIG_ENDIAN 4321
42+
#endif
43+
#endif
44+
3145
/* Include the actual fastpbkdf2 header */
3246
#include "../../vendor/fastpbkdf2/fastpbkdf2.h"
3347

0 commit comments

Comments
 (0)