Skip to content

Commit

Permalink
Use Singular_jll
Browse files Browse the repository at this point in the history
  • Loading branch information
thofma committed Aug 12, 2020
1 parent 8ae349f commit 034ca17
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 234 deletions.
3 changes: 2 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Markdown = "d6f4376e-aef5-505a-96c1-9c027394607a"
Nemo = "2edaba10-b0f1-5616-af89-8c11ac63239a"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
Singular_jll = "43d676ae-4934-50ba-8046-7a96366d613b"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
lib4ti2_jll = "1493ae25-0f90-5c0e-a06c-8c5077d6d66f"

Expand All @@ -20,7 +21,7 @@ AbstractAlgebra = "^0.9.0, 0.10"
BinaryProvider = "^0.5.8"
CMake = "^1.1.1"
CxxWrap = "^0.10.1, 0.11"
Nemo = "^0.17.0"
Nemo = "^0.18.0"
julia = "1.3"

[extras]
Expand Down
199 changes: 5 additions & 194 deletions deps/build.jl
Original file line number Diff line number Diff line change
@@ -1,203 +1,14 @@
using BinaryProvider

using Singular_jll

import CxxWrap
import Libdl
import Nemo
import CMake

# Parse some basic command-line arguments
const verbose = "--verbose" in ARGS

issource_build = "SINGULAR_SOURCE_BUILD" in keys(ENV) && ENV["SINGULAR_SOURCE_BUILD"] == "1"

const prefixpath = joinpath(@__DIR__, "usr")
const wdir = joinpath(@__DIR__)

const nemodir = realpath(joinpath(dirname(pathof(Nemo)), ".."))
nemovdir = "$nemodir/deps/usr"

if !issource_build
# Dependencies that must be installed before this package can be built
dependencies = [
# This has to be in sync with the corresponding commit in the source build below (for flint, singular)
"https://github.com/JuliaPackaging/Yggdrasil/releases/download/GMP-v6.1.2-1/build_GMP.v6.1.2.jl",
"https://github.com/JuliaPackaging/Yggdrasil/releases/download/MPFR-v4.0.2-1/build_MPFR.v4.0.2.jl",
"https://github.com/thofma/Flint2Builder/releases/download/ba0cee/build_libflint.v0.0.0-ba0ceed35136a2a43441ab9a9b2e7764e38548ea.jl",
"https://github.com/thofma/NTLBuilder2/releases/download/v10.5.0-1/build_libntl.v10.5.0.jl",
"https://github.com/oscar-system/SingularBuilder/releases/download/v0.0.6/build_libsingular.v0.0.6.jl",
]

const prefix = Prefix(get([a for a in ARGS if a != "--verbose"], 1, joinpath(@__DIR__, "usr")))

products = []

for url in dependencies
build_file = joinpath(@__DIR__, basename(url))
if !isfile(build_file)
download(url, build_file)
end
end

# Execute the build scripts for the dependencies in an isolated module to
# avoid overwriting any variables/constants here
for url in dependencies
build_file = joinpath(@__DIR__, basename(url))
m = @eval module $(gensym()); include($build_file); end
append!(products, m.products)
end

filenames = ["libgmp.la", "libgmpxx.la", "libmpfr.la"]

for filename in filenames
fpath = joinpath(prefixpath, "lib", filename)
txt = read(fpath, String)
open(fpath, "w") do f
write(f, replace(txt, "/workspace/destdir" => prefixpath))
end
end

else # source build

("NEMO_SOURCE_BUILD" in keys(ENV) && ENV["NEMO_SOURCE_BUILD"] == "1") || error("Source build of Nemo required")

const pkgdir = realpath(joinpath(@__DIR__, ".."))

const debug_build = false # N.B: debug builds are up to 50 times slower at runtime!

@show NTL_VERSION = "10.5.0"
@show SINGULAR_VERSION = "e7e39839d32320823bf9689c97c5071650497b8e"
@show CDDLIB_VERSION = "094h"

println("Removing old binaries ...")

rm(prefixpath, force = true, recursive = true)
mkdir(prefixpath)
mkdir(joinpath(prefixpath, "lib"))

if Sys.isapple() && !("CC" in keys(ENV))
ENV["CC"] = "clang"
ENV["CXX"] = "clang++"
end

LDFLAGS = "-Wl,-rpath,$prefixpath/lib -Wl,-rpath,\$\$ORIGIN/../share/julia/site/v$(VERSION.major).$(VERSION.minor)/Singular/local/lib"
cd(wdir)
localprefixpath = joinpath(@__DIR__, "usr")

cores = Sys.CPU_THREADS
println("Detected $cores CPU threads.")

# INSTALL NTL

const NTL_FILE=joinpath(wdir, "ntl-$NTL_VERSION"*".tar.gz")

try
download("https://www.shoup.net/ntl/$NTL_FILE", "$NTL_FILE")
catch
end

const tmp = mktempdir(wdir)

# http://www.shoup.net/ntl/
cd(tmp)
run(`tar -C "$tmp" -zxkvf $NTL_FILE`)
cd(joinpath(tmp, "ntl-$NTL_VERSION", "src"))
withenv("CPP_FLAGS"=>"-I$prefixpath/include", "LD_LIBRARY_PATH"=>"$prefixpath/lib:$nemovdir/lib", "LDFLAGS"=>LDFLAGS) do
run(`./configure PREFIX=$prefixpath DEF_PREFIX=$nemovdir SHARED=on NTL_THREADS=off NTL_EXCEPTIONS=off NTL_GMP_LIP=on CXXFLAGS="-I$nemovdir/include"`)
run(`make -j$cores`)
run(`make install`)
end
cd(wdir)
rm(tmp; recursive=true)

# Install cddlib

# Currently cddlib appears to have no way to specify what GMP is used
# thus --enable-gfanlib is not possible below, since it relies on cddlib
# being installed

# const CDDLIB_FILE="cddlib-$CDDLIB_VERSION"*".tar.gz"

# try
# run(`wget -q -nc -c -O $wdir/$CDDLIB_FILE ftp://ftp.math.ethz.ch/users/fukudak/cdd/$CDDLIB_FILE`)
# catch
# end

# const tmp2 = mktempdir(wdir)

# cd(tmp2)
# run(`tar -C $tmp2 -xkvf $wdir/$CDDLIB_FILE`)
# cd(joinpath(tmp2, cddlib))
# withenv("CPP_FLAGS"=>"-I$prefixpath/include", "LD_LIBRARY_PATH"=>"$prefixpath/lib:$nemovdir/lib", "LDFLAGS"=>LDFLAGS) do
# run(`./configure --prefix=$prefixpath --with-gmp=$nemovdir`)
# run(`make -j$cores`)
# run(`make install`)
# end
# cd(wdir)
# rm(tmp2; recursive=true)

# Install Singular

const srcs = joinpath(wdir, "Singular")

# get/update sources
try
run(`git clone -b spielwiese https://github.com/Singular/Sources.git $srcs`)
run(`git checkout $SINGULAR_VERSION`)
catch
cd(srcs)
try
run(`git pull --rebase`)
catch
end
cd(wdir)
end

cd(srcs)
run(`./autogen.sh`)
cd(wdir)

# out of source-tree building:
try
mkdir(joinpath(wdir, "Singular_build"))
catch
end

cd(joinpath(wdir, "Singular_build"))
withenv("CPP_FLAGS"=>"-I$prefixpath/include", "LD_LIBRARY_PATH"=>"$prefixpath/lib:$nemodir/lib") do
cmd = split(
"""
$srcs/configure
--with-libparse
--prefix=$prefixpath
--libdir=$prefixpath/lib
--disable-static
--enable-p-procs-static
--disable-p-procs-dynamic
--disable-gfanlib
--enable-shared
--with-gmp=$nemovdir
--with-flint=$nemovdir
--with-ntl=$prefixpath
--without-python
--with-readline=no
""", "\n", keepempty = false)
if debug_build
append!(cmd, [
"--with-debug",
"--enable-debug",
"--disable-optimizationflags",
])
end
run(Cmd(string.(cmd)))
withenv("LDFLAGS"=>LDFLAGS) do
run(`make -j$cores`)
run(`make install`)
end
end

print("Done building Singular")

cd(wdir)
end
prefixpath = Singular_jll.artifact_dir

# add shell scripts that startup another julia for some lib4ti2 programs
# singular and libsingular are supposed to at least look in
Expand Down Expand Up @@ -293,7 +104,7 @@ run(`$(CMake.cmake)
-Dextra_cppflags=$extra_cppflags
-Dsingular_includes=$prefixpath/include
-Dsingular_libdir=$prefixpath/lib
-DCMAKE_INSTALL_LIBDIR=$prefixpath/lib
-DCMAKE_INSTALL_LIBDIR=$localprefixpath/lib
$cmake_src_path`)

println("Running cmake")
Expand Down
6 changes: 3 additions & 3 deletions deps/parselibs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ function execute(cmd::Cmd)
code = process.exitcode)
end

libparsepath = abspath(joinpath(@__DIR__, "usr", "bin", "libparse"))
libparsepath = abspath(joinpath(prefixpath, "bin", "libparse"))

if haskey(ENV, "SINGULAR_LIBRARY_DIR")
library_dir = ENV["SINGULAR_LIBRARY_DIR"]
else
library_dir = abspath(joinpath(@__DIR__, "usr", "share", "singular", "LIB"))
library_dir = abspath(joinpath(prefixpath, "share", "singular", "LIB"))
end

filenames = filter(x -> endswith(x, ".lib"), readdir(library_dir))
Expand All @@ -31,7 +31,7 @@ output_filename = abspath(joinpath(@__DIR__, "..", "src", "libraryfuncdictionary
All other columns (containing info such as line numbers, library name, etc)
are ignored.
=#
cd(abspath(joinpath(@__DIR__, "usr", "bin"))) do
cd(abspath(joinpath(prefixpath, "bin"))) do
open(output_filename, "w") do outputfile
println(outputfile, "libraryfunctiondictionary = Dict(")
for i in filenames
Expand Down
7 changes: 4 additions & 3 deletions src/Singular.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ using Markdown
using Nemo
using Pkg
using lib4ti2_jll
using Singular_jll

import Base: abs, checkbounds, convert, deepcopy, deepcopy_internal,
denominator, div, divrem, exponent,
Expand Down Expand Up @@ -52,9 +53,9 @@ export ZZ, QQ, FiniteField, FunctionField, CoefficientRing, Fp
###############################################################################

const pkgdir = realpath(joinpath(dirname(@__FILE__), ".."))
const prefix = joinpath(pkgdir, "deps", "usr")
const libsingular = joinpath(prefix, "lib", "libSingular")
const binSingular = joinpath(prefix, "bin", "Singular")

const libsingular = Singular_jll.libsingular
const binSingular = Singular_jll.Singular_path

const libflint = Nemo.libflint
const libantic = Nemo.libantic
Expand Down
66 changes: 33 additions & 33 deletions test/poly/spoly-test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -414,39 +414,39 @@ end
@test jf == x^3
end

@testset "spoly.test_spoly_factor..." begin
R1 , (x, y, z, w) = Singular.PolynomialRing(Singular.QQ,
["x", "y", "z", "w"]; ordering=:negdegrevlex)
f1 = 113*(2*y^7 + w^2)^3*(1 + x)^2*(x + y*z)^2

R2 , (x, y, z, w) = Singular.PolynomialRing(Singular.ZZ,
["x", "y", "z", "w"]; ordering=:negdegrevlex)
f2 = 123*(57*y^3 + w^5)^3*(x^2 + x+1)^2*(x + y*z)^2

R3 , (x, y, z, w) = Singular.PolynomialRing(Singular.Fp(3),
["x", "y", "z", "w"]; ordering=:negdegrevlex)
f3 = 7*(y^3 + w^3)*(1 + x)^2*(x + y*z)^2

for f in [f1, f2, f3]
#Test factor
F = factor(f)
g = F.unit
for p in keys(F.fac)
g = g*p^F[p]
end
@test f == g

#Test factor_squarefree over QQ and Fp
if typeof(f.parent) != PolyRing{n_Z}
F = factor_squarefree(f)
g = F.unit
for p in keys(F.fac)
g = g*p^F[p]
end
@test f == g
end
end
end
#@testset "spoly.test_spoly_factor..." begin
# R1 , (x, y, z, w) = Singular.PolynomialRing(Singular.QQ,
# ["x", "y", "z", "w"]; ordering=:negdegrevlex)
# f1 = 113*(2*y^7 + w^2)^3*(1 + x)^2*(x + y*z)^2
#
# R2 , (x, y, z, w) = Singular.PolynomialRing(Singular.ZZ,
# ["x", "y", "z", "w"]; ordering=:negdegrevlex)
# f2 = 123*(57*y^3 + w^5)^3*(x^2 + x+1)^2*(x + y*z)^2
#
# R3 , (x, y, z, w) = Singular.PolynomialRing(Singular.Fp(3),
# ["x", "y", "z", "w"]; ordering=:negdegrevlex)
# f3 = 7*(y^3 + w^3)*(1 + x)^2*(x + y*z)^2
#
# for f in [f1, f2, f3]
# #Test factor
# F = factor(f)
# g = F.unit
# for p in keys(F.fac)
# g = g*p^F[p]
# end
# @test f == g
#
# #Test factor_squarefree over QQ and Fp
# if typeof(f.parent) != PolyRing{n_Z}
# F = factor_squarefree(f)
# g = F.unit
# for p in keys(F.fac)
# g = g*p^F[p]
# end
# @test f == g
# end
# end
#end

@testset "spoly.hash..." begin
R, (x, y) = PolynomialRing(QQ, ["x", "y"])
Expand Down

0 comments on commit 034ca17

Please sign in to comment.