Skip to content

Commit

Permalink
refactor: Use lower case file names on Windows (#3855)
Browse files Browse the repository at this point in the history
* Convert Windows header names to lower case
File systems on Windows are case-insensitive, but when cross compiling on Linux
all files provided by e.g. mingw are provided in lower case.

* Include windows.h after declaring `WIN32_LEAN_AND_MEAN`

* Use lower case Windows library names
File systems on Windows are case-insensitive, but when cross compiling on Linux
all files provided by e.g. mingw are provided in lower case.

* Use lower case names in @link annotations for Windows
  • Loading branch information
avdv committed Mar 30, 2024
1 parent 61dfa12 commit 3ca9233
Show file tree
Hide file tree
Showing 42 changed files with 59 additions and 60 deletions.
2 changes: 1 addition & 1 deletion javalib/src/main/resources/scala-native/time_millis.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <time.h>
#if defined(_WIN32)
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#include <windows.h>
#include "win_freq.h"
#else
#include <stdio.h>
Expand Down
2 changes: 1 addition & 1 deletion javalib/src/main/resources/scala-native/time_nano.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#if defined(_WIN32)
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#include <windows.h>
#include "win_freq.h"
#else
#include <time.h>
Expand Down
2 changes: 1 addition & 1 deletion javalib/src/main/resources/scala-native/win_freq.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#if defined(_WIN32)
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#include <windows.h>
#include "win_freq.h"

static int winFreqQuadPartValue = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <time.h>
#if defined(_WIN32)
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#include <windows.h>

static int winFreqQuadPartValue = 0;
static int winFreqQuadPart(int *quad) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
*/

#if defined(_WIN32)
#include <Windows.h>
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#elif defined(__unix__) || defined(__unix) || defined(unix) || \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
// Boehm on Windows needs User32.lib linked
#pragma comment(lib, "User32.lib")
#pragma comment(lib, "Kernel32.lib")
#pragma comment(lib, "user32.lib")
#pragma comment(lib, "kernel32.lib")
#include <windows.h>
typedef DWORD ThreadRoutineReturnType;
#else
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#include <windows.h>
#else
#include <sys/utsname.h>
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#if defined(_WIN32)

#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#include <DbgHelp.h>
#include <windows.h>
#include <dbghelp.h>
#include <stdio.h>
#include "../unwind.h"

Expand Down
4 changes: 2 additions & 2 deletions posixlib/src/main/resources/scala-native/arpa/inet.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#define _WINSOCK_DEPRECATED_NO_WARNINGS
#pragma comment(lib, "Ws2_32.lib")
#include <WinSock2.h>
#pragma comment(lib, "ws2_32.lib")
#include <winsock2.h>
#else
#include <arpa/inet.h>
#endif
Expand Down
12 changes: 6 additions & 6 deletions posixlib/src/main/resources/scala-native/net/if.c
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#if defined(SCALANATIVE_COMPILE_ALWAYS) || defined(__SCALANATIVE_POSIX_NET_IF)
#ifdef _WIN32
#include <WinSock2.h>
#pragma comment(lib, "Ws2_32.lib")
#include <Netioapi.h>
#include <Iphlpapi.h>
#pragma comment(lib, "Iphlpapi.lib")
#include <winsock2.h>
#pragma comment(lib, "ws2_32.lib")
#include <netioapi.h>
#include <iphlpapi.h>
#pragma comment(lib, "iphlpapi.lib")
#else
#include <net/if.h>

Expand Down Expand Up @@ -50,4 +50,4 @@ _Static_assert(offsetof(struct scalanative_if_nameindex, if_name) ==
* buffer overrun defects.
*/
int scalanative_if_namesize() { return IF_NAMESIZE + 1; }
#endif
#endif
4 changes: 2 additions & 2 deletions posixlib/src/main/resources/scala-native/netdb.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#if defined(SCALANATIVE_COMPILE_ALWAYS) || defined(__SCALANATIVE_POSIX_NETDB)
#ifdef _WIN32
#include <WinSock2.h>
#include <winsock2.h>
#include <ws2tcpip.h> // socklen_t
// #include <Winerror.h>
// #include <winerror.h>
#else // not _WIN32
/* FreeBSD wants AF_INET, which is in <sys/socket.h>
*
Expand Down
6 changes: 3 additions & 3 deletions posixlib/src/main/resources/scala-native/netinet/in.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#define WINSOCK_DEPRECATED_NO_WARNINGS
#pragma comment(lib, "Ws2_32.lib")
#include <WinSock2.h>
#include <WS2tcpip.h>
#pragma comment(lib, "ws2_32.lib")
#include <winsock2.h>
#include <ws2tcpip.h>
typedef uint32_t in_addr_t;
typedef uint16_t in_port_t;
#else
Expand Down
2 changes: 1 addition & 1 deletion posixlib/src/main/resources/scala-native/netinet/tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
defined(__SCALANATIVE_POSIX_NETINET_TCP)
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#include <WinSock2.h>
#include <winsock2.h>
#else
#ifdef __OpenBSD__
#include <sys/types.h>
Expand Down
2 changes: 1 addition & 1 deletion posixlib/src/main/resources/scala-native/sys/ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#include <winsock2.h>
#pragma comment(lib, "Ws2_32.lib")
#pragma comment(lib, "ws2_32.lib")
#else
#include <sys/ioctl.h>
#endif
Expand Down
4 changes: 2 additions & 2 deletions posixlib/src/main/resources/scala-native/sys/select.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
#include <string.h>

#ifdef _WIN32
#pragma comment(lib, "Ws2_32.lib")
#include <WinSock2.h>
#pragma comment(lib, "ws2_32.lib")
#include <winsock2.h>
typedef long int suseconds_t;
#else
#include <sys/select.h>
Expand Down
4 changes: 2 additions & 2 deletions posixlib/src/main/resources/scala-native/sys/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
#include <ws2tcpip.h>
#endif
#ifdef _WIN32
#include <WinSock2.h>
#pragma comment(lib, "Ws2_32.lib")
#include <winsock2.h>
#pragma comment(lib, "ws2_32.lib")
typedef SSIZE_T ssize_t;
#else
#if defined(__FreeBSD__)
Expand Down
2 changes: 1 addition & 1 deletion scripted-tests/run/build-library-static/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def compileAndTest(
outFile: File
): Unit = {
val platformLibs =
if (Platform.isWindows) Seq("Advapi32", "Userenv", "Dbghelp")
if (Platform.isWindows) Seq("advapi32", "userenv", "dbghelp")
else Seq("pthread", "dl")
val cmd: Seq[String] =
Seq(
Expand Down
2 changes: 1 addition & 1 deletion tools/src/main/scala/scala/scalanative/build/LLVM.scala
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ private[scalanative] object LLVM {
// * libpthread for process APIs and parallel garbage collection.
// * Dbghelp for windows implementation of unwind libunwind API
val platformsLinks =
if (config.targetsWindows) Seq("Dbghelp")
if (config.targetsWindows) Seq("dbghelp")
else if (config.targetsOpenBSD || config.targetsNetBSD)
Seq("pthread")
else Seq("pthread", "dl")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#if defined(_WIN32) || defined(WIN32)
#define WIN32_LEAN_AND_MEAN
#include <AccCtrl.h>
#include <accctrl.h>

int scalanative_not_used_access() { return NOT_USED_ACCESS; }
int scalanative_grant_access() { return GRANT_ACCESS; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#if (defined(_WIN32) || defined(WIN32)) && !defined(__MINGW64__)
#define WIN32_LEAN_AND_MEAN
#include <AccCtrl.h>
#include <accctrl.h>

int scalanative_se_unknown_object_type() { return SE_UNKNOWN_OBJECT_TYPE; }
int scalanative_se_file_object() { return SE_FILE_OBJECT; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#if defined(_WIN32) || defined(WIN32)
#define WIN32_LEAN_AND_MEAN
#include <AccCtrl.h>
#include <accctrl.h>

int scalanative_trustee_is_sid() { return TRUSTEE_IS_SID; }
int scalanative_trustee_is_name() { return TRUSTEE_IS_NAME; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#if defined(_WIN32) || defined(WIN32)
#define WIN32_LEAN_AND_MEAN
#include <AccCtrl.h>
#include <accctrl.h>

int scalanative_trustee_is_unknown() { return TRUSTEE_IS_UNKNOWN; }
int scalanative_trustee_is_user() { return TRUSTEE_IS_USER; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#if defined(_WIN32) || defined(WIN32)
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#include <windows.h>

DWORD scalanative_std_input_handle() { return STD_INPUT_HANDLE; }
DWORD scalanative_std_output_handle() { return STD_OUTPUT_HANDLE; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#if defined(_WIN32) || defined(WIN32)
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#include <windows.h>

// Needed to find symbols from UCRT - Windows Universal C Runtime
#pragma comment(lib, "legacy_stdio_definitions.lib")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#if defined(_WIN32) || defined(WIN32)
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <Winbase.h>
#include <winbase.h>

DWORD scalanative_file_map_all_access() { return FILE_MAP_ALL_ACCESS; }
DWORD scalanative_file_map_read() { return FILE_MAP_READ; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#if defined(_WIN32) || defined(WIN32)
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#include <windows.h>

DWORD scalanative_securityanonymous() { return SecurityAnonymous; }
DWORD scalanative_securityidentification() { return SecurityIdentification; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#if defined(_WIN32) || defined(WIN32)
#define WIN32_LEAN_AND_MEAN
#include "Windows.h"
#include "windows.h"
#include <winsock2.h>

#pragma comment(lib, "Ws2_32.lib")
#pragma comment(lib, "ws2_32.lib")

SOCKET scalanative_winsock_invalid_socket() { return INVALID_SOCKET; }
DWORD scalanative_winsock_wsadata_size() { return sizeof(WSADATA); }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#if defined(_WIN32) || defined(WIN32)
#define WIN32_LEAN_AND_MEAN
#include "Windows.h"
#include "windows.h"

PCWSTR scalanative_locale_name_invariant() { return LOCALE_NAME_INVARIANT; }
PCWSTR scalanative_locale_name_system_default() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#if defined(_WIN32) || defined(WIN32)
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#include <windows.h>

DWORD scalanative_generic_all() { return GENERIC_ALL; }

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#if defined(_WIN32) || defined(WIN32)
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#include <windows.h>

DWORD scalanative_token_adjust_default() { return TOKEN_ADJUST_DEFAULT; }
DWORD scalanative_token_adjust_groups() { return TOKEN_ADJUST_GROUPS; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#if defined(_WIN32) || defined(WIN32)
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#pragma comment(lib, "Advapi32.lib")
#include <windows.h>
#pragma comment(lib, "advapi32.lib")

size_t scalanative_winnt_empty_priviliges_size() {
PRIVILEGE_SET privileges = {0};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#if defined(_WIN32) || defined(WIN32)
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#include <WinNT.h>
#include <windows.h>
#include <winnt.h>

int scalanative_sidtypeuser() { return SidTypeUser; }
int scalanative_sidtypegroup() { return SidTypeGroup; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#if defined(_WIN32) || defined(WIN32)
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#include <WinNT.h>
#include <windows.h>
#include <winnt.h>
#include <sdkddkver.h>

int scalanative_tokenuser() { return TokenUser; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import scalanative.unsigned._
import HandleApi.Handle
import WinBaseApi.SecurityAttributes

@link("Advapi32")
@link("Kernel32")
@link("advapi32")
@link("kernel32")
@extern()
object ProcessThreadsApi {
type StartupInfoW = CStruct18[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package scala.scalanative.windows

import scala.scalanative.unsafe._

@link("Advapi32")
@link("advapi32")
@extern()
object SddlApi {
import SecurityBaseApi._
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package scala.scalanative.windows
import scala.scalanative.unsafe.{Word => _, _}
import scala.scalanative.windows.HandleApi.Handle

@link("Advapi32")
@link("advapi32")
@extern()
object SecurityBaseApi {
import winnt.TokenInformationClass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package scala.scalanative.windows
import scala.scalanative.unsafe._
import scala.scalanative.windows.HandleApi.Handle

@link("Userenv")
@link("userenv")
@extern()
object UserEnvApi {
def GetUserProfileDirectoryA(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import scala.scalanative.unsigned._
import HandleApi.Handle
import scala.scalanative.windows.winnt._

@link("Advapi32")
@link("advapi32")
@extern()
object WinBaseApi {
import SecurityBaseApi._
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package scala.scalanative.windows
import scala.scalanative.unsafe._
import scala.scalanative.unsigned._

@link("Kernel32")
@link("kernel32")
@extern()
object WinNlsApi {
type LCType = Int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package scala.scalanative.windows.winnt

import scala.scalanative.unsafe._

@link("Advapi32")
@link("advapi32")
@extern
object AccessRights {
@name("scalanative_generic_all")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import scala.scalanative.unsafe._

import scala.scalanative.windows.SecurityBaseApi._

@link("Advapi32")
@link("advapi32")
@extern
object HelperMethods {
@name("scalanative_winnt_setupUsersGroupSid")
Expand Down

0 comments on commit 3ca9233

Please sign in to comment.