Skip to content

Commit 35197f4

Browse files
committed
Use regular -I include flag for SDL paths
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. As part of this I also refactored the generation of C flags such that we don't pass `-I` flags when building `.i`/`.ii` files. These files are considered to be already pre-processed and clang warns if you pass `-I` flags when compiling them.
1 parent ab96ffb commit 35197f4

File tree

3 files changed

+58
-45
lines changed

3 files changed

+58
-45
lines changed

emcc.py

Lines changed: 55 additions & 42 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

@@ -791,10 +792,6 @@ def array_contains_any_of(hay, needles):
791792
if n in hay:
792793
return True
793794

794-
# relaxed-simd implies simd128.
795-
if '-mrelaxed-simd' in user_args:
796-
user_args += ['-msimd128']
797-
798795
if array_contains_any_of(user_args, SIMD_INTEL_FEATURE_TOWER) or array_contains_any_of(user_args, SIMD_NEON_FLAGS):
799796
if '-msimd128' not in user_args:
800797
exit_with_error('Passing any of ' + ', '.join(SIMD_INTEL_FEATURE_TOWER + SIMD_NEON_FLAGS) + ' flags also requires passing -msimd128!')
@@ -825,10 +822,55 @@ def array_contains_any_of(hay, needles):
825822
return cflags + ['-Xclang', '-iwithsysroot' + os.path.join('/include', 'compat')]
826823

827824

828-
def get_clang_flags():
825+
def get_asm_flags():
829826
return ['-target', shared.get_llvm_target()]
830827

831828

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

834876

@@ -839,7 +881,7 @@ def get_cflags(user_args):
839881

840882
# Flags we pass to the compiler when building C/C++ code
841883
# We add these to the user's flags (newargs), but not when building .s or .S assembly files
842-
cflags = get_clang_flags()
884+
cflags = get_clang_flags(user_args)
843885

844886
if settings.EMSCRIPTEN_TRACING:
845887
cflags.append('-D__EMSCRIPTEN_TRACING__=1')
@@ -861,40 +903,6 @@ def get_cflags(user_args):
861903
'-D__EMSCRIPTEN_minor__=' + str(shared.EMSCRIPTEN_VERSION_MINOR),
862904
'-D__EMSCRIPTEN_tiny__=' + str(shared.EMSCRIPTEN_VERSION_TINY)]
863905

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

900908
# Implicit functions can cause horribly confusing function pointer type errors, see #2175
@@ -1048,7 +1056,7 @@ def run(args):
10481056
if len(args) == 2 and args[1] == '-v':
10491057
# autoconf likes to see 'GNU' in the output to enable shared object support
10501058
print(version_string(), file=sys.stderr)
1051-
return shared.check_call([clang, '-v'] + get_clang_flags(), check=False).returncode
1059+
return shared.check_call([clang, '-v'] + get_target_flags(), check=False).returncode
10521060

10531061
# Additional compiler flags that we treat as if they were passed to us on the
10541062
# commandline
@@ -2712,8 +2720,11 @@ def get_compiler(src_file):
27122720
def get_clang_command(src_file):
27132721
return get_compiler(src_file) + get_cflags(state.orig_args) + compile_args + [src_file]
27142722

2723+
def get_clang_command_preprocessed(src_file):
2724+
return get_compiler(src_file) + get_clang_flags(state.orig_args) + compile_args + [src_file]
2725+
27152726
def get_clang_command_asm(src_file):
2716-
return get_compiler(src_file) + get_clang_flags() + compile_args + [src_file]
2727+
return get_compiler(src_file) + get_asm_flags() + compile_args + [src_file]
27172728

27182729
# preprocessor-only (-E) support
27192730
if state.mode == Mode.PREPROCESS_ONLY:
@@ -2768,6 +2779,8 @@ def compile_source_file(i, input_file):
27682779
linker_inputs.append((i, output_file))
27692780
if get_file_suffix(input_file) in ASSEMBLY_ENDINGS:
27702781
cmd = get_clang_command_asm(input_file)
2782+
elif get_file_suffix(input_file) in PREPROCESSED_ENDINGS:
2783+
cmd = get_clang_command_preprocessed(input_file)
27712784
else:
27722785
cmd = get_clang_command(input_file)
27732786
if not state.has_dash_c:

tools/ports/__init__.py

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

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

359359
needed = get_needed_ports(settings)
360360

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)