add support for clang compiler (#592)

* hacks to align strings for clang... wow just wow

* start work to getting built with clang

* fix issues with struct constructors, all builds, doesn't link still

* fix some narrowing issues that clang complains about

* fix compliation of zapd

* fix null deref in VersionInfo

* builds with clang

* make stringbuilding use StringHelper instead of addition

* fix linking

* add CLANG SHIP overlay on clang built versions

* doesn't need to be volatile

* mark unknown strings as extern

* rename some stuff

* can't align extern

* hopefully fix compilation for everythign

* expandtab

* allow setting LD

* Revert "allow setting LD"

This reverts commit 711aba6db2.

maybe to use lld it should be a LDFLAG?

* -Wno-deprecated-declarations is required for newer versions of clang

on macOS 13 beta sdk, the version of apple clang requires this

* Add jenkins support for clang

* Forward CXX flags to stormlib compilation

* Move GCC only flags to check

* use exports to set multiarch setup

* Fix Jenkins forever

* use make instead of cmake --build

add some flags to build with clang-11 as well

* address review coments

- rework extraction to allow multi thread
- misc readability cleanup

* update makefile to add WARN on linux+clang

Co-authored-by: David Chavez <david@dcvz.io>
This commit is contained in:
Jeffrey Crowell 2022-07-10 10:51:12 -04:00 committed by GitHub
commit d4c1c40c1d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
27 changed files with 155 additions and 109 deletions

View file

@ -18,8 +18,11 @@ LTO ?= 0
WARN := \
-Wno-return-type \
-Wno-unused-command-line-argument \
-Wno-implicit-function-declaration \
-Wno-c++11-narrowing \
-funsigned-char \
-fno-stack-protector -fno-common -fno-zero-initialized-in-bss -fno-strict-aliasing -fno-inline-functions -fno-inline-small-functions -fno-toplevel-reorder -ffreestanding -fwrapv \
-fno-stack-protector -fno-common -fno-zero-initialized-in-bss -fno-strict-aliasing -fno-inline-functions -fno-inline-small-functions -ffreestanding -fwrapv \
CXXFLAGS := $(WARN) -std=c++20 -D_GNU_SOURCE -fpermissive -no-pie -nostdlib
CFLAGS := $(WARN) -std=c99 -D_GNU_SOURCE -no-pie -nostdlib
@ -99,7 +102,6 @@ LDLIBS := \
bz2 \
z \
pthread \
atomic \
ultraship \
)
@ -116,7 +118,7 @@ endif
ifeq ($(UNAME), Darwin) #APPLE
LDLIBS += \
$(addprefix -framework, \
$(addprefix -framework , \
OpenGL \
) \
$(shell sdl2-config --libs) $(shell pkg-config --libs glew)
@ -208,7 +210,7 @@ build/%.o: %.c
$(TARGET): $(LIBULTRASHIP)
$(TARGET): $(O_FILES)
$(CXX) $^ -o $@ $(LDFLAGS) -fuse-ld=$(LD) $(LDDIRS) $(LDLIBS)
$(CXX) $^ -o $@ $(LDFLAGS) $(LDDIRS) $(LDLIBS)
-include $(D_FILES)

View file

@ -5,6 +5,7 @@
#include <ultra64.h>
#include <functions.h>
#include <variables.h>
#include <string.h>
#include <stdarg.h>
#include <z64.h>
#include <ultra64/gbi.h>

View file

@ -509,7 +509,7 @@ void DebugConsole_LoadCVars()
if (cfg.size() < 2) continue;
if (cfg[1].find("\"") != std::string::npos) {
std::string value(cfg[1]);
value.erase(std::ranges::remove(value, '\"').begin(), value.end());
value.erase(std::remove(value.begin(), value.end(), '\"'), value.end());
CVar_SetString(cfg[0].c_str(), ImStrdup(value.c_str()));
}
if (is_number<float>(cfg[1])) {

View file

@ -194,9 +194,9 @@ void CreateSphereFace(std::vector<std::tuple<size_t, size_t, size_t>>& faces, in
// Create 3 new verticies at the midpoints
Vec3f vs[3] = {
Vec3f((v0.n.ob[0] + v1.n.ob[0]) / 2.0f, (v0.n.ob[1] + v1.n.ob[1]) / 2.0f, (v0.n.ob[2] + v1.n.ob[2]) / 2.0f),
Vec3f((v1.n.ob[0] + v2.n.ob[0]) / 2.0f, (v1.n.ob[1] + v2.n.ob[1]) / 2.0f, (v1.n.ob[2] + v2.n.ob[2]) / 2.0f),
Vec3f((v2.n.ob[0] + v0.n.ob[0]) / 2.0f, (v2.n.ob[1] + v0.n.ob[1]) / 2.0f, (v2.n.ob[2] + v0.n.ob[2]) / 2.0f)
Vec3f{(v0.n.ob[0] + v1.n.ob[0]) / 2.0f, (v0.n.ob[1] + v1.n.ob[1]) / 2.0f, (v0.n.ob[2] + v1.n.ob[2]) / 2.0f},
Vec3f{(v1.n.ob[0] + v2.n.ob[0]) / 2.0f, (v1.n.ob[1] + v2.n.ob[1]) / 2.0f, (v1.n.ob[2] + v2.n.ob[2]) / 2.0f},
Vec3f{(v2.n.ob[0] + v0.n.ob[0]) / 2.0f, (v2.n.ob[1] + v0.n.ob[1]) / 2.0f, (v2.n.ob[2] + v0.n.ob[2]) / 2.0f}
};
// Normalize vertex positions so they are on the sphere
@ -221,20 +221,20 @@ void CreateSphereData() {
float d = (1.0f + sqrtf(5.0f)) / 2.0f;
// Create the 12 starting verticies, 4 on each rectangle
base.emplace_back(-1, d, 0);
base.emplace_back(1, d, 0);
base.emplace_back(-1, -d, 0);
base.emplace_back(1, -d, 0);
base.emplace_back(Vec3f({-1, d, 0}));
base.emplace_back(Vec3f({1, d, 0}));
base.emplace_back(Vec3f({-1, -d, 0}));
base.emplace_back(Vec3f({1, -d, 0}));
base.emplace_back(0, -1, d);
base.emplace_back(0, 1, d);
base.emplace_back(0, -1, -d);
base.emplace_back(0, 1, -d);
base.emplace_back(Vec3f({0, -1, d}));
base.emplace_back(Vec3f({0, 1, d}));
base.emplace_back(Vec3f({0, -1, -d}));
base.emplace_back(Vec3f({0, 1, -d}));
base.emplace_back(d, 0, -1);
base.emplace_back(d, 0, 1);
base.emplace_back(-d, 0, -1);
base.emplace_back(-d, 0, 1);
base.emplace_back(Vec3f({d, 0, -1}));
base.emplace_back(Vec3f({d, 0, 1}));
base.emplace_back(Vec3f({-d, 0, -1}));
base.emplace_back(Vec3f({-d, 0, 1}));
// Normalize verticies so they are on the unit sphere
for (Vec3f& v : base) {

View file

@ -185,17 +185,17 @@ typedef struct {
// Maps quest items ids to info for use in ImGui
std::map<uint32_t, QuestMapEntry> questMapping = {
QUEST_MAP_ENTRY(QUEST_MEDALLION_FOREST, gForestMedallionIconTex),
QUEST_MAP_ENTRY(QUEST_MEDALLION_FIRE, gFireMedallionIconTex),
QUEST_MAP_ENTRY(QUEST_MEDALLION_WATER, gWaterMedallionIconTex),
QUEST_MAP_ENTRY(QUEST_MEDALLION_SPIRIT, gSpiritMedallionIconTex),
QUEST_MAP_ENTRY(QUEST_MEDALLION_SHADOW, gShadowMedallionIconTex),
QUEST_MAP_ENTRY(QUEST_MEDALLION_LIGHT, gLightMedallionIconTex),
QUEST_MAP_ENTRY(QUEST_KOKIRI_EMERALD, gKokiriEmeraldIconTex),
QUEST_MAP_ENTRY(QUEST_GORON_RUBY, gGoronRubyIconTex),
QUEST_MAP_ENTRY(QUEST_ZORA_SAPPHIRE, gZoraSapphireIconTex),
QUEST_MAP_ENTRY(QUEST_STONE_OF_AGONY, gStoneOfAgonyIconTex),
QUEST_MAP_ENTRY(QUEST_GERUDO_CARD, gGerudosCardIconTex),
QUEST_MAP_ENTRY(QUEST_MEDALLION_FOREST, dgForestMedallionIconTex),
QUEST_MAP_ENTRY(QUEST_MEDALLION_FIRE, dgFireMedallionIconTex),
QUEST_MAP_ENTRY(QUEST_MEDALLION_WATER, dgWaterMedallionIconTex),
QUEST_MAP_ENTRY(QUEST_MEDALLION_SPIRIT, dgSpiritMedallionIconTex),
QUEST_MAP_ENTRY(QUEST_MEDALLION_SHADOW, dgShadowMedallionIconTex),
QUEST_MAP_ENTRY(QUEST_MEDALLION_LIGHT, dgLightMedallionIconTex),
QUEST_MAP_ENTRY(QUEST_KOKIRI_EMERALD, dgKokiriEmeraldIconTex),
QUEST_MAP_ENTRY(QUEST_GORON_RUBY, dgGoronRubyIconTex),
QUEST_MAP_ENTRY(QUEST_ZORA_SAPPHIRE, dgZoraSapphireIconTex),
QUEST_MAP_ENTRY(QUEST_STONE_OF_AGONY, dgStoneOfAgonyIconTex),
QUEST_MAP_ENTRY(QUEST_GERUDO_CARD, dgGerudosCardIconTex),
};
typedef struct {

View file

@ -1330,17 +1330,17 @@ extern "C" int16_t OTRGetRectDimensionFromRightEdge(float v) {
}
extern "C" void bswapSoundFontSound(SoundFontSound* swappable) {
swappable->sample = (SoundFontSample*)BOMSWAP32((u32)swappable->sample);
swappable->tuningAsU32 = BOMSWAP32((u32)swappable->tuningAsU32);
swappable->sample = (SoundFontSample*)BOMSWAP32((u32)(uintptr_t(swappable->sample)));
swappable->tuningAsU32 = BOMSWAP32((u32)(swappable->tuningAsU32 & 0xFFFFFFFF));
}
extern "C" void bswapDrum(Drum* swappable) {
bswapSoundFontSound(&swappable->sound);
swappable->envelope = (AdsrEnvelope*)BOMSWAP32((u32)swappable->envelope);
swappable->envelope = (AdsrEnvelope*)BOMSWAP32((u32)uintptr_t(swappable->envelope));
}
extern "C" void bswapInstrument(Instrument* swappable) {
swappable->envelope = (AdsrEnvelope*)BOMSWAP32((u32)swappable->envelope);
swappable->envelope = (AdsrEnvelope*)BOMSWAP32((u32)uintptr_t(swappable->envelope));
bswapSoundFontSound(&swappable->lowNotesSound);
bswapSoundFontSound(&swappable->normalNotesSound);
bswapSoundFontSound(&swappable->highNotesSound);
@ -1355,9 +1355,9 @@ extern "C" void bswapSoundFontSample(SoundFontSample* swappable) {
swappable->unk_bit25 = (origBitfield >> 21) & 0x01;
swappable->size = (origBitfield) & 0x00FFFFFF;
swappable->sampleAddr = (u8*)BOMSWAP32((u32)swappable->sampleAddr);
swappable->loop = (AdpcmLoop*)BOMSWAP32((u32)swappable->loop);
swappable->book = (AdpcmBook*)BOMSWAP32((u32)swappable->book);
swappable->sampleAddr = (u8*)BOMSWAP32((u32)uintptr_t(swappable->sampleAddr));
swappable->loop = (AdpcmLoop*)BOMSWAP32((u32)uintptr_t(swappable->loop));
swappable->book = (AdpcmBook*)BOMSWAP32((u32)uintptr_t(swappable->book));
}
extern "C" void bswapAdpcmLoop(AdpcmLoop* swappable) {

View file

@ -1,3 +1,4 @@
#include <math.h>
#include "z64.h"
void guMtxF2L(float mf[4][4], Mtx* m) {
@ -84,4 +85,4 @@ void guNormalize(f32* x, f32* y, f32* z) {
*x = *x * tmp;
*y = *y * tmp;
*z = *z * tmp;
}
}

View file

@ -1,3 +1,4 @@
#include <string.h>
#include "global.h"
#include "vt.h"
@ -9,6 +10,9 @@ ViMode sViMode;
FaultClient sGameFaultClient;
u16 sLastButtonPressed;
// Forward declared, because this in a C++ header.
int gfx_create_framebuffer(uint32_t width, uint32_t height);
void GameState_FaultPrint(void) {
static char sBtnChars[] = "ABZSuldr*+LRudlr";
s32 i;

View file

@ -33,6 +33,8 @@ void Title_PrintBuildInfo(Gfx** gfxp) {
#ifdef _MSC_VER
GfxPrint_Printf(&printer, "MSVC SHIP");
#elif __clang__
GfxPrint_Printf(&printer, "CLANG SHIP");
#else
GfxPrint_Printf(&printer, "GCC SHIP");
#endif