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 31160f4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 20 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
9 changes: 5 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +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 @@ -16,11 +13,16 @@ if (WIN32)
if (NOT MSVC)
message(FATAL_ERROR "MSVC is required on Windows.")
endif ()
add_compile_definitions(_ITERATOR_DEBUG_LEVEL=0)
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++")
link_libraries("-static-libgcc -static-libstdc++")
link_libraries(libc++.a)
link_libraries(libc++abi.a)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
else ()
message(FATAL_ERROR "${CMAKE_SYSTEM_NAME} (${CMAKE_SYSTEM_PROCESSOR}) is not supported")
endif ()
Expand Down Expand Up @@ -63,7 +65,6 @@ add_library(${PROJECT_NAME} SHARED src/example_plugin.cpp)
target_include_directories(${PROJECT_NAME} PUBLIC include)
target_link_libraries(${PROJECT_NAME} PRIVATE endstone::headers)


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

0 comments on commit 31160f4

Please sign in to comment.