Skip to content

Commit b562271

Browse files
authored
[OSRM] Add build recipe (#12743)
1 parent be43cc4 commit b562271

File tree

1 file changed

+194
-0
lines changed

1 file changed

+194
-0
lines changed

O/OSRM/build_tarballs.jl

Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
# Note that this script can accept some limited command-line arguments, run
2+
# `julia build_tarballs.jl --help` to see a usage message.
3+
using BinaryBuilder, Pkg
4+
5+
include(joinpath("..", "..", "platforms", "macos_sdks.jl"))
6+
7+
name = "OSRM"
8+
version = v"6.0.0"
9+
10+
# Collection of sources required to complete build
11+
sources = [
12+
GitSource("https://github.com/Project-OSRM/osrm-backend.git", "01605f7589e6fe68df3fc690ad001b687128aba7"),
13+
get_macos_sdk_sources("14.5")...
14+
]
15+
16+
script = raw"""
17+
cd ${WORKSPACE}/srcdir/osrm-backend
18+
19+
# Common cmake flags
20+
CMAKE_FLAGS=(
21+
-DCMAKE_INSTALL_PREFIX=${prefix}
22+
-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TARGET_TOOLCHAIN}
23+
-DCMAKE_BUILD_TYPE=Release
24+
-DCMAKE_CXX_STANDARD=20
25+
-DCMAKE_PREFIX_PATH=${prefix}
26+
-DBUILD_SHARED_LIBS=ON
27+
-DBUILD_TESTING=OFF
28+
)
29+
30+
# Linux specific handling
31+
if [[ "${target}" == *-linux-* ]]; then
32+
### CMake flags
33+
CMAKE_FLAGS+=(-DCMAKE_CXX_FLAGS="-Wno-array-bounds -Wno-uninitialized -Wno-error")
34+
35+
if [[ "${target}" == *-linux-musl* ]]; then
36+
### OSRM-backend Patching
37+
sed -i 's/-Wpedantic/-Wno-pedantic/g; s/-Werror=pedantic/-Wno-error=pedantic/g' CMakeLists.txt
38+
39+
### CMake flags
40+
CMAKE_FLAGS+=(
41+
-DOSRM_HAS_STD_FORMAT_EXITCODE=0
42+
-DOSRM_HAS_STD_FORMAT_EXITCODE__TRYRUN_OUTPUT=""
43+
)
44+
fi
45+
fi
46+
47+
# Apple specific handling
48+
if [[ "${target}" == *-apple-darwin* ]]; then
49+
### SDK extraction
50+
apple_sdk_root=$WORKSPACE/srcdir/MacOSX14.5.sdk
51+
mkdir -p "$apple_sdk_root"
52+
echo "Extracting MacOSX14.5.tar.xz (this may take a while)"
53+
tar --extract --file=${WORKSPACE}/srcdir/MacOSX14.5.tar.xz --directory="$apple_sdk_root" --strip-components=1 --warning=no-unknown-keyword MacOSX14.5.sdk/System MacOSX14.5.sdk/usr
54+
sed -i "s!/opt/$target/$target/sys-root!$apple_sdk_root!" $CMAKE_TARGET_TOOLCHAIN
55+
sed -i "s!/opt/$target/$target/sys-root!$apple_sdk_root!" /opt/bin/$bb_full_target/$target-clang++
56+
export MACOSX_DEPLOYMENT_TARGET=14.5
57+
58+
### OSRM-backend Patching
59+
# Exclude duplicate intersection files from GUIDANCE for platforms that link to EXTRACTOR
60+
sed -i 's|file(GLOB GuidanceGlob src/guidance/\*\.cpp src/extractor/intersection/\*\.cpp)|file(GLOB GuidanceGlob src/guidance/*.cpp)|' CMakeLists.txt
61+
# Replace the osrm_guidance library definition with version that links to EXTRACTOR
62+
sed -i '/^add_library(osrm_guidance $<TARGET_OBJECTS:GUIDANCE> $<TARGET_OBJECTS:UTIL>)$/c\
63+
add_library(osrm_guidance $<TARGET_OBJECTS:GUIDANCE> $<TARGET_OBJECTS:UTIL> $<TARGET_OBJECTS:MICROTAR>)\
64+
target_link_libraries(osrm_guidance PRIVATE EXTRACTOR ${LUA_LIBRARIES} BZip2::BZip2 ZLIB::ZLIB EXPAT::EXPAT Boost::iostreams TBB::tbb)' CMakeLists.txt
65+
66+
### CMake flags
67+
CMAKE_FLAGS+=(
68+
-DENABLE_LTO=OFF
69+
-DCMAKE_EXE_LINKER_FLAGS="-L${libdir} -ltbb -lz"
70+
-DCMAKE_SHARED_LINKER_FLAGS="-L${libdir} -ltbb -lz"
71+
-DBoost_DIR=${libdir}/cmake/Boost-1.87.0/
72+
-DTBB_DIR=${libdir}/cmake/TBB
73+
-DLUA_LIBRARIES="${libdir}/liblua.dylib"
74+
-DLUA_INCLUDE_DIR="${includedir}"
75+
-DOSRM_HAS_STD_FORMAT_EXITCODE=0
76+
-DOSRM_HAS_STD_FORMAT_EXITCODE__TRYRUN_OUTPUT=""
77+
)
78+
fi
79+
80+
# Windows specific handling
81+
if [[ "${target}" == *-mingw* ]]; then
82+
### OSRM-backend Patching
83+
# Ensure console executables by stripping WIN32 from add_executable invocations
84+
find . -name "CMakeLists.txt" -o -name "*.cmake" | while read f; do
85+
sed -i '/add_executable(/,/)/{s/ WIN32//g;}' "$f"
86+
sed -i 's/add_executable(\([^ ]*\) WIN32 /add_executable(\1 /g' "$f"
87+
sed -i 's/add_executable(\([^ ]*\) WIN32)/add_executable(\1)/g' "$f"
88+
done
89+
# Remove rpath flag for Windows
90+
sed -i '/set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,origin")/d' CMakeLists.txt
91+
# Exclude duplicate intersection files from GUIDANCE for platforms that link to EXTRACTOR
92+
sed -i 's|file(GLOB GuidanceGlob src/guidance/\*\.cpp src/extractor/intersection/\*\.cpp)|file(GLOB GuidanceGlob src/guidance/*.cpp)|' CMakeLists.txt
93+
# Replace the osrm_guidance library definition with version that links to EXTRACTOR
94+
sed -i '/^add_library(osrm_guidance $<TARGET_OBJECTS:GUIDANCE> $<TARGET_OBJECTS:UTIL>)$/c\
95+
add_library(osrm_guidance $<TARGET_OBJECTS:GUIDANCE> $<TARGET_OBJECTS:UTIL> $<TARGET_OBJECTS:MICROTAR>)\
96+
target_link_libraries(osrm_guidance PRIVATE EXTRACTOR ${LUA_LIBRARIES} BZip2::BZip2 ZLIB::ZLIB EXPAT::EXPAT Boost::iostreams TBB::tbb)' CMakeLists.txt
97+
98+
### CMake flags
99+
LTO_FLAGS="-fno-lto"
100+
CMAKE_FLAGS+=(
101+
-DENABLE_LTO=OFF
102+
-DCMAKE_CXX_FLAGS="-Wno-array-bounds -Wno-uninitialized -Wno-unused-parameter -Wno-maybe-uninitialized ${LTO_FLAGS} -Wno-error -Wno-pedantic"
103+
-DCMAKE_CXX_FLAGS_RELEASE="-O3 -DNDEBUG ${LTO_FLAGS}"
104+
-DCMAKE_EXE_LINKER_FLAGS="${LTO_FLAGS} -Wl,-subsystem,console -L${libdir} -ltbb12 -lz"
105+
-DCMAKE_SHARED_LINKER_FLAGS="${LTO_FLAGS} -Wl,--export-all-symbols -L${libdir} -ltbb12 -lz"
106+
-DCMAKE_CXX_VISIBILITY_PRESET=default
107+
-DCMAKE_VISIBILITY_INLINES_HIDDEN=OFF
108+
-DCMAKE_SKIP_RPATH=ON
109+
-DOSRM_HAS_STD_FORMAT_EXITCODE=0
110+
-DOSRM_HAS_STD_FORMAT_EXITCODE__TRYRUN_OUTPUT=""
111+
-DBoost_DIR=${libdir}/cmake/Boost-1.87.0/
112+
-DTBB_DIR=${libdir}/cmake/TBB
113+
-DLUA_LIBRARIES="lua54"
114+
-DLUA_INCLUDE_DIR="${includedir}"
115+
)
116+
fi
117+
118+
mkdir build && cd build
119+
120+
cmake .. "${CMAKE_FLAGS[@]}"
121+
122+
cmake --build . --parallel ${nproc}
123+
cmake --install .
124+
125+
# Windows: Regenerate import library with proper symbols
126+
if [[ "${target}" == *-mingw* ]]; then
127+
if [ -f ${prefix}/bin/libosrm.dll ] && [ -f ${prefix}/lib/libosrm.dll.a ]; then
128+
cd ${prefix}/lib
129+
# Extract exported symbols from DLL - nm -D shows dynamically exported symbols
130+
nm -D ${prefix}/bin/libosrm.dll 2>/dev/null | awk '/^[0-9a-fA-F]+ [Tt] / {print $3}' > /tmp/libosrm.def
131+
if [ -s /tmp/libosrm.def ]; then
132+
# Create proper .def file format with EXPORTS header
133+
echo "EXPORTS" > /tmp/libosrm.def.tmp
134+
cat /tmp/libosrm.def >> /tmp/libosrm.def.tmp
135+
mv /tmp/libosrm.def.tmp /tmp/libosrm.def
136+
# Regenerate import library from .def file
137+
dlltool -d /tmp/libosrm.def -l libosrm.dll.a -D ${prefix}/bin/libosrm.dll
138+
rm -f /tmp/libosrm.def
139+
fi
140+
fi
141+
fi
142+
143+
cp -r ${WORKSPACE}/srcdir/osrm-backend/profiles ${prefix}/
144+
install_license "${WORKSPACE}/srcdir/osrm-backend/LICENSE.TXT"
145+
"""
146+
147+
platforms = supported_platforms()
148+
platforms = filter(p -> Sys.islinux(p) || Sys.isapple(p) || Sys.iswindows(p), platforms)
149+
platforms = expand_cxxstring_abis(platforms)
150+
151+
# The products that we will ensure are always built
152+
products = [
153+
ExecutableProduct("osrm-extract", :osrm_extract),
154+
ExecutableProduct("osrm-contract", :osrm_contract),
155+
ExecutableProduct("osrm-partition", :osrm_partition),
156+
ExecutableProduct("osrm-customize", :osrm_customize),
157+
ExecutableProduct("osrm-routed", :osrm_routed),
158+
ExecutableProduct("osrm-datastore", :osrm_datastore),
159+
ExecutableProduct("osrm-components", :osrm_components),
160+
LibraryProduct("libosrm", :libosrm; dont_dlopen=true), # Cannot be loaded in sandbox
161+
FileProduct("profiles/bicycle.lua", :bicycle_lua),
162+
FileProduct("profiles/car.lua", :car_lua),
163+
FileProduct("profiles/foot.lua", :foot_lua),
164+
FileProduct("profiles/lib/access.lua", :lib_access_lua),
165+
FileProduct("profiles/lib/maxspeed.lua", :lib_maxspeed_lua),
166+
FileProduct("profiles/lib/profile_debugger.lua", :lib_profile_debugger_lua),
167+
FileProduct("profiles/lib/set.lua", :lib_set_lua),
168+
FileProduct("profiles/lib/utils.lua", :lib_utils_lua),
169+
FileProduct("profiles/lib/destination.lua", :lib_destination_lua),
170+
FileProduct("profiles/lib/measure.lua", :lib_measure_lua),
171+
FileProduct("profiles/lib/relations.lua", :lib_relations_lua),
172+
FileProduct("profiles/lib/tags.lua", :lib_tags_lua),
173+
FileProduct("profiles/lib/way_handlers.lua", :lib_way_handlers_lua),
174+
FileProduct("profiles/lib/guidance.lua", :lib_guidance_lua),
175+
FileProduct("profiles/lib/pprint.lua", :lib_pprint_lua),
176+
FileProduct("profiles/lib/sequence.lua", :lib_sequence_lua),
177+
FileProduct("profiles/lib/traffic_signal.lua", :lib_traffic_signal_lua),
178+
]
179+
180+
# Dependencies that must be installed before this package can be built
181+
dependencies = [
182+
Dependency("boost_jll"; compat="=1.87.0"),
183+
Dependency("Lua_jll"; compat="~5.4.9"),
184+
Dependency("oneTBB_jll"; compat="2022.0.0"),
185+
Dependency("Expat_jll"; compat="2.6.5"),
186+
Dependency("XML2_jll"; compat="~2.14.1"),
187+
Dependency("libzip_jll"),
188+
Dependency("Bzip2_jll"),
189+
Dependency("Zlib_jll"),
190+
]
191+
192+
# Build the tarballs, and possibly a `build.jl` as well.
193+
build_tarballs(ARGS, name, version, sources, script, platforms, products, dependencies;
194+
julia_compat="1.10", preferred_gcc_version=v"13")

0 commit comments

Comments
 (0)