Skip to content

Commit

Permalink
feat: fix build example with folly
Browse files Browse the repository at this point in the history
  • Loading branch information
devillove084 committed Nov 9, 2024
1 parent 84bcb0f commit 74afbfc
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 46 deletions.
2 changes: 0 additions & 2 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,3 @@
# In theory, your system GCC and libstdc++ should be able to compile everything here. In practice,
# you probably want these overrides, so they're enabled by default.
CXX = "clang++"
# CXXSTDLIB = "libc++"
#CXXFLAGS = "-std=gnu++2a -fcoroutines -stdlib=libc++"
157 changes: 115 additions & 42 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
name: CI

on:
push:
branches:
Expand All @@ -9,7 +8,7 @@ on:
- main

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_name }}
group: '${{ github.workflow }}-${{ github.ref }}-${{ github.event_name }}'
cancel-in-progress: true

jobs:
Expand All @@ -18,24 +17,38 @@ jobs:
steps:
- uses: actions/checkout@v4

# - name: Install deps
# run: sudo apt-get install libfmt-dev libgflags-dev

- name: Cache cargo registry
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
key: cargo-registry-${{ runner.os }}-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
cargo-registry-${{ runner.os }}-
- name: Cache cargo build
uses: actions/cache@v4
with:
path: target
key: cargo-build-${{ runner.os }}-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
cargo-build-${{ runner.os }}-
- name: Format
run: cargo fmt --all -- --check

- name: Clippy
working-directory: cxx-async
run: cargo clippy -- -D warnings

build:
runs-on: ${{ matrix.os }}
build_and_test_with_folly:
runs-on: ubuntu-latest
strategy:
matrix:
os:
- ubuntu-latest
# - macos-latest
# - windows-latest

steps:
- uses: actions/checkout@v4

Expand All @@ -48,17 +61,17 @@ jobs:
make \
gcc \
g++ \
clang \
autoconf \
automake \
libtool \
python3-pip \
ninja-build \
libgflags-dev \
libboost-all-dev \
libdouble-conversion-dev \
libevent-dev \
libgflags-dev \
libgoogle-glog-dev \
libboost-all-dev \
libssl-dev \
libunwind-dev \
liblz4-dev \
Expand All @@ -68,53 +81,113 @@ jobs:
binutils-dev \
libjemalloc-dev \
libiberty-dev
- name: Add environment variables
run: |
echo "PATH=$HOME/.local/bin:$PATH" >> $GITHUB_ENV
echo "CMAKE_PREFIX_PATH=$HOME/.local:$CMAKE_PREFIX_PATH" >> $GITHUB_ENV
echo "C_INCLUDE_PATH=$HOME/.local/include:$C_INCLUDE_PATH" >> $GITHUB_ENV
echo "CPLUS_INCLUDE_PATH=$HOME/.local/include:$CPLUS_INCLUDE_PATH" >> $GITHUB_ENV
echo "LIBRARY_PATH=$HOME/.local/lib:$LIBRARY_PATH" >> $GITHUB_ENV
echo "LD_LIBRARY_PATH=$HOME/.local/lib:$LD_LIBRARY_PATH" >> $GITHUB_ENV
echo "PKG_CONFIG_PATH=$HOME/.local/lib/pkgconfig:$PKG_CONFIG_PATH" >> $GITHUB_ENV
# Cache fmt
- name: Cache fmt
id: cache-fmt
uses: actions/cache@v4
with:
path: |
~/.local/include/fmt/**
~/.local/lib/libfmt*
key: fmt-${{ runner.os }}-v10.1.1

- name: Build fmt
- name: Build fmt if not cached
if: steps.cache-fmt.outputs.cache-hit != 'true'
run: |
git clone https://github.com/fmtlib/fmt.git && cd fmt
rm _build -rf; mkdir _build -p && cd _build
cmake .. -DCMAKE_CXX_COMPILER=/usr/bin/clang++ -DCMAKE_C_COMPILER=/usr/bin/clang -DFMT_TEST=OFF
cd /tmp/
git clone https://github.com/fmtlib/fmt.git
cd fmt
mkdir -p _build && cd _build
cmake .. \
-DFMT_TEST=OFF \
-DCMAKE_INSTALL_PREFIX=$HOME/.local \
-DCMAKE_POSITION_INDEPENDENT_CODE=TRUE
make -j$(nproc)
sudo make install
make install
sudo ldconfig
- name: Build fast_float
cd ../../
rm -rf /tmp/fmt
# Cache fast_float
- name: Cache fast_float
id: cache-fast_float
uses: actions/cache@v4
with:
path: |
~/.local/lib/libfast_float*
~/.local/include/fast_float/**
key: fast_float-${{ runner.os }}-v3.9.0

- name: Build fast_float if not cached
if: steps.cache-fast_float.outputs.cache-hit != 'true'
run: |
cd /tmp
git clone https://github.com/fastfloat/fast_float.git && cd fast_float
rm _build -rf; mkdir _build -p && cd _build
rm -rf _build; mkdir -p _build && cd _build
cmake .. -DCMAKE_CXX_COMPILER=/usr/bin/clang++ \
-DCMAKE_C_COMPILER=/usr/bin/clang \
-DCMAKE_INSTALL_PREFIX=$HOME/.local \
-DCMAKE_CXX_FLAGS="-O3" \
-DBUILD_SHARED_LIBS=TRUE \
-DBUILD_BENCHMARKS=OFF
make -j$(nproc)
sudo make install
make install
sudo ldconfig
cd ../../
rm -rf /tmp/fast_float
# Cache Folly
- name: Cache Folly
id: cache-folly
uses: actions/cache@v4
with:
path: |
~/.local/lib/libfolly**
~/.local/include/folly/**
key: folly-${{ runner.os }}-20241104

- name: Build Folly
- name: Build Folly if not cached
if: steps.cache-folly.outputs.cache-hit != 'true'
run: |
git clone https://github.com/facebook/folly.git
cd folly
rm _build -rf
mkdir _build && cd _build
cmake .. -DBUILD_SHARED_LIBS=ON \
-DCMAKE_CXX_COMPILER=/usr/bin/clang++ \
-DCMAKE_C_COMPILER=/usr/bin/clang \
-DCMAKE_POSITION_INDEPENDENT_CODE=ON \
-DBUILD_BENCHMARKS=OFF \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_CXX_STANDARD=20 \
-DCMAKE_CXX_STANDARD_REQUIRED=ON
cd /tmp
git clone https://github.com/facebook/folly.git && cd folly
git checkout v2024.11.04.00
rm -rf _build; mkdir _build && cd _build
cmake .. \
-DBUILD_SHARED_LIBS=ON \
-DCMAKE_INSTALL_PREFIX=$HOME/.local \
-DCMAKE_CXX_COMPILER=/usr/bin/clang++ \
-DCMAKE_C_COMPILER=/usr/bin/clang \
-DCMAKE_POSITION_INDEPENDENT_CODE=ON \
-DBUILD_TESTS=OFF \
-DBUILD_BENCHMARKS=OFF \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_CXX_STANDARD=20 \
-DCMAKE_CXX_STANDARD_REQUIRED=ON
make -j$(nproc)
sudo make install
make install
sudo ldconfig
cd ../
rm -rf /tmp/folly/
# - name: Install dependencies on linux
# if: matrix.os == 'ubuntu-latest'
# run: sudo apt-get install libfmt-dev libgflags-dev

- name: Copy dependencies to sys
run: |
sudo cp -r $HOME/.local/include/* /usr/include/
sudo cp -r $HOME/.local/lib/* /usr/lib/
sudo ldconfig
- name: Build
working-directory: cxx-async
run: |
cargo build
run: |
cargo build
13 changes: 13 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ resolver = "2"
members = [
"cxx-async",
"macro",
# "examples/cppcoro",
"examples/cppcoro",
"examples/folly",
]
1 change: 0 additions & 1 deletion cxx-async/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ features = ["thread-pool"]

[dependencies.link-cplusplus]
version = "1"
# features = ["libc++"]

[build-dependencies]
cxx-build = "1"
Expand Down

0 comments on commit 74afbfc

Please sign in to comment.