Skip to content

Commit

Permalink
igraph: add package (#6005)
Browse files Browse the repository at this point in the history
* igraph: add package

* test linux with bundle deps

* limit plat

* fix grammar error

* bison: fix msys install

* disable ccache

* force to use ninja

* fix cmake find libxml2 on windows

* patch bison codegen header missing

* fix patch checksum (crlf -> lf)

* use custom tarball (not need flex/bison)

* support cross-compilation

* test mingw cross-compilation

* Revert "test mingw cross-compilation"

This reverts commit 961a953.
  • Loading branch information
star-hengxing authored Dec 29, 2024
1 parent bf79554 commit 95aa0e9
Show file tree
Hide file tree
Showing 5 changed files with 150 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/b/bison/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ package("bison")
end
end)

on_install("@msys", function (package) end)

on_install("windows", function (package)
os.cp(path.join(package:dep("winflexbison"):installdir(), "*"), package:installdir())
os.rm(path.join(package:installdir(), "bin", "flex.exe"))
Expand Down
12 changes: 12 additions & 0 deletions packages/i/igraph/arith_osx.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/* Suitable for macOS on x86_64 and arm64 */
/* Not suitable for 32-bit macOS */

#define IEEE_8087
#define Arith_Kind_ASL 1
#define Long int
#define Intcast (int)(long)
#define Double_Align
#define X64_bit_pointers
#define NANCHECK
#define QNaN0 0x0
#define QNaN1 0x7ff80000
8 changes: 8 additions & 0 deletions packages/i/igraph/arith_win32.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/* Windows 32-bit */

#define IEEE_8087
#define Arith_Kind_ASL 1
#define Double_Align
#define NANCHECK
#define QNaN0 0x0
#define QNaN1 0x7ff80000
8 changes: 8 additions & 0 deletions packages/i/igraph/arith_win64.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/* Windows 32-bit */

#define IEEE_8087
#define Arith_Kind_ASL 1
#define Double_Align
#define NANCHECK
#define QNaN0 0x0
#define QNaN1 0x7ff80000
120 changes: 120 additions & 0 deletions packages/i/igraph/xmake.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
package("igraph")
set_homepage("https://igraph.org")
set_description("Library for the analysis of networks")
set_license("GPL-2.0")

add_urls("https://github.com/igraph/igraph/releases/download/$(version)/igraph-$(version).tar.gz",
"https://github.com/igraph/igraph.git")

add_versions("0.10.15", "03ba01db0544c4e32e51ab66f2356a034394533f61b4e14d769b9bbf5ad5e52c")

add_configs("glpk", {description = "Compile igraph with GLPK support", default = false, type = "boolean"})
add_configs("graphml", {description = "Compile igraph with GraphML support", default = false, type = "boolean"})
add_configs("openmp", {description = "Use OpenMP for parallelization", default = false, type = "boolean"})
if is_plat("wasm") then
add_configs("shared", {description = "Build shared library.", default = false, type = "boolean", readonly = true})
end

if is_plat("linux", "bsd") then
add_syslinks("pthread")
end

add_deps("cmake")
add_deps("plfit")

on_check(function (package)
if package:is_cross() then
if not package:is_plat("windows", "macosx") then
raise("package(igraph) unsupported cross-compilation now. To support it, see https://igraph.org/c/html/latest/igraph-Installation.html#igraph-Installation-cross-compiling")
end
end
end)

on_load(function (package)
if package:gitref() then
wprint("If build failed with flex/bison, please see https://github.com/igraph/igraph/issues/2713")
package:add("deps", "flex", "bison", {kind = "binary"})
end

-- TODO: unbundle deps gmp, arpack, blas, lapack
-- https://igraph.org/c/html/latest/igraph-Installation.html#igraph-Installation-prerequisites
if package:is_plat("linux", "macosx") then
package:add("deps", "gmp")
end

if package:config("glpk") then
package:add("deps", "glpk")
end
if package:config("graphml") then
package:add("deps", "libxml2")
end
if package:config("openmp") then
package:add("deps", "openmp")
end

if not package:config("shared") then
package:add("defines", "IGRAPH_STATIC")
end
end)

on_install("!cross and !bsd", function (package)
-- Disable test/doc/cpack
io.replace("CMakeLists.txt", "CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME", "0", {plain = true})
if package:config("graphml") then
io.replace("etc/cmake/dependencies.cmake", "find_package(LibXml2 ${LIBXML2_VERSION_MIN} QUIET)", "find_package(LibXml2 CONFIG REQUIRED)", {plain = true})
end
if package:gitref() then
io.writefile("IGRAPH_VERSION", package:version_str())
end

-- https://igraph.org/c/html/latest/igraph-Installation.html
local configs = {
"-DUSE_CCACHE=OFF",
"-DIGRAPH_WARNINGS_AS_ERRORS=OFF",
-- "-DIGRAPH_USE_INTERNAL_GMP=OFF",
-- "-DIGRAPH_USE_INTERNAL_ARPACK=OFF",
-- "-DIGRAPH_USE_INTERNAL_BLAS=OFF",
-- "-DIGRAPH_USE_INTERNAL_LAPACK=OFF",
"-DIGRAPH_USE_INTERNAL_GLPK=OFF",
"-DIGRAPH_USE_INTERNAL_PLFIT=OFF",
}
if package:is_plat("linux", "macosx") then
table.insert(configs, "-DIGRAPH_USE_INTERNAL_GMP=OFF")
end
table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
table.insert(configs, "-DIGRAPH_ENABLE_LTO=" .. (package:config("lto") and "ON" or "OFF"))

table.insert(configs, "-DIGRAPH_GLPK_SUPPORT=" .. (package:config("glpk") and "ON" or "OFF"))
table.insert(configs, "-DIGRAPH_OPENMP_SUPPORT=" .. (package:config("openmp") and "ON" or "OFF"))
-- AUTO -> find_package, ON -> find_dependency (unavailable)
table.insert(configs, "-DIGRAPH_GRAPHML_SUPPORT=" .. (package:config("graphml") and "AUTO" or "OFF"))
if package:is_cross() then
-- from https://github.com/microsoft/vcpkg/tree/0857a4b08c14030bbe41e80accb2b1fddb047a74/ports/igraph
local header
if package:is_plat("macosx") then
header = "arith_osx.h"
elseif package:is_plat("windows") then
if package:is_arch64() then
header = "arith_win64.h"
else
header = "arith_win32.h"
end
end

if header then
local header_path = path.unix(path.join(os.scriptdir(), header))
table.insert(configs, "-DF2C_EXTERNAL_ARITH_HEADER=" .. header_path)
end
end

local opt = {}
if package:config("glpk") then
opt.packagedeps = "zlib"
end
import("package.tools.cmake").install(package, configs, opt)
end)

on_test(function (package)
assert(package:has_cfuncs("igraph_rng_seed", {includes = "igraph/igraph.h"}))
end)

0 comments on commit 95aa0e9

Please sign in to comment.