|
| 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 | +name = "MQLib" |
| 6 | +version = v"0.1.1" |
| 7 | + |
| 8 | +# Collection of sources required to complete build. |
| 9 | +sources = [ |
| 10 | + GitSource( |
| 11 | + "https://github.com/MQLib/MQLib.git", |
| 12 | + "585496274af5abb0849d0d47e135496b4688680b", |
| 13 | + ), |
| 14 | + # Provides the C ABI wrapper that is packaged as libmqlib_c_api. |
| 15 | + GitSource( |
| 16 | + "https://github.com/JuliaQUBO/MQLib.jl.git", |
| 17 | + "8b491876ef44b663e8fd04a48d262d72e73faff7", |
| 18 | + ), |
| 19 | +] |
| 20 | + |
| 21 | +# Bash recipe for building across all platforms. |
| 22 | +script = raw""" |
| 23 | +cd "${WORKSPACE}/srcdir" |
| 24 | +
|
| 25 | +MQLIB_SRC="${WORKSPACE}/srcdir/MQLib" |
| 26 | +MQLIB_C_HEADER="$(find "${WORKSPACE}/srcdir" -path '*/c_api/include/mqlib_c_api.h' -print -quit)" |
| 27 | +MQLIB_JL_SRC="${MQLIB_C_HEADER%/c_api/include/mqlib_c_api.h}" |
| 28 | +
|
| 29 | +if [[ ! -f "${MQLIB_JL_SRC}/c_api/src/mqlib_c_api.cpp" ]]; then |
| 30 | + echo "Could not find MQLib.jl C ABI sources" >&2 |
| 31 | + exit 1 |
| 32 | +fi |
| 33 | +
|
| 34 | +cd "${MQLIB_SRC}" |
| 35 | +make -j${nproc} |
| 36 | +install -Dvm 0755 bin/MQLib "${bindir}/MQLib${exeext}" |
| 37 | +install -Dvm 0644 \ |
| 38 | + "${MQLIB_JL_SRC}/c_api/include/mqlib_c_api.h" \ |
| 39 | + "${includedir}/mqlib_c_api.h" |
| 40 | +
|
| 41 | +mapfile -t MQLIB_LIBRARY_SOURCES < <(find src -name '*.cpp' ! -name main.cpp | sort) |
| 42 | +
|
| 43 | +if [[ "${target}" == *-mingw* ]]; then |
| 44 | + MQLIB_C_API_LIBRARY="${bindir}/libmqlib_c_api.${dlext}" |
| 45 | + MQLIB_C_API_SHARED_FLAGS=( |
| 46 | + -shared |
| 47 | + -Wl,--out-implib,"${libdir}/libmqlib_c_api.dll.a" |
| 48 | + ) |
| 49 | +elif [[ "${target}" == *-apple-darwin* ]]; then |
| 50 | + MQLIB_C_API_LIBRARY="${libdir}/libmqlib_c_api.${dlext}" |
| 51 | + MQLIB_C_API_SHARED_FLAGS=( |
| 52 | + -dynamiclib |
| 53 | + -Wl,-install_name,@rpath/libmqlib_c_api.${dlext} |
| 54 | + ) |
| 55 | +else |
| 56 | + MQLIB_C_API_LIBRARY="${libdir}/libmqlib_c_api.${dlext}" |
| 57 | + MQLIB_C_API_SHARED_FLAGS=(-shared) |
| 58 | +fi |
| 59 | +
|
| 60 | +"${CXX}" \ |
| 61 | + -std=c++11 \ |
| 62 | + -O2 \ |
| 63 | + -fPIC \ |
| 64 | + -DMQLIB_C_BUILD_SHARED \ |
| 65 | + -Iinclude \ |
| 66 | + -I"${MQLIB_JL_SRC}/c_api/include" \ |
| 67 | + "${MQLIB_LIBRARY_SOURCES[@]}" \ |
| 68 | + "${MQLIB_JL_SRC}/c_api/src/mqlib_c_api.cpp" \ |
| 69 | + "${MQLIB_C_API_SHARED_FLAGS[@]}" \ |
| 70 | + -o "${MQLIB_C_API_LIBRARY}" \ |
| 71 | + -lm |
| 72 | +""" |
| 73 | + |
| 74 | +# These are the platforms we will build for by default, unless further |
| 75 | +# platforms are passed in on the command line. |
| 76 | +platforms = expand_cxxstring_abis(supported_platforms()) |
| 77 | + |
| 78 | +# The products that we will ensure are always built. |
| 79 | +products = [ |
| 80 | + ExecutableProduct("MQLib", :MQLib), |
| 81 | + LibraryProduct("libmqlib_c_api", :libmqlib_c_api), |
| 82 | +] |
| 83 | + |
| 84 | +# Dependencies that must be installed before this package can be built. |
| 85 | +dependencies = [ |
| 86 | + Dependency("CompilerSupportLibraries_jll"; platforms = filter(!Sys.isapple, platforms)), |
| 87 | +] |
| 88 | + |
| 89 | +# Build the tarballs, and possibly a `build.jl` as well. |
| 90 | +build_tarballs( |
| 91 | + ARGS, |
| 92 | + name, |
| 93 | + version, |
| 94 | + sources, |
| 95 | + script, |
| 96 | + platforms, |
| 97 | + products, |
| 98 | + dependencies; |
| 99 | + julia_compat = "1.6", |
| 100 | +) |
0 commit comments