Skip to content

Commit 5d8a6a2

Browse files
authored
Use regular -I include flag for SDL paths (#17475)
When SDL it used on the desktop the SDL include paths are injected in this way: ``` $ sdl-config --cflags -I/usr/include/SDL -D_GNU_SOURCE=1 -D_REENTRANT $ sdl2-config --cflags -I/usr/include/SDL2 -D_REENTRANT ``` Its also the way to add include paths for all the other ports.
1 parent d2e79de commit 5d8a6a2

File tree

3 files changed

+53
-41
lines changed

3 files changed

+53
-41
lines changed

emcc.py

Lines changed: 50 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
C_ENDINGS = ('.c', '.i')
6060
CXX_ENDINGS = ('.cpp', '.cxx', '.cc', '.c++', '.CPP', '.CXX', '.C', '.CC', '.C++', '.ii')
6161
OBJC_ENDINGS = ('.m', '.mi')
62+
PREPROCESSED_ENDINGS = ('.i', '.ii')
6263
OBJCXX_ENDINGS = ('.mm', '.mii')
6364
SPECIAL_ENDINGLESS_FILENAMES = (os.devnull,)
6465

@@ -822,10 +823,50 @@ def array_contains_any_of(hay, needles):
822823
return cflags + ['-Xclang', '-iwithsysroot' + os.path.join('/include', 'compat')]
823824

824825

825-
def get_clang_flags():
826+
def get_target_flags():
826827
return ['-target', shared.get_llvm_target()]
827828

828829

830+
def get_clang_flags(user_args):
831+
flags = get_target_flags()
832+
833+
# if exception catching is disabled, we can prevent that code from being
834+
# generated in the frontend
835+
if settings.DISABLE_EXCEPTION_CATCHING and not settings.WASM_EXCEPTIONS:
836+
flags.append('-fignore-exceptions')
837+
838+
if settings.INLINING_LIMIT:
839+
flags.append('-fno-inline-functions')
840+
841+
if settings.RELOCATABLE and '-fPIC' not in user_args:
842+
flags.append('-fPIC')
843+
844+
# We use default visiibilty=default in emscripten even though the upstream
845+
# backend defaults visibility=hidden. This matched the expectations of C/C++
846+
# code in the wild which expects undecorated symbols to be exported to other
847+
# DSO's by default.
848+
if not any(a.startswith('-fvisibility') for a in user_args):
849+
flags.append('-fvisibility=default')
850+
851+
if settings.LTO:
852+
if not any(a.startswith('-flto') for a in user_args):
853+
flags.append('-flto=' + settings.LTO)
854+
# setjmp/longjmp handling using Wasm EH
855+
# For non-LTO, '-mllvm -wasm-enable-eh' added in
856+
# building.llvm_backend_args() sets this feature in clang. But in LTO, the
857+
# argument is added to wasm-ld instead, so clang needs to know that EH is
858+
# enabled so that it can be added to the attributes in LLVM IR.
859+
if settings.SUPPORT_LONGJMP == 'wasm':
860+
flags.append('-mexception-handling')
861+
862+
else:
863+
# In LTO mode these args get passed instead at link time when the backend runs.
864+
for a in building.llvm_backend_args():
865+
flags += ['-mllvm', a]
866+
867+
return flags
868+
869+
829870
cflags = None
830871

831872

@@ -836,7 +877,7 @@ def get_cflags(user_args):
836877

837878
# Flags we pass to the compiler when building C/C++ code
838879
# We add these to the user's flags (newargs), but not when building .s or .S assembly files
839-
cflags = get_clang_flags()
880+
cflags = get_clang_flags(user_args)
840881

841882
if settings.EMSCRIPTEN_TRACING:
842883
cflags.append('-D__EMSCRIPTEN_TRACING__=1')
@@ -858,40 +899,6 @@ def get_cflags(user_args):
858899
'-D__EMSCRIPTEN_minor__=' + str(shared.EMSCRIPTEN_VERSION_MINOR),
859900
'-D__EMSCRIPTEN_tiny__=' + str(shared.EMSCRIPTEN_VERSION_TINY)]
860901

861-
# if exception catching is disabled, we can prevent that code from being
862-
# generated in the frontend
863-
if settings.DISABLE_EXCEPTION_CATCHING and not settings.WASM_EXCEPTIONS:
864-
cflags.append('-fignore-exceptions')
865-
866-
if settings.INLINING_LIMIT:
867-
cflags.append('-fno-inline-functions')
868-
869-
if settings.RELOCATABLE and '-fPIC' not in user_args:
870-
cflags.append('-fPIC')
871-
872-
# We use default visiibilty=default in emscripten even though the upstream
873-
# backend defaults visibility=hidden. This matched the expectations of C/C++
874-
# code in the wild which expects undecorated symbols to be exported to other
875-
# DSO's by default.
876-
if not any(a.startswith('-fvisibility') for a in user_args):
877-
cflags.append('-fvisibility=default')
878-
879-
if settings.LTO:
880-
if not any(a.startswith('-flto') for a in user_args):
881-
cflags.append('-flto=' + settings.LTO)
882-
# setjmp/longjmp handling using Wasm EH
883-
# For non-LTO, '-mllvm -wasm-enable-eh' added in
884-
# building.llvm_backend_args() sets this feature in clang. But in LTO, the
885-
# argument is added to wasm-ld instead, so clang needs to know that EH is
886-
# enabled so that it can be added to the attributes in LLVM IR.
887-
if settings.SUPPORT_LONGJMP == 'wasm':
888-
cflags.append('-mexception-handling')
889-
890-
else:
891-
# In LTO mode these args get passed instead at link time when the backend runs.
892-
for a in building.llvm_backend_args():
893-
cflags += ['-mllvm', a]
894-
895902
# Changes to default clang behavior
896903

897904
# Implicit functions can cause horribly confusing function pointer type errors, see #2175
@@ -1045,7 +1052,7 @@ def run(args):
10451052
if len(args) == 2 and args[1] == '-v':
10461053
# autoconf likes to see 'GNU' in the output to enable shared object support
10471054
print(version_string(), file=sys.stderr)
1048-
return shared.check_call([clang, '-v'] + get_clang_flags(), check=False).returncode
1055+
return shared.check_call([clang, '-v'] + get_target_flags(), check=False).returncode
10491056

10501057
# Additional compiler flags that we treat as if they were passed to us on the
10511058
# commandline
@@ -2709,8 +2716,11 @@ def get_compiler(src_file):
27092716
def get_clang_command(src_file):
27102717
return get_compiler(src_file) + get_cflags(state.orig_args) + compile_args + [src_file]
27112718

2719+
def get_clang_command_preprocessed(src_file):
2720+
return get_compiler(src_file) + get_clang_flags(state.orig_args) + compile_args + [src_file]
2721+
27122722
def get_clang_command_asm(src_file):
2713-
return get_compiler(src_file) + get_clang_flags() + compile_args + [src_file]
2723+
return get_compiler(src_file) + get_target_flags() + compile_args + [src_file]
27142724

27152725
# preprocessor-only (-E) support
27162726
if state.mode == Mode.PREPROCESS_ONLY:
@@ -2765,6 +2775,8 @@ def compile_source_file(i, input_file):
27652775
linker_inputs.append((i, output_file))
27662776
if get_file_suffix(input_file) in ASSEMBLY_ENDINGS:
27672777
cmd = get_clang_command_asm(input_file)
2778+
elif get_file_suffix(input_file) in PREPROCESSED_ENDINGS:
2779+
cmd = get_clang_command_preprocessed(input_file)
27682780
else:
27692781
cmd = get_clang_command(input_file)
27702782
if not state.has_dash_c:

tools/ports/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ def add_cflags(args, settings): # noqa: U100
355355

356356
# Legacy SDL1 port is not actually a port at all but builtin
357357
if settings.USE_SDL == 1:
358-
args += ['-Xclang', '-iwithsysroot/include/SDL']
358+
args += ['-I' + Ports.get_include_dir('SDL')]
359359

360360
needed = get_needed_ports(settings)
361361

tools/ports/sdl2.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ def create(final):
6969
o = os.path.join(ports.get_build_dir(), 'sdl2', 'src', src + '.o')
7070
shared.safe_ensure_dirs(os.path.dirname(o))
7171
command = [shared.EMCC,
72+
'-sUSE_SDL=0',
7273
'-c', os.path.join(ports.get_dir(), 'sdl2', SUBDIR, 'src', src),
7374
'-o', o, '-I' + ports.get_include_dir('SDL2'),
7475
'-O2', '-w']
@@ -91,8 +92,7 @@ def linker_setup(ports, settings):
9192

9293

9394
def process_args(ports):
94-
# TODO(sbc): remove this
95-
return ['-Xclang', '-isystem' + ports.get_include_dir('SDL2')]
95+
return ['-I' + ports.get_include_dir('SDL2')]
9696

9797

9898
def show():

0 commit comments

Comments
 (0)