libsdl-org / SDL

Simple Directmedia Layer
https://libsdl.org
zlib License
9.79k stars 1.82k forks source link

Can't build with clang-cl, error inlining sss3 intrinsic function #6214

Closed jonesmz closed 5 months ago

jonesmz commented 2 years ago

See github action run: https://github.com/jonesmz/osp-magnum/runs/8295514550

D:\a\osp-magnum\osp-magnum\3rdparty\SDL2\src\audio\SDL_audiocvt.c(113,39): error : always_inline function '_mm_hadd_ps' requires target feature 'sse3', but would be inlined into function 'SDL_ConvertStereoToMono_SSE3' that is compiled without support for 'sse3' [D:\a\osp-magnum\osp-magnum\build\3rdparty\SDL2\SDL2.vcxproj]

I'm trying to build my project with clang-cl like this

jobs:
  build:
    strategy:
      fail-fast: false
      matrix:
        compiler: [msvc, clangcl]
        config: [Release, Debug]
        image: [windows-2019, windows-2022]

    runs-on: ${{ matrix.image }}

    steps:
    - uses: actions/checkout@v3
      with:
        fetch-depth: 1
        submodules: recursive

    # Don't change this to use v1. It doesn't work correctly with the github "major version" auto-magic
    - uses: hendrikmuhs/ccache-action@v1.2
      with:
        Key: windows-${{ matrix.image }}-${{ matrix.config }}

    - uses: honeybunch/setup-mingw@v3
      if: ${{ matrix.compiler == 'mingw' }}

    - uses: egor-tensin/setup-clang@v1
      if: ${{ matrix.compiler == 'clang' }}

    - uses: ashutoshvarma/setup-ninja@v1.1
      if: ${{ matrix.compiler == 'clang' }}

    - name: Configure (MSVC)
      if: ${{ matrix.compiler == 'msvc' }}
      run: |
        cmake -B build -DCMAKE_CONFIGURATION_TYPES=${{ matrix.config }}

    - name: Configure (ClangCL)
      if: ${{ matrix.compiler == 'clangcl' }}
      run: |
        cmake -B build -DCMAKE_CONFIGURATION_TYPES=${{ matrix.config }} -TClangCL

    - name: Compile Dependencies
      run: |
        cmake --build build --parallel --config ${{ matrix.config }} --target compile-osp-magnum-deps compile-test-deps

    - name: Compile OSP-Magnum
      run: |
        cmake --build build --parallel --config ${{ matrix.config }} --target osp-magnum

    - name: Compile Unit Tests
      run: |
        cmake --build build --parallel --config ${{ matrix.config }} --target compile-tests

    # MSVC Generator doesn't support the special target "test" like Ninja generator does on linux.
    - name: Run Unit Tests
      run: |
        ctest --schedule-random --progress --output-on-failure --parallel --no-tests error --build-config ${{ matrix.config }} --test-dir build

    - uses: actions/upload-artifact@v2
      with:
        name: OSP-${{ matrix.image }}-${{ matrix.config }}-${{ matrix.compiler }}

SDL is being configured like:

  # This is the most minimal set of features which still make Sdl2Application
  # work. If you need something from these, remove the setting. The SDL_AUDIO
  # option (and SDL_DLOPEN) should not be needed either as Magnum doesn't use it,
  # but if it's disabled it causes linker errors. Needs further investigation.
  SET(SDL_ATOMIC            OFF CACHE BOOL "" FORCE)
  SET(SDL_CPUINFO           OFF CACHE BOOL "" FORCE)
  SET(SDL_FILESYSTEM        OFF CACHE BOOL "" FORCE)
  SET(SDL_HAPTIC            OFF CACHE BOOL "" FORCE)
  SET(SDL_LOCALE            OFF CACHE BOOL "" FORCE)
  SET(SDL_POWER             OFF CACHE BOOL "" FORCE)
  SET(SDL_RENDER            OFF CACHE BOOL "" FORCE)
  SET(SDL_SENSOR            OFF CACHE BOOL "" FORCE)
  SET(SDL_TIMERS            OFF CACHE BOOL "" FORCE)
  SET(SDL_ALTIVEC           OFF CACHE BOOL "" FORCE) # POWERPC exclusive, not supported by osp-magnum
  SET(SDL_3DNOW             OFF CACHE BOOL "" FORCE) # Old 32bit x86 chips only, not supported by osp-magnum.
  SET(SDL_MMX               OFF CACHE BOOL "" FORCE) # Old. Superceeded by SSE1, not supported by osp-magnum.
  SET(SDL_ASSEMBLY          OFF CACHE BOOL "" FORCE) # Presumably not actually needed. Lets try more for portability than speed...

  ##
  # SDL Audio backend settings
  ##
  SET(SDL_AUDIO             ON  CACHE BOOL "" FORCE)

  # Enabled audio settings
  SET(SDL_PULSEAUDIO        ON  CACHE BOOL "" FORCE) # Most linux systems use pulseaudio
  SET(SDL_PULSEAUDIO_SHARED OFF CACHE BOOL "" FORCE) # Don't need dynamic lib support for pulse, yet

  # Disabled audio settings
  SET(SDL_PIPEWIRE          OFF CACHE BOOL "" FORCE)
  SET(SDL_PIPEWIRE_SHARED   OFF CACHE BOOL "" FORCE)
  SET(SDL_ALSA              OFF CACHE BOOL "" FORCE)
  SET(SDL_ALSA_SHARED       OFF CACHE BOOL "" FORCE)
  SET(SDL_JACK              OFF CACHE BOOL "" FORCE)
  SET(SDL_JACK_SHARED       OFF CACHE BOOL "" FORCE)
  SET(SDL_DISKAUDIO         OFF CACHE BOOL "" FORCE)
  SET(SDL_DISKAUDIO_SHARED  OFF CACHE BOOL "" FORCE)
  SET(SDL_SNDIO             OFF CACHE BOOL "" FORCE)
  SET(SDL_SNDIO_SHARED      OFF CACHE BOOL "" FORCE)
  SET(SDL_DUMMYAUDIO        OFF CACHE BOOL "" FORCE)
  SET(SDL_DUMMYAUDIO_SHARED OFF CACHE BOOL "" FORCE)
  SET(SDL_ESD               OFF CACHE BOOL "" FORCE)
  SET(SDL_ESD_SHARED        OFF CACHE BOOL "" FORCE)
  SET(SDL_ARTS              OFF CACHE BOOL "" FORCE)
  SET(SDL_ARTS_SHARED       OFF CACHE BOOL "" FORCE)
  SET(SDL_NAS               OFF CACHE BOOL "" FORCE)
  SET(SDL_NAS_SHARED        OFF CACHE BOOL "" FORCE)
  SET(SDL_OSS               OFF CACHE BOOL "" FORCE)
  SET(SDL_OSS_SHARED        OFF CACHE BOOL "" FORCE)
  SET(SDL_WASAPI            OFF CACHE BOOL "" FORCE) # Windows Audio Session API : Is this really needed?

  ##
  # SDL Video backend settings
  ##
  SET(SDL_VIDEO              ON  CACHE BOOL "" FORCE)

  # Enabled video settings
  SET(SDL_OPENGL             ON  CACHE BOOL "" FORCE)

  # Disabled video settings
  SET(SDL_DUMMYVIDEO         OFF CACHE BOOL "" FORCE)
  SET(SDL_VULKAN             OFF CACHE BOOL "" FORCE) # Vulkan is cool and all, but one project at a time.
  SET(SDL_OPENGLES           OFF CACHE BOOL "" FORCE)
  SET(SDL_DIRECTFB           OFF CACHE BOOL "" FORCE)
  SET(SDL_DIRECTX            OFF CACHE BOOL "" FORCE) # DirectX is windows specific. Lets stick with multiplatform.
  SET(SDL_RENDER_D3D         OFF CACHE BOOL "" FORCE) # Ancient DirectX?
  if(NOT APPLE)
    SET(SDL_COCOA              OFF CACHE BOOL "" FORCE) # Cocoa is mac specific. Lets stick with multiplatform.
    SET(SDL_METAL              OFF CACHE BOOL "" FORCE) # Metal is mac specific. Lets stick with multiplatform.
    SET(SDL_RENDER_METAL       OFF CACHE BOOL "" FORCE) # Metal is mac specific. Lets stick with multiplatform.
  endif()
  SET(SDL_RPI                OFF CACHE BOOL "" FORCE) # Raspberry PI is not multiplatform. It supports OpenGL.
  SET(SDL_WAYLAND            OFF CACHE BOOL "" FORCE)
  SET(SDL_WAYLAND_QT_TOUCH   OFF CACHE BOOL "" FORCE)
  SET(SDL_KMSDRM             OFF CACHE BOOL "" FORCE)

  SET(SDL_FILE               ON  CACHE BOOL "" FORCE) # Needed for Mac OSX
  SET(SDL_LOADSO             ON  CACHE BOOL "" FORCE)

  SET(SDL_JOYSTICK           ON  CACHE BOOL "" FORCE)
  SET(SDL_VIRTUAL_JOYSTICK   ON  CACHE BOOL "" FORCE)

  SET(LIBSAMPLERATE          ON  CACHE BOOL "" FORCE)
  SET(LIBSAMPLERATE_SHARED   ON  CACHE BOOL "" FORCE)

  SET(SDL_EVENTS             ON  CACHE BOOL "" FORCE)
  SET(SDL_THREADS            ON  CACHE BOOL "" FORCE)

  # This assumes you want to have SDL as a static library. If not, set SDL_STATIC
  # to OFF instead.
  SET(SDL_DLOPEN ON  CACHE BOOL "" FORCE)
  SET(SDL_SHARED ON  CACHE BOOL "" FORCE)
  SET(SDL_STATIC OFF CACHE BOOL "" FORCE)

  ADD_SUBDIRECTORY(SDL2 EXCLUDE_FROM_ALL)

SDL2 is at tag prerelease-2.23.1, which I can't move past just yet due to another third party dependency (working on it...).

slouken commented 2 years ago

@icculus, this might be part of the cpuinfo inline intrinsics cleanup we have on the TODO list.

Basically clang doesn't have a way to include support for intrinsics without allowing the compiler to generally use the instruction set, so even though we check to see if SSE3 is supported, clang doesn't know that and doesn't allow the instruction.

@jonesmz, in the meantime, you will probably have to add clang compiler architecture options to allow SSE if that works for your product, or edit SDL_cpuinfo.h to remove SSE capability.

icculus commented 2 years ago

Yeah, this is the same problem we're having with Intel's C++ compiler (which is also just clang afaik).

This is still meant to get reworked for SDL3, which I really want to branch off for soon.

jonesmz commented 2 years ago

Understood. Thank you for the advice.

icculus commented 5 months ago

I believe we have fixed this, between moving intrinsic headers to a separate include and adding the SDL_TARGETING macro; plus I think we're building with clang-cl on GitHub Actions...?

This should be resolved for SDL3; please let us know if it isn't!