Skip to content

Commit

Permalink
Lua is now required
Browse files Browse the repository at this point in the history
We are moving to the flex output which always needs Lua. Making Lua
optional isn't useful any more and just makes code more complicated.
This commit makes Lua non-optional.
  • Loading branch information
joto committed Jun 15, 2024
1 parent c3b18c7 commit 8c5e1e2
Show file tree
Hide file tree
Showing 10 changed files with 121 additions and 206 deletions.
7 changes: 1 addition & 6 deletions .github/actions/build-and-test/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,7 @@ runs:

- name: configure
run: |
CMAKE_OPTIONS="-LA -DBUILD_TESTS=ON"
if [ -z "${LUA_VERSION}" ]; then
CMAKE_OPTIONS="$CMAKE_OPTIONS -DWITH_LUA=OFF"
else
CMAKE_OPTIONS="$CMAKE_OPTIONS -DWITH_LUAJIT=${LUAJIT_OPTION}"
fi
CMAKE_OPTIONS="-LA -DBUILD_TESTS=ON -DWITH_LUAJIT=${LUAJIT_OPTION}"
if [ -n "$WITH_PROJ" ]; then
CMAKE_OPTIONS="$CMAKE_OPTIONS -DWITH_PROJ=$WITH_PROJ"
fi
Expand Down
33 changes: 0 additions & 33 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -215,22 +215,6 @@ jobs:
- uses: ./.github/actions/ubuntu-prerequisites
- uses: ./.github/actions/build-and-test

ubuntu20-pg13-gcc10-release-nolua:
runs-on: ubuntu-20.04

env:
CC: gcc-10
CXX: g++-10
POSTGRESQL_VERSION: 13
POSTGIS_VERSION: 2.5
BUILD_TYPE: Release
PSYCOPG: 2

steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/ubuntu-prerequisites
- uses: ./.github/actions/build-and-test

ubuntu22-pg16-clang14-jit:
runs-on: ubuntu-22.04

Expand Down Expand Up @@ -323,23 +307,6 @@ jobs:
- uses: ./.github/actions/ubuntu-prerequisites
- uses: ./.github/actions/build-and-test

ubuntu22-pg16-gcc12-release-nolua:
runs-on: ubuntu-22.04

env:
CC: gcc-12
CXX: g++-12
EXTRA_FLAGS: -Wno-stringop-overread
POSTGRESQL_VERSION: 16
POSTGIS_VERSION: 3
BUILD_TYPE: Release
PSYCOPG: 2

steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/ubuntu-prerequisites
- uses: ./.github/actions/build-and-test

ubuntu22-pg16-clang15-cpp20:
runs-on: ubuntu-22.04

Expand Down
67 changes: 29 additions & 38 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ endif()

option(BUILD_TESTS "Build test suite" OFF)
option(BUILD_COVERAGE "Build with coverage" OFF)
option(WITH_LUA "Build with Lua support" ON)
option(WITH_LUAJIT "Build with LuaJIT support" OFF)
option(WITH_PROJ "Build with Projection support" ON)

Expand Down Expand Up @@ -184,23 +183,19 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src ${CMAKE_CURRENT_BINARY_DIR})
find_package(Osmium 2.17.3 REQUIRED COMPONENTS io)
include_directories(SYSTEM ${OSMIUM_INCLUDE_DIRS} ${PROTOZERO_INCLUDE_DIR} ${FMT_INCLUDE_DIR} ${CLI11_INCLUDE_DIR})

if (WITH_LUA)
if (WITH_LUAJIT)
message(STATUS "Building with LuaJIT support")
find_package(LuaJIT REQUIRED)
include_directories(SYSTEM ${LUAJIT_INCLUDE_DIR})
add_definitions(-DHAVE_LUAJIT=1)
else()
message(STATUS "Building with Lua support")
find_package(Lua REQUIRED)
include_directories(SYSTEM ${LUA_INCLUDE_DIR})
endif()
add_definitions(-DHAVE_LUA=1)
find_program(LUA_EXE NAMES lua lua5.4 lua5.3 lua5.2 lua5.1)
if (WITH_LUAJIT)
message(STATUS "Building with LuaJIT support")
find_package(LuaJIT REQUIRED)
include_directories(SYSTEM ${LUAJIT_INCLUDE_DIR})
add_definitions(-DHAVE_LUAJIT=1)
else()
message(STATUS "Building without Lua support")
message(STATUS "Building with Lua (but not LuaJIT) support")
find_package(Lua REQUIRED)
include_directories(SYSTEM ${LUA_INCLUDE_DIR})
endif()

find_program(LUA_EXE NAMES lua lua5.4 lua5.3 lua5.2 lua5.1)

find_package(Boost 1.50 REQUIRED)
include_directories(SYSTEM ${Boost_INCLUDE_DIR})

Expand Down Expand Up @@ -235,7 +230,7 @@ endif()

if (LUAJIT_FOUND)
list(APPEND LIBS ${LUAJIT_LIBRARIES})
elseif (LUA_FOUND)
else()
list(APPEND LIBS ${LUA_LIBRARIES})
endif()

Expand All @@ -257,28 +252,24 @@ target_link_libraries(osm2pgsql osm2pgsql_lib ${LIBS})
if (${POTRACE_LIBRARY} STREQUAL "POTRACE_LIBRARY-NOTFOUND" OR NOT OPENCV_CORE_FOUND)
message(STATUS "Did not find opencv and/or potrace library. Not building osm2pgsql-gen.")
else()
if (WITH_LUA)
message(STATUS "Found opencv and potrace library. Building osm2pgsql-gen.")
set(BUILD_GEN 1)
include_directories(SYSTEM ${POTRACE_INCLUDE_DIR})
add_executable(osm2pgsql-gen src/gen/osm2pgsql-gen.cpp
src/gen/canvas.cpp
src/gen/gen-base.cpp
src/gen/gen-create.cpp
src/gen/gen-discrete-isolation.cpp
src/gen/gen-rivers.cpp
src/gen/gen-tile-builtup.cpp
src/gen/gen-tile-raster.cpp
src/gen/gen-tile-sql.cpp
src/gen/gen-tile-vector.cpp
src/gen/gen-tile.cpp
src/gen/params.cpp
src/gen/raster.cpp
src/gen/tracer.cpp)
target_link_libraries(osm2pgsql-gen osm2pgsql_lib ${LIBS} ${POTRACE_LIBRARY} ${OpenCV_LIBS})
else()
message(STATUS "No Lua. Not building osm2pgsql-gen.")
endif()
message(STATUS "Found opencv and potrace library. Building osm2pgsql-gen.")
set(BUILD_GEN 1)
include_directories(SYSTEM ${POTRACE_INCLUDE_DIR})
add_executable(osm2pgsql-gen src/gen/osm2pgsql-gen.cpp
src/gen/canvas.cpp
src/gen/gen-base.cpp
src/gen/gen-create.cpp
src/gen/gen-discrete-isolation.cpp
src/gen/gen-rivers.cpp
src/gen/gen-tile-builtup.cpp
src/gen/gen-tile-raster.cpp
src/gen/gen-tile-sql.cpp
src/gen/gen-tile-vector.cpp
src/gen/gen-tile.cpp
src/gen/params.cpp
src/gen/raster.cpp
src/gen/tracer.cpp)
target_link_libraries(osm2pgsql-gen osm2pgsql_lib ${LIBS} ${POTRACE_LIBRARY} ${OpenCV_LIBS})
endif()

#############################################################
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ Required libraries are
* [OpenCV](https://opencv.org/) (Optional, for generalization only)
* [potrace](https://potrace.sourceforge.net/) (Optional, for generalization only)
* [PostgreSQL](https://www.postgresql.org/) client libraries
* [Lua](https://www.lua.org/) (Optional, used for Lua tag transforms
and the flex output)
* [Lua](https://www.lua.org/)
* [Python](https://python.org/) (only for running tests)
* [Psycopg](https://www.psycopg.org/) (only for running tests)

Expand Down
120 changes: 58 additions & 62 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,71 +5,67 @@ add_library(osm2pgsql_lib STATIC)
# binaries that use it.
target_compile_features(osm2pgsql_lib PUBLIC cxx_std_17)

set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS
"${CMAKE_CURRENT_SOURCE_DIR}/init.lua")
file(READ "${CMAKE_CURRENT_SOURCE_DIR}/init.lua" LUA_INIT_CODE)
configure_file(lua-init.cpp.in lua-init.cpp @ONLY)

target_sources(osm2pgsql_lib PRIVATE
command-line-app.cpp
command-line-parser.cpp
db-copy.cpp
debug-output.cpp
expire-tiles.cpp
expire-output.cpp
geom.cpp
geom-box.cpp
geom-from-osm.cpp
geom-functions.cpp
geom-pole-of-inaccessibility.cpp
idlist.cpp
input.cpp
logging.cpp
middle.cpp
middle-pgsql.cpp
middle-ram.cpp
node-locations.cpp
node-persistent-cache.cpp
ordered-index.cpp
osmdata.cpp
output-null.cpp
output-pgsql.cpp
output.cpp
pgsql.cpp
pgsql-capabilities.cpp
pgsql-helper.cpp
progress-display.cpp
properties.cpp
reprojection.cpp
table.cpp
taginfo.cpp
tagtransform-c.cpp
tagtransform.cpp
tile.cpp
thread-pool.cpp
util.cpp
wildcmp.cpp
wkb.cpp
command-line-app.cpp
command-line-parser.cpp
db-copy.cpp
debug-output.cpp
expire-output.cpp
expire-tiles.cpp
flex-index.cpp
flex-lua-expire-output.cpp
flex-lua-geom.cpp
flex-lua-index.cpp
flex-lua-table.cpp
flex-table-column.cpp
flex-table.cpp
flex-write.cpp
geom-box.cpp
geom-from-osm.cpp
geom-functions.cpp
geom-pole-of-inaccessibility.cpp
geom.cpp
idlist.cpp
input.cpp
logging.cpp
lua-setup.cpp
lua-utils.cpp
middle-pgsql.cpp
middle-ram.cpp
middle.cpp
node-locations.cpp
node-persistent-cache.cpp
ordered-index.cpp
osmdata.cpp
output-flex.cpp
output-null.cpp
output-pgsql.cpp
output.cpp
pgsql-capabilities.cpp
pgsql-helper.cpp
pgsql.cpp
progress-display.cpp
properties.cpp
reprojection.cpp
table.cpp
taginfo.cpp
tagtransform-c.cpp
tagtransform-lua.cpp
tagtransform.cpp
thread-pool.cpp
tile.cpp
util.cpp
wildcmp.cpp
wkb.cpp
${CMAKE_CURRENT_BINARY_DIR}/lua-init.cpp
${PROJECT_BINARY_DIR}/src/version.cpp
)

if (WITH_LUA)
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS
"${CMAKE_CURRENT_SOURCE_DIR}/init.lua")
file(READ "${CMAKE_CURRENT_SOURCE_DIR}/init.lua" LUA_INIT_CODE)
configure_file(lua-init.cpp.in lua-init.cpp @ONLY)
target_sources(osm2pgsql_lib PRIVATE
flex-index.cpp
flex-table.cpp
flex-table-column.cpp
flex-lua-expire-output.cpp
flex-lua-geom.cpp
flex-lua-index.cpp
flex-lua-table.cpp
flex-write.cpp
lua-setup.cpp
lua-utils.cpp
output-flex.cpp
tagtransform-lua.cpp
${CMAKE_CURRENT_BINARY_DIR}/lua-init.cpp)
endif()

target_sources(osm2pgsql_lib PRIVATE ${PROJECT_BINARY_DIR}/src/version.cpp)

if (HAVE_PROJ6)
target_sources(osm2pgsql_lib PRIVATE reprojection-generic-proj6.cpp)
else()
Expand Down
8 changes: 0 additions & 8 deletions src/command-line-parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@

#include <CLI/CLI.hpp>

#ifdef HAVE_LUA
#include <lua.hpp>
#endif

#include <algorithm>
#include <cstdio>
Expand Down Expand Up @@ -118,15 +116,11 @@ void print_version()
fmt::print(stderr, "Compiled using the following library versions:\n");
fmt::print(stderr, "Libosmium {}\n", LIBOSMIUM_VERSION_STRING);
fmt::print(stderr, "Proj {}\n", get_proj_version());
#ifdef HAVE_LUA
#ifdef HAVE_LUAJIT
fmt::print(stderr, "{} ({})\n", LUA_RELEASE, LUAJIT_VERSION);
#else
fmt::print(stderr, "{}\n", LUA_RELEASE);
#endif
#else
fmt::print(stderr, "Lua support not included\n");
#endif
}

static void check_options_non_slim(CLI::App const &app)
Expand Down Expand Up @@ -446,15 +440,13 @@ options_t parse_command_line(int argc, char *argv[])
->description("Compute area column using Web Mercator coordinates.")
->group("Pgsql output options");

#ifdef HAVE_LUA
// --tag-transform-script
app.add_option("--tag-transform-script", options.tag_transform_script)
->description(
"Specify a Lua script to handle tag filtering and normalisation.")
->option_text("SCRIPT")
->check(CLI::ExistingFile)
->group("Pgsql output options");
#endif

// ----------------------------------------------------------------------
// Expire options
Expand Down
14 changes: 3 additions & 11 deletions src/output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,10 @@
#include "db-copy.hpp"
#include "format.hpp"
#include "options.hpp"
#include "output-flex.hpp"
#include "output-null.hpp"
#include "output-pgsql.hpp"

#ifdef HAVE_LUA
# include "output-flex.hpp"
static constexpr char const *const flex_backend = "flex, ";
#else
static constexpr char const *const flex_backend = "";
#endif

#include <stdexcept>
#include <string>
#include <utility>
Expand All @@ -36,21 +30,19 @@ output_t::create_output(std::shared_ptr<middle_query_t> const &mid,
options);
}

#ifdef HAVE_LUA
if (options.output_backend == "flex") {
return std::make_shared<output_flex_t>(mid, std::move(thread_pool),
options);
}
#endif

if (options.output_backend == "null") {
return std::make_shared<output_null_t>(mid, std::move(thread_pool),
options);
}

throw fmt_error("Output backend '{}' not recognised. Should be one of"
" [pgsql, {}null].",
options.output_backend, flex_backend);
" [pgsql, flex, null].",
options.output_backend);
}

output_t::output_t(std::shared_ptr<middle_query_t> mid,
Expand Down
Loading

0 comments on commit 8c5e1e2

Please sign in to comment.