Skip to content

Commit

Permalink
feat: static link to libc++
Browse files Browse the repository at this point in the history
  • Loading branch information
wu-vincent committed Mar 14, 2024
1 parent 2a2374d commit 11ae28c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 19 deletions.
25 changes: 9 additions & 16 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
- name: Upload Artifacts
uses: actions/upload-artifact@v4
with:
name: endstone-cpp-plugin-windows
name: example-plugin-windows
path: ./build/*.dll

build_linux:
Expand All @@ -46,28 +46,21 @@ jobs:
- name: Checkout Code
uses: actions/checkout@v4

- name: Set up Clang 15
- name: Set up Clang 11
env:
LLVM_VERSION: 15
LLVM_VERSION: 11
run: |
sudo apt-get update -y -q
sudo apt-get install -y -q lsb-release wget software-properties-common gnupg
sudo wget https://apt.llvm.org/llvm.sh
sudo chmod +x llvm.sh
sudo ./llvm.sh ${LLVM_VERSION}
sudo apt-get install -y -q libc++-${LLVM_VERSION}-dev libc++abi-${LLVM_VERSION}-dev
sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-${LLVM_VERSION} 100
sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-${LLVM_VERSION} 100
sudo update-alternatives --install /usr/bin/llvm-cov llvm-cov /usr/bin/llvm-cov-${LLVM_VERSION} 100
sudo update-alternatives --install /usr/bin/ld ld /usr/bin/ld.lld-${LLVM_VERSION} 100
sudo wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
sudo apt-get update
sudo apt-get install -y -q clang-${LLVM_VERSION} libc++-${LLVM_VERSION}-dev libc++abi-${LLVM_VERSION}-dev
sudo update-alternatives --install /usr/bin/cc cc /usr/bin/clang-${LLVM_VERSION} 100
sudo update-alternatives --install /usr/bin/c++ c++ /usr/bin/clang++-${LLVM_VERSION} 100
- name: Set up CMake and Ninja
uses: lukka/get-cmake@latest

- name: Build with CMake
run: |
export CC=/usr/bin/clang
export CXX=/usr/bin/clang++
mkdir build
cd build
cmake -G Ninja -DCMAKE_BUILD_TYPE=Release ..
Expand All @@ -76,5 +69,5 @@ jobs:
- name: Upload Artifacts
uses: actions/upload-artifact@v4
with:
name: endstone-cpp-plugin-linux
name: example-plugin-linux
path: ./build/*.so
7 changes: 4 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ project(endstone_example_plugin CXX)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)

add_compile_definitions(_ITERATOR_DEBUG_LEVEL=0)

Expand All @@ -20,7 +19,6 @@ elseif (UNIX)
if (NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang")
message(FATAL_ERROR "Clang is required on Linux.")
endif ()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
else ()
message(FATAL_ERROR "${CMAKE_SYSTEM_NAME} (${CMAKE_SYSTEM_PROCESSOR}) is not supported")
endif ()
Expand Down Expand Up @@ -62,7 +60,10 @@ target_link_libraries(endstone_headers INTERFACE fmt::fmt)
add_library(${PROJECT_NAME} SHARED src/example_plugin.cpp)
target_include_directories(${PROJECT_NAME} PUBLIC include)
target_link_libraries(${PROJECT_NAME} PRIVATE endstone::headers)

if (UNIX)
target_link_options(${PROJECT_NAME} PRIVATE -stdlib=libc++ -static-libstdc++ -static-libgcc -fPIC)
target_link_libraries(${PROJECT_NAME} PRIVATE libc++abi.a)
endif ()

# ===============
# Install
Expand Down

0 comments on commit 11ae28c

Please sign in to comment.