Skip to content

Commit

Permalink
build(core) with clang-cl when possible
Browse files Browse the repository at this point in the history
Build times with Visual Studio's Clang/LLVM toolset are considerably
higher, but the resulting binaries are generally more efficient.
  • Loading branch information
Spasi committed Jun 10, 2024
1 parent 233fb88 commit 4ac9d90
Show file tree
Hide file tree
Showing 11 changed files with 85 additions and 42 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -359,9 +359,10 @@ jobs:
Rename-Item zulu8.78.0.19-ca-jdk8.0.412-win_i686 jdk8
shell: pwsh
if: matrix.ARCH == 'x86'
- name: Build native
- name: Build native # TODO: remove old LLVM workaround, see https://github.com/actions/runner-images/issues/10001
run: |
set LWJGL_BUILD_ARCH=${{matrix.ARCH}}
set PATH=%PATH:C:\Program Files\LLVM\bin;=%
ant -emacs compile-native
- name: Run tests
run: ant -emacs tests
Expand Down
73 changes: 49 additions & 24 deletions config/windows/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,26 @@
<project name="native-windows" basedir="../.." xmlns:if="ant:if" xmlns:unless="ant:unless">
<import file="../build-definitions.xml"/>

<property name="clang-target" value="i686" if:set="build.arch.x86"/>
<property name="clang-target" value="amd64" if:set="build.arch.x64"/>
<property name="clang-target" value="aarch64" if:set="build.arch.arm64"/>

<macrodef name="compile">
<attribute name="dest" default="${dest}"/>
<attribute name="useClang" default="true"/>
<attribute name="flags" default=""/>
<attribute name="simple" default="false"/>
<attribute name="relative" default="true"/>
<element name="source" implicit="true" optional="true"/>
<sequential>
<local name="compiler"/>
<condition property="compiler" value="clang-cl" else="cl"><istrue value="@{useClang}"/></condition>

<mkdir dir="@{dest}"/>
<apply executable="cl" dest="@{dest}" skipemptyfilesets="true" failonerror="true" relative="@{relative}" parallel="true" taskname="Compiler">
<arg line="/c /EHsc /O2 /GL /GR- /GS- /MT /MP @{flags} /nologo /DNDEBUG /DLWJGL_WINDOWS /DLWJGL_${build.arch}"/>
<apply executable="${compiler}" dest="@{dest}" skipemptyfilesets="true" failonerror="true" relative="@{relative}" parallel="true" taskname="Compiler">
<arg line="/c /EHsc /O2 /GR- /GS- /MT @{flags} /nologo /DNDEBUG /DLWJGL_WINDOWS /DLWJGL_${build.arch}"/>
<arg line="/GL /MP" unless:true="@{useClang}"/>
<arg line="-flto -fwhole-program-vtables --target=${clang-target}-pc-windows-msvc" if:true="@{useClang}"/>

<arg value="/Fo@{dest}\"/>

Expand All @@ -36,6 +46,7 @@

<macrodef name="build">
<attribute name="module"/>
<attribute name="useClang" default="true"/>
<attribute name="flags" default="/W2"/>
<attribute name="simple" default="false"/>
<element name="beforeCompile" optional="true"/>
Expand All @@ -59,7 +70,7 @@
<property name="dest" value="${bin.native}/@{module}"/>

<beforeCompile/>
<compile flags="@{flags}" simple="@{simple}">
<compile useClang="@{useClang}" flags="@{flags}" simple="@{simple}">
<compileargs/>
<source/>
</compile>
Expand Down Expand Up @@ -111,8 +122,12 @@ EXPORTS

<mkdir dir="${lib.arch}" unless:set="lib-uptodate"/>
<beforeLink unless:set="lib-uptodate"/>
<apply executable="cl" failonerror="true" parallel="true" taskname="Linker" unless:set="lib-uptodate">

<local name="linker"/>
<condition property="linker" value="clang-cl" else="cl"><istrue value="@{useClang}"/></condition>
<apply executable="${linker}" failonerror="true" parallel="true" taskname="Linker" unless:set="lib-uptodate">
<arg line='/LD /WX /nologo /Fe:"${bin.native}\build\${name}.dll"'/>
<arg line='-fuse-ld=lld' if:true="@{useClang}"/>

<fileset dir="${dest}" includes="*.obj"/>
<link/>
Expand All @@ -121,6 +136,7 @@ EXPORTS
<arg value="/link"/>
<arg value="/OPT:REF,ICF"/>
<arg value="/DLL"/>
<arg value="/INCREMENTAL:NO"/>
<arg value="/LTCG"/>
<arg value="/DEF:${bin.native}\build\${name}.def" if:set="undecorate"/>

Expand All @@ -134,8 +150,9 @@ EXPORTS

<macrodef name="build_simple">
<attribute name="module"/>
<attribute name="useClang" default="true"/>
<sequential>
<build module="@{module}" simple="true" if:true="${binding.@{module}}"/>
<build module="@{module}" useClang="@{useClang}" simple="true" if:true="${binding.@{module}}"/>
</sequential>
</macrodef>

Expand All @@ -145,7 +162,7 @@ EXPORTS
<parallel threadsPerProcessor="1">

<!-- CORE -->
<build module="core" flags="/Wall /WX /wd4710 /wd4711">
<build module="core" flags="/W4 /WX /wd4710 /wd4711">
<compileargs>
<arg value="/I${src.main}\libffi"/>
<arg value="/I${src.main}\libffi\aarch64" if:set="build.arch.arm64"/>
Expand Down Expand Up @@ -213,17 +230,21 @@ EXPORTS
</build>

<!-- Meow -->
<build_simple module="meow"/>
<build_simple module="meow" useClang="false"/>

<!-- meshoptimizer -->
<build module="meshoptimizer" simple="true" if:true="${binding.meshoptimizer}">
<beforeCompile>
<compile flags="/DMESHOPTIMIZER_NO_WRAPPERS">
<arg value="/I${src.main}"/>
<fileset dir="." includes="${src.main}/*.cpp"/>
</compile>
</beforeCompile>
</build>
<sequential if:true="${binding.meshoptimizer}">
<local name="meshoptimizer.useClang"/>
<condition property="meshoptimizer.useClang" value="false" else="true"><isset property="build.arch.arm64"/></condition>
<build module="meshoptimizer" useClang="${meshoptimizer.useClang}" simple="true">
<beforeCompile>
<compile useClang="${meshoptimizer.useClang}" flags="/DMESHOPTIMIZER_NO_WRAPPERS">
<arg value="/I${src.main}"/>
<fileset dir="." includes="${src.main}/*.cpp"/>
</compile>
</beforeCompile>
</build>
</sequential>

<!-- NanoVG -->
<build module="nanovg" simple="true" if:true="${binding.nanovg}">
Expand Down Expand Up @@ -281,15 +302,19 @@ EXPORTS
<build_simple module="par"/>

<!-- Remotery -->
<build module="remotery" if:true="${binding.remotery}">
<compileargs>
<arg value="/I${src.main}"/>
<arg value="/I${module.lwjgl}\vulkan\src\main\c"/>
</compileargs>
<source>
<fileset dir="." includes="${src.generated}/*.c" excludes="**/*Metal.c"/>
</source>
</build>
<sequential if:true="${binding.remotery}">
<local name="remotery.useClang"/>
<condition property="remotery.useClang" value="false" else="true"><isset property="build.arch.x86"/></condition>
<build module="remotery" useClang="${remotery.useClang}">
<compileargs>
<arg value="/I${src.main}"/>
<arg value="/I${module.lwjgl}\vulkan\src\main\c"/>
</compileargs>
<source>
<fileset dir="." includes="${src.generated}/*.c" excludes="**/*Metal.c"/>
</source>
</build>
</sequential>

<!-- rpmalloc -->
<build module="rpmalloc" simple="true" if:true="${binding.rpmalloc}">
Expand Down
1 change: 1 addition & 0 deletions doc/notes/3.3.4.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ This build includes the following changes:
- Linux: Added support for the RISC-V 64 architecture. (#890)
* Maven classifier: `linux-riscv64`
- Linux: ARM/PowerPC/RISC-V shared libraries are now built with GCC 11 (up from GCC 7).
- Windows: Shared libraries are now built with Clang/LLVM (clang-cl toolset) when possible.
- Vulkan: Made `VkMemoryRequirements` mutable for the `vmaAllocateMemory(Pages)` functions. (#937)

#### Fixes
Expand Down
2 changes: 2 additions & 0 deletions modules/lwjgl/core/src/main/c/common_tools.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ extern JNIEnv* getEnv(jboolean* async);
envData = (EnvData *)(uintptr_t)(*__env)->CallStaticLongMethod(__env, TLU, (*__env)->GetStaticMethodID(__env, TLU, "setupEnvData", "()J")); \
} \
envData->LastError = LastError;
#endif

#if defined(LWJGL_WINDOWS) && !defined(__clang__)
#define VA_LIST_CAST &(va_list)
#else
#define VA_LIST_CAST (va_list *)
Expand Down
26 changes: 20 additions & 6 deletions modules/lwjgl/core/src/main/c/windows/WindowsConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,28 @@

#include <stdint.h>

#define DISABLE_WARNINGS() \
__pragma(warning(push, 0))
#ifdef __clang__
#define DISABLE_WARNINGS() \
_Pragma("GCC diagnostic push") \
_Pragma("GCC diagnostic ignored \"-Wall\"") \
_Pragma("GCC diagnostic ignored \"-Wextra\"")
_Pragma("GCC diagnostic ignored \"-Wunused-value\"")
_Pragma("GCC diagnostic ignored \"-Wunused-function\"")
_Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
_Pragma("GCC diagnostic ignored \"-Wignored-attributes\"")

#define ENABLE_WARNINGS() \
__pragma(warning(pop))
#define ENABLE_WARNINGS() \
_Pragma("GCC diagnostic pop")
#else
#define DISABLE_WARNINGS() \
__pragma(warning(push, 0))

#ifndef __cplusplus
#define inline __forceinline
#define ENABLE_WARNINGS() \
__pragma(warning(pop))

#ifndef __cplusplus
#define inline __forceinline
#endif
#endif

// JNIEXPORT_CRITICAL & CRITICAL are used as a workaround for JDK-8167409 on applicable functions.
Expand Down
8 changes: 4 additions & 4 deletions modules/lwjgl/nanovg/src/main/c/blendish.h
Original file line number Diff line number Diff line change
Expand Up @@ -1750,21 +1750,21 @@ void bndNodeBackground(NVGcontext *ctx, float x, float y, float w, float h,
iconid, bnd_theme.regularTheme.textColor,
bndOffsetColor(titleColor, BND_BEVEL_SHADE),
BND_LEFT, BND_LABEL_FONT_SIZE, label);
NVGcolor arrowColor;
//NVGcolor arrowColor;
NVGcolor borderColor;
switch(state) {
default:
case BND_DEFAULT: {
borderColor = nvgRGBf(0,0,0);
arrowColor = bndOffsetColor(titleColor, -BND_BEVEL_SHADE);
//arrowColor = bndOffsetColor(titleColor, -BND_BEVEL_SHADE);
} break;
case BND_HOVER: {
borderColor = bnd_theme.nodeTheme.nodeSelectedColor;
arrowColor = bnd_theme.nodeTheme.nodeSelectedColor;
//arrowColor = bnd_theme.nodeTheme.nodeSelectedColor;
} break;
case BND_ACTIVE: {
borderColor = bnd_theme.nodeTheme.activeNodeColor;
arrowColor = bnd_theme.nodeTheme.nodeSelectedColor;
//arrowColor = bnd_theme.nodeTheme.nodeSelectedColor;
} break;
}
bndOutlineBox(ctx,x,y,w,h+1,
Expand Down
6 changes: 3 additions & 3 deletions modules/lwjgl/tootle/src/main/c/RayTracer/Math/JMLSSEVec.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <iostream>
#include <math.h>

#ifdef _LINUX
#if defined(_LINUX) || defined(__clang__)
class SSEVec4
#else
class __declspec(align(16)) SSEVec4
Expand All @@ -21,7 +21,7 @@
union
{
__m128 vec128;
#ifdef _LINUX
#if defined(_LINUX) || defined(__clang__)
float f32[4];
#endif
};
Expand All @@ -42,7 +42,7 @@
inline operator const __m128() const { return vec128; };

// indexing
#ifdef _LINUX
#if defined(_LINUX) || defined(__clang__)
inline const float& operator[](int i) const { return f32[i]; };
inline float& operator[](int i) { return f32[i]; };
#else
Expand Down
2 changes: 1 addition & 1 deletion modules/lwjgl/tootle/src/main/c/tootlelib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include "Stripifier.h"

#ifdef _DX11_1_
#include "directxmesh.h"
#include "DirectXMesh.h"
#endif

#define AMD_TOOTLE_API_FUNCTION_BEGIN try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "common_tools.h"
#include "lwjgl_malloc.h"
DISABLE_WARNINGS()
#if LWJGL_MACOS
#ifdef __clang__
_Pragma("GCC diagnostic ignored \"-Wnullability-completeness\"")
#endif
#define VMA_IMPLEMENTATION
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ val VMA = "Vma".nativeClass(Module.VMA, "Vma", prefix = "VMA") {
nativeDirective(
"""#include "lwjgl_malloc.h"
DISABLE_WARNINGS()
#if LWJGL_MACOS
#ifdef __clang__
_Pragma("GCC diagnostic ignored \"-Wnullability-completeness\"")
#endif
#define VMA_IMPLEMENTATION
Expand Down
2 changes: 1 addition & 1 deletion modules/lwjgl/zstd/src/main/c/common/cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ MEM_STATIC ZSTD_cpuid_t ZSTD_cpuid(void) {
U32 f7b = 0;
U32 f7c = 0;
#if defined(_MSC_VER) && (defined(_M_X64) || defined(_M_IX86))
#if !defined(__clang__)
#if !defined(__clang__) || defined(_M_IX86)
int reg[4];
__cpuid((int*)reg, 0);
{
Expand Down

0 comments on commit 4ac9d90

Please sign in to comment.