Skip to content

Commit

Permalink
2024-10-17 15:04 UTC+0200 Aleksander Czajczynski (hb fki.pl)
Browse files Browse the repository at this point in the history
  * .github/workflows/windows-ci.yml
    * update windows MSYS2 integration runner set of
      requested packages. PGSQL, Firebird and MariaDB libs
      are no longer available in the 32-bit environment

    + add clang x86_64 compiler for testing under this CI

  * include/harbour.hbx
  * include/hbapi.h
  * src/common/hbver.c
  * src/harbour.def
  * src/rtl/version.c
    ! fixed Windows 11 detection, by vendor likings it has
      NT Kernel Version stamped with 10.0, so now Build Number
      is more significant as a recognition factor.

    + new C helper functions hb_winisbuild(), hb_iswin11()

    + added PRG function hb_osIsWin11()

    * also try to detect new Windows Server versions

  * config/win/clang.mk
  * utils/hbmk2/hbmk2.prg
  * ChangeLog.txt
    ! recursion happening in the Makefiles rendered recently
      introduced compatibility option unreliable. Changed to
      use separate variable: HB_USER_FIXES=--mingw-script
      You don't need it, the problem shouldn't exist, but
      anyway...
  • Loading branch information
alcz committed Oct 17, 2024
1 parent 60a1066 commit c88029e
Show file tree
Hide file tree
Showing 9 changed files with 176 additions and 15 deletions.
31 changes: 27 additions & 4 deletions .github/workflows/windows-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@ jobs:
compiler:
- bcc
- mingw64
- clang
cpu:
- x86
- x86_64
exclude:
- compiler: bcc
cpu: x86_64
- compiler: clang
cpu: x86
strictness:
- "normal"
- "strict"
Expand All @@ -37,13 +40,17 @@ jobs:
(x86_64) echo MINGWxx="MINGW64"
echo "msys_cpu=${{matrix.cpu}}" ;;
esac
case ${{matrix.compiler}} in
(clang) echo MINGWxx="CLANG64" ;;
esac
} >> $GITHUB_ENV
- name: Install packages
uses: msys2/setup-msys2@v2
with:
msystem: ${{ env.MINGWxx }}
location: d:/
update: true
install: >
mingw-w64-${{ env.msys_cpu }}-ccache
mingw-w64-${{ env.msys_cpu }}-gcc
Expand All @@ -52,17 +59,22 @@ jobs:
mingw-w64-${{ env.msys_cpu }}-bzip2
mingw-w64-${{ env.msys_cpu }}-cairo
mingw-w64-${{ env.msys_cpu }}-curl
mingw-w64-${{ env.msys_cpu }}-firebird2-git
mingw-w64-${{ env.msys_cpu }}-libgd
mingw-w64-${{ env.msys_cpu }}-ghostscript
mingw-w64-${{ env.msys_cpu }}-libmariadbclient
mingw-w64-${{ env.msys_cpu }}-openssl
mingw-w64-${{ env.msys_cpu }}-postgresql
mingw-w64-${{ env.msys_cpu }}-qt5-base
# Dependencies for disabled contribs:
# mingw-w64-${{ env.msys_cpu }}-freeimage

- name: 'Add packages available on 64-bit hosts only'
if: matrix.cpu != 'x86'
shell: msys2 {0}
run: |
pacman -S --noconfirm mingw-w64-${{ env.msys_cpu }}-postgresql
pacman -S --noconfirm mingw-w64-${{ env.msys_cpu }}-libmariadbclient
pacman -S --noconfirm mingw-w64-${{ env.msys_cpu }}-firebird
- name: Checkout code
uses: actions/checkout@v3
with:
Expand All @@ -87,6 +99,17 @@ jobs:
set -ex
HB_USER_CFLAGS=""
HB_USER_LDFLAGS=""
case ${{matrix.compiler}} in
(clang)
pacman -S --noconfirm mingw-w64-${{ env.msys_cpu }}-clang
PATH="$PATH:/mingw64/bin/"
tee ./.bashrc <<EOMCLPTH
export PATH="\$PATH:/mingw64/bin/" # add ccache location
EOMCLPTH
;;
esac
case ${{matrix.strictness}} in
normal) ;;
strict) case ${{matrix.compiler}} in
Expand All @@ -95,7 +118,7 @@ jobs:
(*) HB_USER_CFLAGS="$HB_USER_CFLAGS -Werror -Wno-error=deprecated-declarations" ;;
esac ;;
esac
tee ./.bashrc <<EOENV
tee -a ./.bashrc <<EOENV
# These contribs do not build on any platform
export HB_BUILD_CONTRIBS="no hbfimage" # incompatible with freeimage 3.18+
Expand Down
34 changes: 33 additions & 1 deletion ChangeLog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,38 @@
Entries may not always be in chronological/commit order.
See license at the end of file. */

2024-10-17 15:04 UTC+0200 Aleksander Czajczynski (hb fki.pl)
* .github/workflows/windows-ci.yml
* update windows MSYS2 integration runner set of
requested packages. PGSQL, Firebird and MariaDB libs
are no longer available in the 32-bit environment

+ add clang x86_64 compiler for testing under this CI

* include/harbour.hbx
* include/hbapi.h
* src/common/hbver.c
* src/harbour.def
* src/rtl/version.c
! fixed Windows 11 detection, by vendor likings it has
NT Kernel Version stamped with 10.0, so now Build Number
is more significant as a recognition factor.

+ new C helper functions hb_winisbuild(), hb_iswin11()

+ added PRG function hb_osIsWin11()

* also try to detect new Windows Server versions

* config/win/clang.mk
* utils/hbmk2/hbmk2.prg
* ChangeLog.txt
! recursion happening in the Makefiles rendered recently
introduced compatibility option unreliable. Changed to
use separate variable: HB_USER_FIXES=--mingw-script
You don't need it, the problem shouldn't exist, but
anyway...

2024-10-10 14:21 UTC+0200 Aleksander Czajczynski (hb fki.pl)
+ config/win/clang-noauto.mk
+ additional clang flavour checking when the compiler is specified
Expand Down Expand Up @@ -37,7 +69,7 @@
They are now probed in order: windres, llvm-windres, llvm-rc.

* added option to use MinGW INPUT(file.o) link scripts for old tools
To apply workaround with clang, set HB_USER_DFLAGS=--mingw-script
To apply workaround with clang, set HB_USER_FIXES=--mingw-script
It is not supported in at least some of current clang toolchains,
but it's still needed to succesfully build on old ones (those
using GNU ld on Windows).
Expand Down
6 changes: 3 additions & 3 deletions config/win/clang.mk
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,14 @@ endif

TMPSPEC := @__dyn__.tmp

# setting HB_USER_DFLAGS=--mingw-script[...]
# setting HB_USER_FIXES=--mingw-script[...]
# may help to workaround if old clang + MinGW linker is in use,
# build may fail either with too long command line or unrecognized argument
ifneq ($(filter --mingw-script, $(HB_USER_DFLAGS)),)
HB_USER_DFLAGS := $(subst --mingw-script,,$(HB_USER_DFLAGS))
ifneq ($(filter --mingw-script, $(HB_USER_FIXES)),)
# NOTE: The empty line directly before 'endef' HAS TO exist!
override define dynlib_object
@$(ECHO) $(ECHOQUOTE)INPUT($(subst \,/,$(file)))$(ECHOQUOTE) >> __dyn__.tmp

endef
TMPSPEC := __dyn__.tmp
endif
Expand Down
1 change: 1 addition & 0 deletions include/harbour.hbx
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,7 @@ DYNAMIC hb_osDriveSeparator
DYNAMIC hb_osError
DYNAMIC hb_osFileMask
DYNAMIC hb_osIs64bit
DYNAMIC hb_osIsWin11
DYNAMIC hb_osIsWin10
DYNAMIC hb_osIsWin2K
DYNAMIC hb_osIsWin7
Expand Down
2 changes: 2 additions & 0 deletions include/hbapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -1213,9 +1213,11 @@ extern HB_EXPORT HB_BOOL hb_iswin7( void ); /* return HB_TRUE if OS == Windo
extern HB_EXPORT HB_BOOL hb_iswin8( void ); /* return HB_TRUE if OS == Windows 8 or newer */
extern HB_EXPORT HB_BOOL hb_iswin81( void ); /* return HB_TRUE if OS == Windows 8.1 or newer */
extern HB_EXPORT HB_BOOL hb_iswin10( void ); /* return HB_TRUE if OS == Windows 10 or newer */
extern HB_EXPORT HB_BOOL hb_iswin11( void ); /* return HB_TRUE if OS == Windows 11 or newer */
extern HB_EXPORT HB_BOOL hb_iswince( void ); /* return HB_TRUE if OS is Windows CE or Windows Mobile */
extern HB_EXPORT HB_BOOL hb_iswinver( int iMajor, int iMinor, int iType, HB_BOOL fOrUpper );
extern HB_EXPORT HB_BOOL hb_iswinsp( int iServicePackMajor, HB_BOOL fOrUpper );
extern HB_EXPORT HB_BOOL hb_iswinbuild( int iBuildNum, HB_BOOL fOrUpper );

extern HB_EXPORT HB_BOOL hb_printerIsReady( const char * pszPrinterName );

Expand Down
106 changes: 100 additions & 6 deletions src/common/hbver.c
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ const char * hb_verPlatformMacro( void )

static HB_BOOL s_fWinVerInit = HB_FALSE;

static HB_BOOL s_fWin11 = HB_FALSE;
static HB_BOOL s_fWin10 = HB_FALSE;
static HB_BOOL s_fWin81 = HB_FALSE;
static HB_BOOL s_fWin8 = HB_FALSE;
Expand Down Expand Up @@ -340,13 +341,16 @@ static void s_hb_winVerInit( void )
{
#if ! defined( HB_OS_WIN_CE )
s_fWin10 = hb_iswinver( 10, 0, 0, HB_TRUE );
if( s_fWin10 )
s_fWin11 = hb_iswinbuild( 22000, HB_TRUE );
s_fWin81 = hb_iswinver( 6, 3, 0, HB_TRUE );
s_fWin8 = hb_iswinver( 6, 2, 0, HB_TRUE );
s_fWin7 = hb_iswinver( 6, 1, 0, HB_TRUE );
s_fWinVista = hb_iswinver( 6, 0, 0, HB_TRUE );
s_fWin2K3 = hb_iswinver( 5, 2, VER_NT_SERVER, HB_TRUE ) || hb_iswinver( 5, 2, VER_NT_DOMAIN_CONTROLLER, HB_TRUE );
s_fWin2K = hb_iswinver( 5, 0, 0, HB_TRUE );


#if !( defined( HB_OS_WIN_64 ) || ( defined( _MSC_VER ) && _MSC_VER > 1310 ) )
{
OSVERSIONINFO osvi;
Expand All @@ -370,7 +374,7 @@ static void s_hb_winVerInit( void )
else if( osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 0 )
s_iWinNT = 4; /* 4.0 */
else
s_iWinNT = 5; /* newer */
s_iWinNT = 5; /* 2000/XP/2003 */
}
}
#endif
Expand All @@ -383,7 +387,45 @@ static void s_hb_winVerInit( void )
s_iWine = 1;
}

if( s_fWin2K )
if( s_fWin10 && ! s_iWine )
{
/* reusing s_iWinNT to store build number on Win10+ */

#if 0
typedef LONG NTSTATUS, * PNTSTATUS;
#define STATUS_SUCCESS (0x00000000)
typedef NTSTATUS ( WINAPI * _HB_RTLGETVERSION )( LPOSVERSIONINFOW );
HMODULE hntdll = GetModuleHandle( TEXT( "ntdll.dll" ) );

_HB_RTLGETVERSION pRtlGetVersion;
if( hntdll )
{
pRtlGetVersion := ( _HB_RTLGETVERSION ) HB_WINAPI_GETPROCADDRESS( hntdll, "RtlGetVersion" ) )
OSVERSIONINFOW ovi = { 0 };
ovi.dwOSVersionInfoSize = sizeof( ovi );
if( STATUS_SUCCESS == pRtlGetVersion( &ovi ) )
{
s_iWinNT = ( int ) ovi.dwBuildNumber;
}
}
#endif

/* NOTE: NT system version is always mapped into process (user-mode)
memory, though build number is there only on Win10 and up.
https://www.geoffchappell.com/studies/windows/km/ntoskrnl/inc/api/ntexapi_x/kuser_shared_data/index.htm */

s_iWinNT = ( int ) * ( PULONG ) ( 0x7FFE0000 + 0x0260 );

/* COMPAT: this seems much simpler than dyn-calling GetVersionEx
or WDK RtlGetVersion (having in mind deprecation warnings,
regressions from obscure compilers with conflicting headers)
If this ever causes a GPF on memory read, please revert,
or migrate to APIs. Mem-addr is correct for AMD64, ARM64 too.
WINE is intentionally excluded for reason, where an unknown
build may not support this. */

}
else if( s_fWin2K )
s_iWinNT = 5;
#endif

Expand All @@ -394,6 +436,7 @@ static void s_hb_winVerInit( void )

static HB_BOOL s_fWinVerInit = HB_FALSE;

static HB_BOOL s_fWin11 = HB_FALSE;
static HB_BOOL s_fWin10 = HB_FALSE;
static HB_BOOL s_fWin81 = HB_FALSE;
static HB_BOOL s_fWin8 = HB_FALSE;
Expand All @@ -410,6 +453,7 @@ static void s_hb_winVerInit( void )
union REGS regs;

/* TODO */
s_fWin11 = HB_FALSE;
s_fWin10 = HB_FALSE;
s_fWin81 = HB_FALSE;
s_fWin8 = HB_FALSE;
Expand Down Expand Up @@ -578,18 +622,27 @@ char * hb_verPlatform( void )
#if defined( HB_OS_WIN_CE )
pszName = " CE";
#else
if( hb_iswinver( 11, 0, 0, HB_TRUE ) )
if( hb_iswin11() )
{
osvi.dwMajorVersion = 11;
osvi.dwMajorVersion = 10;
osvi.dwMinorVersion = 0;
pszName = " 11 or newer";
if( hb_iswinver( 10, 0, VER_NT_WORKSTATION, HB_FALSE ) )
pszName = " 11 or newer";
else if( hb_iswinbuild( 26040, HB_TRUE ) )
pszName = " Server 2025";
else
pszName = " Server 23H2";
}
else if( hb_iswin10() )
{
osvi.dwMajorVersion = 10;
osvi.dwMinorVersion = 0;
if( hb_iswinver( 10, 0, VER_NT_WORKSTATION, HB_FALSE ) )
pszName = " 10";
else if( hb_iswinbuild( 20348, HB_TRUE ) )
pszName = " Server 2022";
else if( hb_iswinbuild( 17763, HB_TRUE ) )
pszName = " Server 2019";
else
pszName = " Server 2016";
}
Expand Down Expand Up @@ -668,7 +721,14 @@ char * hb_verPlatform( void )

/* Add service pack/other info */

if( hb_iswin2k() )
if( hb_iswin10() && ! s_iWine )
{
/* On Win10+ build number is more significant than Major Minor */
char szBuild[ 8 ];
hb_snprintf( szBuild, sizeof( szBuild ), ".%lu", ( DWORD ) s_iWinNT );
hb_strncat( pszPlatform, szBuild, PLATFORM_BUF_SIZE );
}
else if( hb_iswin2k() )
{
int tmp;

Expand Down Expand Up @@ -814,6 +874,29 @@ HB_BOOL hb_iswinsp( int iServicePackMajor, HB_BOOL fOrUpper )
return HB_FALSE;
}

HB_BOOL hb_iswinbuild( int iBuildNum, HB_BOOL fOrUpper )
{
#if defined( HB_OS_WIN ) && ! defined( HB_OS_WIN_CE )
if( s_hb_winVerifyVersionInit() )
{
OSVERSIONINFOEXW ver;
DWORDLONG dwlConditionMask = 0;

memset( &ver, 0, sizeof( ver ) );
ver.dwOSVersionInfoSize = sizeof( ver );
ver.dwBuildNumber = ( DWORD ) iBuildNum;

dwlConditionMask = s_pVerSetConditionMask( dwlConditionMask, VER_BUILDNUMBER, fOrUpper ? VER_GREATER_EQUAL : VER_EQUAL );

return ( HB_BOOL ) s_pVerifyVersionInfo( &ver, VER_BUILDNUMBER, dwlConditionMask );
}
#else
HB_SYMBOL_UNUSED( iBuildNum );
HB_SYMBOL_UNUSED( fOrUpper );
#endif
return HB_FALSE;
}

int hb_iswine( void )
{
#if defined( HB_OS_WIN ) || defined( HB_OS_DOS )
Expand All @@ -825,6 +908,17 @@ int hb_iswine( void )
#endif
}

HB_BOOL hb_iswin11( void )
{
#if defined( HB_OS_WIN ) || defined( HB_OS_DOS )
if( ! s_fWinVerInit )
s_hb_winVerInit();
return s_fWin11;
#else
return HB_FALSE;
#endif
}

HB_BOOL hb_iswin10( void )
{
#if defined( HB_OS_WIN ) || defined( HB_OS_DOS )
Expand Down
2 changes: 2 additions & 0 deletions src/harbour.def
Original file line number Diff line number Diff line change
Expand Up @@ -924,6 +924,7 @@ HB_FUN_HB_OSDRIVESEPARATOR
HB_FUN_HB_OSERROR
HB_FUN_HB_OSFILEMASK
HB_FUN_HB_OSIS64BIT
HB_FUN_HB_OSISWIN11
HB_FUN_HB_OSISWIN10
HB_FUN_HB_OSISWIN2K
HB_FUN_HB_OSISWIN7
Expand Down Expand Up @@ -2778,6 +2779,7 @@ hb_inkeyPut
hb_inkeyReset
hb_inkeySetLast
hb_inkeySetText
hb_iswin11
hb_iswin10
hb_iswin2k
hb_iswin2k3
Expand Down
5 changes: 5 additions & 0 deletions src/rtl/version.c
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,11 @@ HB_FUNC( HB_OSISWIN10 )
hb_retl( hb_iswin10() );
}

HB_FUNC( HB_OSISWIN11 )
{
hb_retl( hb_iswin11() );
}

HB_FUNC( HB_OSISWINCE )
{
hb_retl( hb_iswince() );
Expand Down
Loading

0 comments on commit c88029e

Please sign in to comment.