Skip to content

Commit

Permalink
Use CMake
Browse files Browse the repository at this point in the history
  • Loading branch information
zachasme committed Sep 20, 2022
1 parent 75d5860 commit e599663
Show file tree
Hide file tree
Showing 20 changed files with 502 additions and 212 deletions.
59 changes: 59 additions & 0 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Windows

on:
push:
branches: [cmake]
pull_request:
branches: [cmake]

# https://github.com/actions/virtual-environments/blob/main/images/win/Windows2019-Readme.md
jobs:
tests:
strategy:
matrix:
#os: [ubuntu-latest, windows-latest, macos-latest]
os: [ubuntu-22.04, windows-2022]
#config: [Release, Debug]
config: [Release]

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

steps:
- uses: actions/checkout@v2

- name: Install PostgreSQL server headers
run: |
sudo apt update
sudo apt-get install postgresql-server-dev-14
if: runner.os == 'Linux'

- name: Configure PATH
run: echo "$PGBIN" >> $GITHUB_PATH
if: runner.os == 'Windows'

- name: Generate
run: cmake -B build .

- name: Build
working-directory: build
run: cmake --build . --config ${{ matrix.config }}

- name: Install with sudo
working-directory: build
run: sudo cmake --install . --component extension --config ${{ matrix.config }}
if: runner.os == 'Linux'

- name: Install without sudo
working-directory: build
run: cmake --install . --component extension --config ${{ matrix.config }}
if: runner.os == 'Windows'

- name: Test
continue-on-error: true
run: |
ctest --output-on-failure --build-config ${{ matrix.config }}
cat D:/a/h3-pg/h3-pg/build/log/initdb.log
defaults:
run:
shell: bash
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
build

# C
*.o
*.bc
Expand Down
56 changes: 56 additions & 0 deletions .tmp-tools/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
ARG UBUNTU=focal
FROM ubuntu:${UBUNTU}
ARG UBUNTU

# set timezone
RUN ln --symbolic --no-dereference --force \
/usr/share/zoneinfo/Europe/Copenhagen /etc/localtime

RUN apt-get update && apt-get install -y \
build-essential \
#cmake \
git \
pgxnclient

# H3 requires CMake 3.20, which has not landed in ubuntu
# as of writing. So we setup cmake apt repository
RUN if [ "$UBUNTU" != "impish" ] ; then apt-key adv --fetch-keys https://apt.kitware.com/keys/kitware-archive-latest.asc ; fi
RUN if [ "$UBUNTU" != "impish" ] ; then echo "deb https://apt.kitware.com/ubuntu/ ${UBUNTU} main" >> /etc/apt/sources.list.d/pgdg.list ; fi
RUN apt-get update && apt-get install -y cmake
# we can remove the block above when 3.20 lands

# setup postgresql apt repository
RUN apt-key adv --fetch-keys https://www.postgresql.org/media/keys/ACCC4CF8.asc
RUN echo "deb http://apt.postgresql.org/pub/repos/apt/ ${UBUNTU}-pgdg main" >> /etc/apt/sources.list.d/pgdg.list

ARG POSTGRESQL=14
ARG POSTGIS=3

# install postgresql and postgis
RUN apt-get update && apt-get install -y \
postgresql-${POSTGRESQL}-postgis-${POSTGIS}-scripts \
postgresql-${POSTGRESQL}-postgis-${POSTGIS} \
postgresql-server-dev-${POSTGRESQL} \
postgresql-${POSTGRESQL}

# install pg_validate_extupgrade
RUN apt-get update && apt install -y cargo
RUN git clone https://github.com/rjuju/pg_validate_extupgrade.git
WORKDIR pg_validate_extupgrade
RUN cargo fetch --locked
RUN RUSTUP_TOOLCHAIN=stable CARGO_TARGET_DIR=target \
cargo build --frozen --release --all-features
RUN ./target/release/pg_validate_extupgrade --version
RUN cp ./target/release/pg_validate_extupgrade /usr/bin/
# For some reason i need this to run pg_validate_extupgrade
RUN echo "local all postgres peer" > /etc/postgresql/${POSTGRESQL}/main/pg_hba.conf
RUN echo "host all all 0.0.0.0/0 trust" >> /etc/postgresql/${POSTGRESQL}/main/pg_hba.conf

# install sudo
RUN apt-get update && apt-get install -y \
sudo

# run it!
WORKDIR /github/workspace
COPY entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
14 changes: 14 additions & 0 deletions .tmp-tools/build-with-cmake.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash
set -e
set -u


BASEDIR=$(dirname $(realpath "$0"))

cd $BASEDIR

sudo rm -rf ../build
mkdir ../build

docker build -t tmp .
docker run --rm -v "$PWD"/..:/github/workspace tmp
23 changes: 23 additions & 0 deletions .tmp-tools/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env sh
set -e

chmod -R a+w build

service postgresql start


# first regular cmake
su postgres -p -c "cmake -B build ."

cd build
su postgres -p -c "cmake --build . --config Release"
cmake --install . --component extension # sudo
su postgres -p -c "ctest --output-on-failure"

cd ..
rm -rf build

# also try makefile pgxn wrapper
#sudo -u postgres make all
#make install # sudo
#sudo -u postgres make test
18 changes: 18 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
cmake_minimum_required(VERSION 3.14) # FetchContent_MakeAvailable (CMake 3.14)

project(h3-pg VERSION 4.0.1
DESCRIPTION "Bindings for H3"
LANGUAGES C)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

# enable testing and set BUILD_TESTING if no parent project
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
message(STATUS "Testing enabled")
include(CTest)
endif()

find_package(PostgreSQL REQUIRED)

add_subdirectory(h3)
add_subdirectory(h3_postgis)
Loading

0 comments on commit e599663

Please sign in to comment.