From e1ee5adcf76892bafe29a831e9d1bad7fa72b0d5 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Tue, 13 Jun 2023 13:56:29 +0200 Subject: [PATCH] Build libgsingular_julia on demand (#639) If the source code in this repository differs from what was used to build libsingular_julia_jll, then recompile libsingular_julia. This requires a working C++ compiler. It is intended for development, not for use in releases. --- .gitignore | 2 + Project.toml | 3 + README.maintainer.md | 86 ++--- deps/src/CMakeLists.txt | 64 ++-- deps/src/LICENSE.md | 674 ---------------------------------------- deps/src/README.md | 82 ----- deps/src/build.jl | 46 --- deps/src/run.jl | 40 --- src/LibSingular.jl | 2 +- src/Singular.jl | 11 +- src/setup.jl | 125 +++++++- 11 files changed, 209 insertions(+), 926 deletions(-) delete mode 100644 deps/src/LICENSE.md delete mode 100644 deps/src/README.md delete mode 100644 deps/src/build.jl delete mode 100644 deps/src/run.jl diff --git a/.gitignore b/.gitignore index 9861b16ef..b279ea553 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,8 @@ *.jl.cov *.jl.mem /bin/ +/deps/build*/ +/deps/install*/ /docs/build/ /gh-pages/ /local/* diff --git a/Project.toml b/Project.toml index 846739a53..e0c85883f 100644 --- a/Project.toml +++ b/Project.toml @@ -6,8 +6,10 @@ version = "0.18.5" AbstractAlgebra = "c3fe647b-3220-5bb0-a1ea-a7954cac585d" BinaryWrappers = "f01c122e-0ea1-4f85-ad8f-907073ad7a9f" CxxWrap = "1f15a43c-97ca-5a2a-ae31-89f07a497df4" +Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" Nemo = "2edaba10-b0f1-5616-af89-8c11ac63239a" +Pidfile = "fa939f87-e72e-5be4-a000-7fc836dbe307" Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" RandomExtensions = "fb686558-2515-59ef-acaa-46db3789a887" @@ -21,6 +23,7 @@ AbstractAlgebra = "0.28, 0.29, 0.30" BinaryWrappers = "~0.1.1" CxxWrap = "0.11, 0.12, 0.13" Nemo = "0.33.0, 0.34.0" +Pidfile = "1.3" RandomExtensions = "0.4.2" Singular_jll = "~403.203.200" julia = "1.6" diff --git a/README.maintainer.md b/README.maintainer.md index cbfb8530a..f643e77d2 100644 --- a/README.maintainer.md +++ b/README.maintainer.md @@ -1,109 +1,89 @@ # Directions for updating Singular.jl -`Singular.jl` depends on the Singular kernel and various C++ wrappers maintained -in `libsingular_julia`. These come as binary artifacts `Singular_jll` and +`Singular.jl` depends on the Singular kernel and some C++ glue code found in +the `deps/src/` directory. Compiled versions of each are distributed to users +as binary artifacts via the Julia "JLL" packages `Singular_jll` and `libsingular_julia_jll` respectively. -The build scripts for each of these: +The build scripts for these JLL packages can be found here: - - +The resulting JLL packages + +- +- + The sources: -- -- +- `Singular` sources: +- `libsingular_julia` sources: `deps/src/` directory of `Singular.jl` -## updating libsingular_julia +## Updating just the C++ wrappers Suppose just the C++ wrappers need to be updated, without any changes to the Singular kernel itself. -1. Commit changes to the `libsingular_julia` source - ex: https://github.com/oscar-system/libsingular-julia/commit/65a12e7fb8546851d3296244aeacc5de1d97af2c +1. Commit changes to the `deps/src/` directory. + > ex: -2. Update the `libsingular_julia` build script with a new version number the commit SHA - ex: https://github.com/JuliaPackaging/Yggdrasil/commit/dd9d775f530b1164dd1cf6135677846dcb25fafc +2. After the changes are merged (and before the next `Singular.jl` release), update + the `libsingular_julia` build script with a new version number and using the + latest commit SHA for the `master` branch of `Singular.jl`. + > ex: -3. Wait for this to be merged into Yggdrasil, and then wait for the registry to pick up the new version of `libsingular_julia_jll` - ex: https://github.com/JuliaRegistries/General/commit/00624106c204ccb28fb2c834877fb6005c653ce7 +3. Wait for this to be merged into Yggdrasil, and then wait for the registry + to pick up the new version of `libsingular_julia_jll`. + > ex: 4. Bump the dependence in `Singular.jl` to whatever version number was used in Step 2. - ex: https://github.com/oscar-system/Singular.jl/commit/f669cea1aa4fc73082d8e8c08a1e33a7c22882ed + > ex: - Version compatibility notation: https://pkgdocs.julialang.org/v1/compatibility/ + Version compatibility notation: 5. Release a new `Singular.jl`. This is done by pinging JuliaRegistrator in the comments of a commit. - ex: https://github.com/oscar-system/Singular.jl/commit/cbc04de26507b386e27d2bd7a23a2f913903d9cc + > ex: After the new version of `Singular.jl` is picked up by the registry, it may be used in further downstream packages. -Note: if you would like test simultaneous changes to both `libsingular_julia` and -`Singular.jl`, create pull requests against both with the same branch name. -The CI should show some "matching: " entries. - ex: https://github.com/oscar-system/libsingular-julia/pull/55 - -## updating the Singular kernel +## Updating the Singular kernel Suppose the Singular kernel needs an update. This involves updating both build scripts because `libsingular_julia_jll` will need to point to the new `Singular_jll`. 1. Update the Singular build script with the commit SHA of the singular sources (https://github.com/Singular/Singular) - ex: https://github.com/JuliaPackaging/Yggdrasil/commit/1996668f09e89bc8da0cc498c59d905821b150c8 + > ex: In this specific commit, `FLINT_jll` was also updated, but this is not necessary to update singular. - Any build issues need to be communicated to https://github.com/Singular/Singular + Any build issues need to be communicated to until you get a commit that builds on all targets. 2. Wait for the Yggdrasil merge, and wait for the registry. - ex: https://github.com/JuliaRegistries/General/commit/c73ad5d2ec0483113ffc2eca9b623049a7d8e81a + > ex: 3. Update the `libsingular_julia` build scripts with a new version and `Singular_jll` dependency. - ex: https://github.com/JuliaPackaging/Yggdrasil/commit/cc75959bcf85b016625d9e528db277fd4d3b32d9 - - Supposedly, Yggdrasil does not like new versions with the same commit SHA. - Therefore, if `https://github.com/oscar-system/libsingular-julia.git` has not - changed since the last version, add a dummy commit and use the new SHA. + > ex: At this point, we have a new `libsingular_julia_jll` in the works, and the steps are essentially Steps 3-5 in the previous section. 4. The usual waiting. - ex: https://github.com/JuliaRegistries/General/commit/5c91a1184ed468d2a014c149f19caf84748fb83f + > ex: 5. Bump the `libsingular_julia_jll` and `Singular_jll` dependencies in `Singular.jl`. - ex: https://github.com/oscar-system/Singular.jl/commit/138eeb12b5105e252c086bc45f259704e74c9885 + > ex: This commit also bumps `AbstractAlgebra` and `Nemo`, but this is not necessary just to update Singular. 6. Release new `Singular.jl` version. - ex: https://github.com/oscar-system/Singular.jl/commit/12f3b6b8689177d55f3952a8e5f9dccf233be885 + > ex: -## updating both libsingular_julia and the Singular kernel +## Updating both `libsingular_julia` and the Singular kernel Since updating the Singular kernel requires an update to `libsingular_julia`, the steps here are the same as in the previous section. Just make sure that in Step 3, the commit SHA used to update the `libsingular_julia` build scripts contains all of the desired changes to `libsingular_julia`. - -# Overriding the libsingular_julia_jll artifact - -Suppose you have cloned -https://github.com/oscar-system/libsingular-julia -into, say `/my/path`, and would like to test your local changes. - -First, you must have a file `.julia/artifacts/Overrides.toml` with the entry - -``` -[ae4fbd8f-ecdb-54f8-bbce-35570499b30e] -libsingular_julia = "/my/path/libsingular-julia/build" -``` - -Next, from `/my/path` run `julia build.jl` which will build the package with -your changes. - -Finally, the updated `libsingular_julia_jll` should be available the next time -julia starts. Packages that depend on it may need to be precompiled again to -pick up the changes. diff --git a/deps/src/CMakeLists.txt b/deps/src/CMakeLists.txt index 61be461cf..c3ff86d97 100644 --- a/deps/src/CMakeLists.txt +++ b/deps/src/CMakeLists.txt @@ -1,22 +1,20 @@ cmake_minimum_required(VERSION 3.01) -# I don't know why I need the following, but it works -if(POLICY CMP0025) - cmake_policy(SET CMP0025 NEW) -endif() - project(libsingular_julia) +set(JL_TARGET singular_julia) + set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib") find_package(JlCxx REQUIRED) +get_target_property(JlCxx_location JlCxx::cxxwrap_julia LOCATION) +get_filename_component(JlCxx_location ${JlCxx_location} DIRECTORY) +message(STATUS "Found JlCxx at ${JlCxx_location}") include(CheckCXXCompilerFlag) set(CMAKE_CXX_STANDARD 14) -set(JLSINGULAR_TARGET singular_julia) - # avoid gcc 9 internal compiler error, # see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90998 if(CMAKE_COMPILER_IS_GNUCC AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 9.0 @@ -28,25 +26,47 @@ endif() set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib") set(CMAKE_INSTALL_LIBDIR "lib") -get_target_property(JlCxx_location JlCxx::cxxwrap_julia LOCATION) -get_filename_component(JlCxx_location ${JlCxx_location} DIRECTORY) set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib;${JlCxx_location}") -message(STATUS "Found JlCxx at ${JlCxx_location}") - -include_directories(${CMAKE_INSTALL_PREFIX}) -include_directories(${Singular_PREFIX}/include/singular) - -SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g ${extra_cppflags} -I${CMAKE_INSTALL_PREFIX}/include -I${Singular_PREFIX}/include/" ) -SET( CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -v ${extra_ldflags} -L${CMAKE_INSTALL_PREFIX}/lib -Wl,-rpath,${CMAKE_INSTALL_PREFIX}/lib -L${Singular_PREFIX}/lib -Wl,-rpath,${Singular_PREFIX}/lib" ) - - -add_library(${JLSINGULAR_TARGET} SHARED singular.cpp rings.cpp coeffs.cpp ideals.cpp matrices.cpp caller.cpp coeff_rings.cpp threading.cpp) - -target_link_libraries(${JLSINGULAR_TARGET} JlCxx::cxxwrap_julia -lSingular -lpolys -lsingular_resources -lfactory -lomalloc -ldl -lgmp) +include_directories( + ${Singular_PREFIX}/include + ${Singular_PREFIX}/include/singular + ${gmp_prefix}/include + ) + +link_directories( + ${Singular_PREFIX}/lib + ${gmp_prefix}/lib + ) + +#SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g ${extra_cppflags}" ) +#SET( CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -v ${extra_ldflags} ) + + +add_library(${JL_TARGET} SHARED + singular.cpp + rings.cpp + coeffs.cpp + ideals.cpp + matrices.cpp + caller.cpp + coeff_rings.cpp + threading.cpp + ) + +target_link_libraries(${JL_TARGET} + JlCxx::cxxwrap_julia + -lSingular + -lpolys + -lsingular_resources + -lfactory + -lomalloc + -ldl + -lgmp + ) install(TARGETS - ${JLSINGULAR_TARGET} + ${JL_TARGET} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} diff --git a/deps/src/LICENSE.md b/deps/src/LICENSE.md deleted file mode 100644 index 7f74e1971..000000000 --- a/deps/src/LICENSE.md +++ /dev/null @@ -1,674 +0,0 @@ -############################################################################### - - IMPORTANT NOTE - - The Singular.jl package is licensed OVERALL under the GNU Public License, - Version 3.0+. See below for full details of the GPL license. - -############################################################################### - -All INDIVIDUAL Julia (.jl) files in the Singular.jl package are licensed -under the BSD license, unless explicitly noted in the file: - -> Copyright (c) 2015-2016: Oleksandr Motsak. -> Copyright (c) 2016: William Hart. -> All rights reserved. -> -> Redistribution and use in source and binary forms, with or without -> modification, are permitted provided that the following conditions are met: -> -> * Redistributions of source code must retain the above copyright notice, this -> list of conditions and the following disclaimer. -> -> * Redistributions in binary form must reproduce the above copyright notice, -> this list of conditions and the following disclaimer in the documentation -> and/or other materials provided with the distribution. -> -> THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -> AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -> IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -> DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -> FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -> DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -> SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -> CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -> OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -> OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -> - - -> Copyright (c) 2015-2016: Oleksandr Motsak. -> Copyright (c) 2016: William Hart. -> This program is free software: you can redistribute it and/or modify -> it under the terms of the GNU General Public License as published by -> the Free Software Foundation, either version 3 of the License, or -> (at your option) any later version. -> -> This program is distributed in the hope that it will be useful, -> but WITHOUT ANY WARRANTY; without even the implied warranty of -> MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -> GNU General Public License for more details. -> -> -> GNU GENERAL PUBLIC LICENSE -> Version 3, 29 June 2007 -> -> Copyright (C) 2007 Free Software Foundation, Inc. -> Everyone is permitted to copy and distribute verbatim copies -> of this license document, but changing it is not allowed. -> -> Preamble -> -> The GNU General Public License is a free, copyleft license for -> software and other kinds of works. -> -> The licenses for most software and other practical works are designed -> to take away your freedom to share and change the works. By contrast, -> the GNU General Public License is intended to guarantee your freedom to -> share and change all versions of a program--to make sure it remains free -> software for all its users. We, the Free Software Foundation, use the -> GNU General Public License for most of our software; it applies also to -> any other work released this way by its authors. You can apply it to -> your programs, too. -> -> When we speak of free software, we are referring to freedom, not -> price. Our General Public Licenses are designed to make sure that you -> have the freedom to distribute copies of free software (and charge for -> them if you wish), that you receive source code or can get it if you -> want it, that you can change the software or use pieces of it in new -> free programs, and that you know you can do these things. -> -> To protect your rights, we need to prevent others from denying you -> these rights or asking you to surrender the rights. Therefore, you have -> certain responsibilities if you distribute copies of the software, or if -> you modify it: responsibilities to respect the freedom of others. -> -> For example, if you distribute copies of such a program, whether -> gratis or for a fee, you must pass on to the recipients the same -> freedoms that you received. You must make sure that they, too, receive -> or can get the source code. And you must show them these terms so they -> know their rights. -> -> Developers that use the GNU GPL protect your rights with two steps: -> (1) assert copyright on the software, and (2) offer you this License -> giving you legal permission to copy, distribute and/or modify it. -> -> For the developers' and authors' protection, the GPL clearly explains -> that there is no warranty for this free software. For both users' and -> authors' sake, the GPL requires that modified versions be marked as -> changed, so that their problems will not be attributed erroneously to -> authors of previous versions. -> -> Some devices are designed to deny users access to install or run -> modified versions of the software inside them, although the manufacturer -> can do so. This is fundamentally incompatible with the aim of -> protecting users' freedom to change the software. The systematic -> pattern of such abuse occurs in the area of products for individuals to -> use, which is precisely where it is most unacceptable. Therefore, we -> have designed this version of the GPL to prohibit the practice for those -> products. If such problems arise substantially in other domains, we -> stand ready to extend this provision to those domains in future versions -> of the GPL, as needed to protect the freedom of users. -> -> Finally, every program is threatened constantly by software patents. -> States should not allow patents to restrict development and use of -> software on general-purpose computers, but in those that do, we wish to -> avoid the special danger that patents applied to a free program could -> make it effectively proprietary. To prevent this, the GPL assures that -> patents cannot be used to render the program non-free. -> -> The precise terms and conditions for copying, distribution and -> modification follow. -> -> TERMS AND CONDITIONS -> -> 0. Definitions. -> -> "This License" refers to version 3 of the GNU General Public License. -> -> "Copyright" also means copyright-like laws that apply to other kinds of -> works, such as semiconductor masks. -> -> "The Program" refers to any copyrightable work licensed under this -> License. Each licensee is addressed as "you". "Licensees" and -> "recipients" may be individuals or organizations. -> -> To "modify" a work means to copy from or adapt all or part of the work -> in a fashion requiring copyright permission, other than the making of an -> exact copy. The resulting work is called a "modified version" of the -> earlier work or a work "based on" the earlier work. -> -> A "covered work" means either the unmodified Program or a work based -> on the Program. -> -> To "propagate" a work means to do anything with it that, without -> permission, would make you directly or secondarily liable for -> infringement under applicable copyright law, except executing it on a -> computer or modifying a private copy. Propagation includes copying, -> distribution (with or without modification), making available to the -> public, and in some countries other activities as well. -> -> To "convey" a work means any kind of propagation that enables other -> parties to make or receive copies. Mere interaction with a user through -> a computer network, with no transfer of a copy, is not conveying. -> -> An interactive user interface displays "Appropriate Legal Notices" -> to the extent that it includes a convenient and prominently visible -> feature that (1) displays an appropriate copyright notice, and (2) -> tells the user that there is no warranty for the work (except to the -> extent that warranties are provided), that licensees may convey the -> work under this License, and how to view a copy of this License. If -> the interface presents a list of user commands or options, such as a -> menu, a prominent item in the list meets this criterion. -> -> 1. Source Code. -> -> The "source code" for a work means the preferred form of the work -> for making modifications to it. "Object code" means any non-source -> form of a work. -> -> A "Standard Interface" means an interface that either is an official -> standard defined by a recognized standards body, or, in the case of -> interfaces specified for a particular programming language, one that -> is widely used among developers working in that language. -> -> The "System Libraries" of an executable work include anything, other -> than the work as a whole, that (a) is included in the normal form of -> packaging a Major Component, but which is not part of that Major -> Component, and (b) serves only to enable use of the work with that -> Major Component, or to implement a Standard Interface for which an -> implementation is available to the public in source code form. A -> "Major Component", in this context, means a major essential component -> (kernel, window system, and so on) of the specific operating system -> (if any) on which the executable work runs, or a compiler used to -> produce the work, or an object code interpreter used to run it. -> -> The "Corresponding Source" for a work in object code form means all -> the source code needed to generate, install, and (for an executable -> work) run the object code and to modify the work, including scripts to -> control those activities. However, it does not include the work's -> System Libraries, or general-purpose tools or generally available free -> programs which are used unmodified in performing those activities but -> which are not part of the work. For example, Corresponding Source -> includes interface definition files associated with source files for -> the work, and the source code for shared libraries and dynamically -> linked subprograms that the work is specifically designed to require, -> such as by intimate data communication or control flow between those -> subprograms and other parts of the work. -> -> The Corresponding Source need not include anything that users -> can regenerate automatically from other parts of the Corresponding -> Source. -> -> The Corresponding Source for a work in source code form is that -> same work. -> -> 2. Basic Permissions. -> -> All rights granted under this License are granted for the term of -> copyright on the Program, and are irrevocable provided the stated -> conditions are met. This License explicitly affirms your unlimited -> permission to run the unmodified Program. The output from running a -> covered work is covered by this License only if the output, given its -> content, constitutes a covered work. This License acknowledges your -> rights of fair use or other equivalent, as provided by copyright law. -> -> You may make, run and propagate covered works that you do not -> convey, without conditions so long as your license otherwise remains -> in force. You may convey covered works to others for the sole purpose -> of having them make modifications exclusively for you, or provide you -> with facilities for running those works, provided that you comply with -> the terms of this License in conveying all material for which you do -> not control copyright. Those thus making or running the covered works -> for you must do so exclusively on your behalf, under your direction -> and control, on terms that prohibit them from making any copies of -> your copyrighted material outside their relationship with you. -> -> Conveying under any other circumstances is permitted solely under -> the conditions stated below. Sublicensing is not allowed; section 10 -> makes it unnecessary. -> -> 3. Protecting Users' Legal Rights From Anti-Circumvention Law. -> -> No covered work shall be deemed part of an effective technological -> measure under any applicable law fulfilling obligations under article -> 11 of the WIPO copyright treaty adopted on 20 December 1996, or -> similar laws prohibiting or restricting circumvention of such -> measures. -> -> When you convey a covered work, you waive any legal power to forbid -> circumvention of technological measures to the extent such circumvention -> is effected by exercising rights under this License with respect to -> the covered work, and you disclaim any intention to limit operation or -> modification of the work as a means of enforcing, against the work's -> users, your or third parties' legal rights to forbid circumvention of -> technological measures. -> -> 4. Conveying Verbatim Copies. -> -> You may convey verbatim copies of the Program's source code as you -> receive it, in any medium, provided that you conspicuously and -> appropriately publish on each copy an appropriate copyright notice; -> keep intact all notices stating that this License and any -> non-permissive terms added in accord with section 7 apply to the code; -> keep intact all notices of the absence of any warranty; and give all -> recipients a copy of this License along with the Program. -> -> You may charge any price or no price for each copy that you convey, -> and you may offer support or warranty protection for a fee. -> -> 5. Conveying Modified Source Versions. -> -> You may convey a work based on the Program, or the modifications to -> produce it from the Program, in the form of source code under the -> terms of section 4, provided that you also meet all of these conditions: -> -> a) The work must carry prominent notices stating that you modified -> it, and giving a relevant date. -> -> b) The work must carry prominent notices stating that it is -> released under this License and any conditions added under section -> 7. This requirement modifies the requirement in section 4 to -> "keep intact all notices". -> -> c) You must license the entire work, as a whole, under this -> License to anyone who comes into possession of a copy. This -> License will therefore apply, along with any applicable section 7 -> additional terms, to the whole of the work, and all its parts, -> regardless of how they are packaged. This License gives no -> permission to license the work in any other way, but it does not -> invalidate such permission if you have separately received it. -> -> d) If the work has interactive user interfaces, each must display -> Appropriate Legal Notices; however, if the Program has interactive -> interfaces that do not display Appropriate Legal Notices, your -> work need not make them do so. -> -> A compilation of a covered work with other separate and independent -> works, which are not by their nature extensions of the covered work, -> and which are not combined with it such as to form a larger program, -> in or on a volume of a storage or distribution medium, is called an -> "aggregate" if the compilation and its resulting copyright are not -> used to limit the access or legal rights of the compilation's users -> beyond what the individual works permit. Inclusion of a covered work -> in an aggregate does not cause this License to apply to the other -> parts of the aggregate. -> -> 6. Conveying Non-Source Forms. -> -> You may convey a covered work in object code form under the terms -> of sections 4 and 5, provided that you also convey the -> machine-readable Corresponding Source under the terms of this License, -> in one of these ways: -> -> a) Convey the object code in, or embodied in, a physical product -> (including a physical distribution medium), accompanied by the -> Corresponding Source fixed on a durable physical medium -> customarily used for software interchange. -> -> b) Convey the object code in, or embodied in, a physical product -> (including a physical distribution medium), accompanied by a -> written offer, valid for at least three years and valid for as -> long as you offer spare parts or customer support for that product -> model, to give anyone who possesses the object code either (1) a -> copy of the Corresponding Source for all the software in the -> product that is covered by this License, on a durable physical -> medium customarily used for software interchange, for a price no -> more than your reasonable cost of physically performing this -> conveying of source, or (2) access to copy the -> Corresponding Source from a network server at no charge. -> -> c) Convey individual copies of the object code with a copy of the -> written offer to provide the Corresponding Source. This -> alternative is allowed only occasionally and noncommercially, and -> only if you received the object code with such an offer, in accord -> with subsection 6b. -> -> d) Convey the object code by offering access from a designated -> place (gratis or for a charge), and offer equivalent access to the -> Corresponding Source in the same way through the same place at no -> further charge. You need not require recipients to copy the -> Corresponding Source along with the object code. If the place to -> copy the object code is a network server, the Corresponding Source -> may be on a different server (operated by you or a third party) -> that supports equivalent copying facilities, provided you maintain -> clear directions next to the object code saying where to find the -> Corresponding Source. Regardless of what server hosts the -> Corresponding Source, you remain obligated to ensure that it is -> available for as long as needed to satisfy these requirements. -> -> e) Convey the object code using peer-to-peer transmission, provided -> you inform other peers where the object code and Corresponding -> Source of the work are being offered to the general public at no -> charge under subsection 6d. -> -> A separable portion of the object code, whose source code is excluded -> from the Corresponding Source as a System Library, need not be -> included in conveying the object code work. -> -> A "User Product" is either (1) a "consumer product", which means any -> tangible personal property which is normally used for personal, family, -> or household purposes, or (2) anything designed or sold for incorporation -> into a dwelling. In determining whether a product is a consumer product, -> doubtful cases shall be resolved in favor of coverage. For a particular -> product received by a particular user, "normally used" refers to a -> typical or common use of that class of product, regardless of the status -> of the particular user or of the way in which the particular user -> actually uses, or expects or is expected to use, the product. A product -> is a consumer product regardless of whether the product has substantial -> commercial, industrial or non-consumer uses, unless such uses represent -> the only significant mode of use of the product. -> -> "Installation Information" for a User Product means any methods, -> procedures, authorization keys, or other information required to install -> and execute modified versions of a covered work in that User Product from -> a modified version of its Corresponding Source. The information must -> suffice to ensure that the continued functioning of the modified object -> code is in no case prevented or interfered with solely because -> modification has been made. -> -> If you convey an object code work under this section in, or with, or -> specifically for use in, a User Product, and the conveying occurs as -> part of a transaction in which the right of possession and use of the -> User Product is transferred to the recipient in perpetuity or for a -> fixed term (regardless of how the transaction is characterized), the -> Corresponding Source conveyed under this section must be accompanied -> by the Installation Information. But this requirement does not apply -> if neither you nor any third party retains the ability to install -> modified object code on the User Product (for example, the work has -> been installed in ROM). -> -> The requirement to provide Installation Information does not include a -> requirement to continue to provide support service, warranty, or updates -> for a work that has been modified or installed by the recipient, or for -> the User Product in which it has been modified or installed. Access to a -> network may be denied when the modification itself materially and -> adversely affects the operation of the network or violates the rules and -> protocols for communication across the network. -> -> Corresponding Source conveyed, and Installation Information provided, -> in accord with this section must be in a format that is publicly -> documented (and with an implementation available to the public in -> source code form), and must require no special password or key for -> unpacking, reading or copying. -> -> 7. Additional Terms. -> -> "Additional permissions" are terms that supplement the terms of this -> License by making exceptions from one or more of its conditions. -> Additional permissions that are applicable to the entire Program shall -> be treated as though they were included in this License, to the extent -> that they are valid under applicable law. If additional permissions -> apply only to part of the Program, that part may be used separately -> under those permissions, but the entire Program remains governed by -> this License without regard to the additional permissions. -> -> When you convey a copy of a covered work, you may at your option -> remove any additional permissions from that copy, or from any part of -> it. (Additional permissions may be written to require their own -> removal in certain cases when you modify the work.) You may place -> additional permissions on material, added by you to a covered work, -> for which you have or can give appropriate copyright permission. -> -> Notwithstanding any other provision of this License, for material you -> add to a covered work, you may (if authorized by the copyright holders of -> that material) supplement the terms of this License with terms: -> -> a) Disclaiming warranty or limiting liability differently from the -> terms of sections 15 and 16 of this License; or -> -> b) Requiring preservation of specified reasonable legal notices or -> author attributions in that material or in the Appropriate Legal -> Notices displayed by works containing it; or -> -> c) Prohibiting misrepresentation of the origin of that material, or -> requiring that modified versions of such material be marked in -> reasonable ways as different from the original version; or -> -> d) Limiting the use for publicity purposes of names of licensors or -> authors of the material; or -> -> e) Declining to grant rights under trademark law for use of some -> trade names, trademarks, or service marks; or -> -> f) Requiring indemnification of licensors and authors of that -> material by anyone who conveys the material (or modified versions of -> it) with contractual assumptions of liability to the recipient, for -> any liability that these contractual assumptions directly impose on -> those licensors and authors. -> -> All other non-permissive additional terms are considered "further -> restrictions" within the meaning of section 10. If the Program as you -> received it, or any part of it, contains a notice stating that it is -> governed by this License along with a term that is a further -> restriction, you may remove that term. If a license document contains -> a further restriction but permits relicensing or conveying under this -> License, you may add to a covered work material governed by the terms -> of that license document, provided that the further restriction does -> not survive such relicensing or conveying. -> -> If you add terms to a covered work in accord with this section, you -> must place, in the relevant source files, a statement of the -> additional terms that apply to those files, or a notice indicating -> where to find the applicable terms. -> -> Additional terms, permissive or non-permissive, may be stated in the -> form of a separately written license, or stated as exceptions; -> the above requirements apply either way. -> -> 8. Termination. -> -> You may not propagate or modify a covered work except as expressly -> provided under this License. Any attempt otherwise to propagate or -> modify it is void, and will automatically terminate your rights under -> this License (including any patent licenses granted under the third -> paragraph of section 11). -> -> However, if you cease all violation of this License, then your -> license from a particular copyright holder is reinstated (a) -> provisionally, unless and until the copyright holder explicitly and -> finally terminates your license, and (b) permanently, if the copyright -> holder fails to notify you of the violation by some reasonable means -> prior to 60 days after the cessation. -> -> Moreover, your license from a particular copyright holder is -> reinstated permanently if the copyright holder notifies you of the -> violation by some reasonable means, this is the first time you have -> received notice of violation of this License (for any work) from that -> copyright holder, and you cure the violation prior to 30 days after -> your receipt of the notice. -> -> Termination of your rights under this section does not terminate the -> licenses of parties who have received copies or rights from you under -> this License. If your rights have been terminated and not permanently -> reinstated, you do not qualify to receive new licenses for the same -> material under section 10. -> -> 9. Acceptance Not Required for Having Copies. -> -> You are not required to accept this License in order to receive or -> run a copy of the Program. Ancillary propagation of a covered work -> occurring solely as a consequence of using peer-to-peer transmission -> to receive a copy likewise does not require acceptance. However, -> nothing other than this License grants you permission to propagate or -> modify any covered work. These actions infringe copyright if you do -> not accept this License. Therefore, by modifying or propagating a -> covered work, you indicate your acceptance of this License to do so. -> -> 10. Automatic Licensing of Downstream Recipients. -> -> Each time you convey a covered work, the recipient automatically -> receives a license from the original licensors, to run, modify and -> propagate that work, subject to this License. You are not responsible -> for enforcing compliance by third parties with this License. -> -> An "entity transaction" is a transaction transferring control of an -> organization, or substantially all assets of one, or subdividing an -> organization, or merging organizations. If propagation of a covered -> work results from an entity transaction, each party to that -> transaction who receives a copy of the work also receives whatever -> licenses to the work the party's predecessor in interest had or could -> give under the previous paragraph, plus a right to possession of the -> Corresponding Source of the work from the predecessor in interest, if -> the predecessor has it or can get it with reasonable efforts. -> -> You may not impose any further restrictions on the exercise of the -> rights granted or affirmed under this License. For example, you may -> not impose a license fee, royalty, or other charge for exercise of -> rights granted under this License, and you may not initiate litigation -> (including a cross-claim or counterclaim in a lawsuit) alleging that -> any patent claim is infringed by making, using, selling, offering for -> sale, or importing the Program or any portion of it. -> -> 11. Patents. -> -> A "contributor" is a copyright holder who authorizes use under this -> License of the Program or a work on which the Program is based. The -> work thus licensed is called the contributor's "contributor version". -> -> A contributor's "essential patent claims" are all patent claims -> owned or controlled by the contributor, whether already acquired or -> hereafter acquired, that would be infringed by some manner, permitted -> by this License, of making, using, or selling its contributor version, -> but do not include claims that would be infringed only as a -> consequence of further modification of the contributor version. For -> purposes of this definition, "control" includes the right to grant -> patent sublicenses in a manner consistent with the requirements of -> this License. -> -> Each contributor grants you a non-exclusive, worldwide, royalty-free -> patent license under the contributor's essential patent claims, to -> make, use, sell, offer for sale, import and otherwise run, modify and -> propagate the contents of its contributor version. -> -> In the following three paragraphs, a "patent license" is any express -> agreement or commitment, however denominated, not to enforce a patent -> (such as an express permission to practice a patent or covenant not to -> sue for patent infringement). To "grant" such a patent license to a -> party means to make such an agreement or commitment not to enforce a -> patent against the party. -> -> If you convey a covered work, knowingly relying on a patent license, -> and the Corresponding Source of the work is not available for anyone -> to copy, free of charge and under the terms of this License, through a -> publicly available network server or other readily accessible means, -> then you must either (1) cause the Corresponding Source to be so -> available, or (2) arrange to deprive yourself of the benefit of the -> patent license for this particular work, or (3) arrange, in a manner -> consistent with the requirements of this License, to extend the patent -> license to downstream recipients. "Knowingly relying" means you have -> actual knowledge that, but for the patent license, your conveying the -> covered work in a country, or your recipient's use of the covered work -> in a country, would infringe one or more identifiable patents in that -> country that you have reason to believe are valid. -> -> If, pursuant to or in connection with a single transaction or -> arrangement, you convey, or propagate by procuring conveyance of, a -> covered work, and grant a patent license to some of the parties -> receiving the covered work authorizing them to use, propagate, modify -> or convey a specific copy of the covered work, then the patent license -> you grant is automatically extended to all recipients of the covered -> work and works based on it. -> -> A patent license is "discriminatory" if it does not include within -> the scope of its coverage, prohibits the exercise of, or is -> conditioned on the non-exercise of one or more of the rights that are -> specifically granted under this License. You may not convey a covered -> work if you are a party to an arrangement with a third party that is -> in the business of distributing software, under which you make payment -> to the third party based on the extent of your activity of conveying -> the work, and under which the third party grants, to any of the -> parties who would receive the covered work from you, a discriminatory -> patent license (a) in connection with copies of the covered work -> conveyed by you (or copies made from those copies), or (b) primarily -> for and in connection with specific products or compilations that -> contain the covered work, unless you entered into that arrangement, -> or that patent license was granted, prior to 28 March 2007. -> -> Nothing in this License shall be construed as excluding or limiting -> any implied license or other defenses to infringement that may -> otherwise be available to you under applicable patent law. -> -> 12. No Surrender of Others' Freedom. -> -> If conditions are imposed on you (whether by court order, agreement or -> otherwise) that contradict the conditions of this License, they do not -> excuse you from the conditions of this License. If you cannot convey a -> covered work so as to satisfy simultaneously your obligations under this -> License and any other pertinent obligations, then as a consequence you may -> not convey it at all. For example, if you agree to terms that obligate you -> to collect a royalty for further conveying from those to whom you convey -> the Program, the only way you could satisfy both those terms and this -> License would be to refrain entirely from conveying the Program. -> -> 13. Use with the GNU Affero General Public License. -> -> Notwithstanding any other provision of this License, you have -> permission to link or combine any covered work with a work licensed -> under version 3 of the GNU Affero General Public License into a single -> combined work, and to convey the resulting work. The terms of this -> License will continue to apply to the part which is the covered work, -> but the special requirements of the GNU Affero General Public License, -> section 13, concerning interaction through a network will apply to the -> combination as such. -> -> 14. Revised Versions of this License. -> -> The Free Software Foundation may publish revised and/or new versions of -> the GNU General Public License from time to time. Such new versions will -> be similar in spirit to the present version, but may differ in detail to -> address new problems or concerns. -> -> Each version is given a distinguishing version number. If the -> Program specifies that a certain numbered version of the GNU General -> Public License "or any later version" applies to it, you have the -> option of following the terms and conditions either of that numbered -> version or of any later version published by the Free Software -> Foundation. If the Program does not specify a version number of the -> GNU General Public License, you may choose any version ever published -> by the Free Software Foundation. -> -> If the Program specifies that a proxy can decide which future -> versions of the GNU General Public License can be used, that proxy's -> public statement of acceptance of a version permanently authorizes you -> to choose that version for the Program. -> -> Later license versions may give you additional or different -> permissions. However, no additional obligations are imposed on any -> author or copyright holder as a result of your choosing to follow a -> later version. -> -> 15. Disclaimer of Warranty. -> -> THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY -> APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT -> HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY -> OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, -> THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -> PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM -> IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF -> ALL NECESSARY SERVICING, REPAIR OR CORRECTION. -> -> 16. Limitation of Liability. -> -> IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -> WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS -> THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY -> GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE -> USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF -> DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD -> PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), -> EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF -> SUCH DAMAGES. -> -> 17. Interpretation of Sections 15 and 16. -> -> If the disclaimer of warranty and limitation of liability provided -> above cannot be given local legal effect according to their terms, -> reviewing courts shall apply local law that most closely approximates -> an absolute waiver of all civil liability in connection with the -> Program, unless a warranty or assumption of liability accompanies a -> copy of the Program in return for a fee. -> -> END OF TERMS AND CONDITIONS -> diff --git a/deps/src/README.md b/deps/src/README.md deleted file mode 100644 index f0aeda51f..000000000 --- a/deps/src/README.md +++ /dev/null @@ -1,82 +0,0 @@ -# libsingular-julia - -This is the C++ library accompanying [Singular.jl](https://github.com/oscar-system/Singular.jl). -It implements the C++ interface from julia to Singular using [CxxWrap.jl](https://github.com/JuliaInterop/CxxWrap.jl) and [libcxxwrap-julia](https://github.com/JuliaInterop/libcxxwrap-julia). - -This library is compiled into a Julia artifact and shipped to the user via -the Julia JLL package -[libsingular_julia_jll](https://github.com/JuliaBinaryWrappers/libsingular_julia_jll.jl). -This JLL package in turn is generated from the sources in this repository and -the build recipe at -. - - -## Quick way to test changes in here - -To test changes you make to the C++ code here, the quickest way is to use the -`run.jl` script bundled in this repository. As a prerequisite, you need a -working C++ compiler and of course Julia. - -Start Julia from this repository as follows: - - julia --project=. run.jl - -This will install a few required Julia packages then build all C++ code, and -finally start a Julia session with an artifact override in place which ensures -that libsingular_julia_jll picks up the copy of the C++ code that was just -compiled. - -To verify the override works, check `libsingular_julia_jll.artifact_dir`; it -should point at a subdirectory of the current directory. - -You can then use the Julia package manager to install or dev `Singular.jl`, -and run its test suite or perform other tests. - - -## Building - -Compiling `libsingular-julia` from source requires a C++ enabled compiler. - -The easiest way to build it is to execute the Julia script `build.jl` (which -in turn is also used by `run.jl`). For this you need to execute it in a Julia -environment in which `Singular_jll` and `CxxWrap` are installed. - -Alternatively, you can also link it against your own `libcxxwrap-julia` -installation and a Singular installation, but this is more work; an -incantation like the following will do it: - -```bash -git clone https://github.com/oscar-system/libsingular-julia \ -cmake -DJulia_PREFIX=/home/user/path/to/julia \ - -DSingular_PREFIX=/home/user/path/to/singular - -DCMAKE_INSTALL_PREFIX=home/user/prefix/for/libsingular-julia \ - -DJlCxx_DIR=/home/user/path/to/libcxxwrap-julia/lib/cmake/JlCxx \ - -DCMAKE_BUILD_TYPE=Release \ - -S libsingular-julia -B build \ - -cmake --build build --config Release --target install -- -j${nproc} -``` - - -### Overriding the default artifacts for Singular.jl - -The `run.jl` script takes care of everything described below, but we document -it in case you need to do any of this manually for some reason. - -Put the following into `~/.julia/artifacts/Overrides.toml` to replace the `libsingular-julia` artifact: - -```toml -[ae4fbd8f-ecdb-54f8-bbce-35570499b30e] -libsingular_julia = "/home/user/prefix/for/libsingular-julia" -``` - -If you were using custom versions of `Singular` and/or `libcxxwrap-julia`, -then their directories used during the build need to be added as well, e.g.: - -```toml -[bcd08a7b-43d2-5ff7-b6d4-c458787f915c] -Singular = "/home/user/path/to/Singular" - -[3eaa8342-bff7-56a5-9981-c04077f7cee7] -libcxxwrap_julia = "/home/user/path/to/libcxxwrap-julia" -``` diff --git a/deps/src/build.jl b/deps/src/build.jl deleted file mode 100644 index 7dec05f43..000000000 --- a/deps/src/build.jl +++ /dev/null @@ -1,46 +0,0 @@ -import Singular_jll, CxxWrap, CMake -using Singular_jll.GMP_jll, Pkg.Artifacts - -# TODO: use ARGS to specify custom build dir? -builddir = "build" -installdir = abspath("install") -JlCxx_DIR = joinpath(CxxWrap.prefix_path(), "lib", "cmake", "JlCxx") - -# In Julia >= 1.6, there is a "fake" GMP_jll which does not include header files; -# see -function gmp_artifact_dir() - artifacts_toml = joinpath(dirname(dirname(Base.pathof(GMP_jll))), "StdlibArtifacts.toml") - - # If this file exists, it's a stdlib JLL and we must download the artifact ourselves - if isfile(artifacts_toml) - meta = artifact_meta("GMP", artifacts_toml) - hash = Base.SHA1(meta["git-tree-sha1"]) - if !artifact_exists(hash) - dl_info = first(meta["download"]) - download_artifact(hash, dl_info["url"], dl_info["sha256"]) - end - return artifact_path(hash) - end - - # Otherwise, we can just use the artifact directory given to us by GMP_jll - return GMP_jll.find_artifact_dir() -end - -const gmp_prefix = gmp_artifact_dir() -const singular_prefix = Singular_jll.artifact_dir - -rm(builddir; force=true, recursive=true) - -run(`$(CMake.cmake) - -DJulia_EXECUTABLE=$(joinpath(Sys.BINDIR, Base.julia_exename())) - -Dextra_cppflags=-I$(gmp_prefix)/include - -Dextra_ldflags=-L$(gmp_prefix)/lib - -DSingular_PREFIX=$(singular_prefix) - -DCMAKE_INSTALL_PREFIX=$(installdir) - -DJlCxx_DIR=$(JlCxx_DIR) - -DCMAKE_BUILD_TYPE=Release - -S . - -B $(builddir) -`) - -run(`$(CMake.cmake) --build $(builddir) --config Release --target install -- -j$(Sys.CPU_THREADS)`) diff --git a/deps/src/run.jl b/deps/src/run.jl deleted file mode 100644 index 60c8de30e..000000000 --- a/deps/src/run.jl +++ /dev/null @@ -1,40 +0,0 @@ -# This script builds libsingular-julia, then starts a fresh Julia instances -# with an appropriate override set for e.g. running the test suite or whatever -# else you'd like. Arguments are passed on verbatim to the subprocess julia, -# so you can invokes this kinda like you'd invoke Julia - -@info "Install needed packages" -using Pkg -Pkg.add(["Singular_jll", "CxxWrap", "CMake", "libsingular_julia_jll"]) -using libsingular_julia_jll - - -@info "Build libsingular-julia" -include("build.jl") - - -mktempdir() do tmpdepot - @info "Created temporary depot at $(tmpdepot)" - - # create override file for libsingular_julia_jll - uuid = string(Base.identify_package("libsingular_julia_jll").uuid) - mkpath(joinpath(tmpdepot, "artifacts")) - open(joinpath(tmpdepot, "artifacts", "Overrides.toml"), "w") do f - write(f, """ - [$(uuid)] - libsingular_julia = "$(installdir)" - """) - end - - # prepend our temporary depot to the depot list... - withenv("JULIA_DEPOT_PATH"=>tmpdepot*":") do - # we need to make sure that precompilation is run again with the override in place - # (just running Pkg.precompile() does not seem to suffice) - run(`touch $(pathof(libsingular_julia_jll))`) - # ... and start Julia, by default with the same project environment - run(`$(Base.julia_cmd()) --project=$(Base.active_project()) $(ARGS)`) - - # TODO: perform some additional steps here, e.g. perhaps - # verify that `libsingular_julia_jll.artifact_dir` is set right? - end -end diff --git a/src/LibSingular.jl b/src/LibSingular.jl index 38f2f2432..8f0e132c6 100644 --- a/src/LibSingular.jl +++ b/src/LibSingular.jl @@ -4,7 +4,7 @@ using CxxWrap import ..Singular: libflint, libantic, libsingular_julia, AbstractAlgebra -@wrapmodule(libsingular_julia) +@wrapmodule(libsingular_julia()) function __init__() @initcxx diff --git a/src/Singular.jl b/src/Singular.jl index 9f286c126..e0a34bb74 100644 --- a/src/Singular.jl +++ b/src/Singular.jl @@ -26,7 +26,6 @@ using Nemo using Pkg using lib4ti2_jll using Singular_jll -using libsingular_julia_jll import Base: abs, checkbounds, convert, deepcopy, deepcopy_internal, denominator, div, divrem, exponent, @@ -77,10 +76,12 @@ export ZZ, QQ, FiniteField, FunctionField, CoefficientRing, Fp # ############################################################################### -const libsingular = Singular_jll.libsingular +include("setup.jl") + const binSingular = Singular_jll.Singular_path -const libsingular_julia = libsingular_julia_jll.libsingular_julia +const _libsingular_julia = Ref(Setup.locate_libsingular()) +libsingular_julia() = _libsingular_julia[] const libflint = Nemo.libflint const libantic = Nemo.libantic @@ -92,6 +93,8 @@ function __init__() windows_error() end + _libsingular_julia[] = Setup.locate_libsingular() + # Initialise Singular ENV["SINGULAR_EXECUTABLE"] = binSingular libSingular.siInit(binSingular) @@ -204,8 +207,6 @@ const VERSION_NUMBER = pkgversion(@__MODULE__) # ############################################################################### -include("setup.jl") - include("AbstractTypes.jl") include("LibSingular.jl") diff --git a/src/setup.jl b/src/setup.jl index d81957aa2..af64414d0 100644 --- a/src/setup.jl +++ b/src/setup.jl @@ -1,11 +1,17 @@ module Setup -using Singular_jll +import Singular_jll import lib4ti2_jll -using BinaryWrappers +import libsingular_julia_jll +import BinaryWrappers +import CxxWrap +import Libdl +import Pidfile +import Pkg +import Pkg.Artifacts -const lib4ti2_binpath = @generate_wrappers(lib4ti2_jll) +const lib4ti2_binpath = BinaryWrappers.@generate_wrappers(lib4ti2_jll) # make sure Singular can find the wrappers function __init__() @@ -58,4 +64,117 @@ end regenerate_libraryfuncdictionary(Singular_jll.find_artifact_dir()) +function jll_artifact_dir(the_jll::Module) + artifacts_toml = joinpath(dirname(dirname(Base.pathof(the_jll))), "StdlibArtifacts.toml") + + # If this file exists, it's a stdlib JLL and we must download the artifact ourselves + if isfile(artifacts_toml) + # the artifact name is always equal to the module name minus the "_jll" suffix + name = replace(string(nameof(the_jll)), "_jll" => "") + meta = Pkg.Artifacts.artifact_meta(name, artifacts_toml) + hash = Base.SHA1(meta["git-tree-sha1"]) + if !Pkg.Artifacts.artifact_exists(hash) + dl_info = first(meta["download"]) + Pkg.Artifacts.download_artifact(hash, dl_info["url"], dl_info["sha256"]) + end + return Pkg.Artifacts.artifact_path(hash) + end + + # Otherwise, we can just use the artifact directory given to us by GMP_jll + return the_jll.find_artifact_dir() +end + +function build_code(src_hash) + @info "Bundled C++ sources don't match libsingular_julia_jll" + + depsdir = abspath(joinpath(@__DIR__, "..", "deps")) + srcdir = joinpath(depsdir, "src") + + # encode the Julia version into into the build & install paths + # as different Julia versions tend to not be ABI compatible + builddir = joinpath(depsdir, "build-$VERSION") + installdir = joinpath(depsdir, "install-$VERSION") + + # check if we already built the code and if so, just use that + lib_path = joinpath(installdir, "lib", "libsingular_julia.$(Libdl.dlext)") + treehash_path = joinpath(installdir, "lib", "libsingular_julia.treehash") + try + bin_hash = read(treehash_path, String) + if bin_hash == src_hash + @info "Using already compiled bundled C++ code" + return lib_path + end + catch + end + + # TODO: check if this is a dev version of Singular.jl; if so, continue. If + # not, i.e. if this is a regular version, then refuse to run + + + @info "Compiling libsingular_julia ..." + + try + run(`cmake --version`) + catch + error("Could not locate 'cmake' binary, needed to build libsingular-julia") + end + + JlCxx_DIR = joinpath(CxxWrap.prefix_path(), "lib", "cmake", "JlCxx") + julia_exec = joinpath(Sys.BINDIR, Base.julia_exename()) + + gmp_prefix = jll_artifact_dir(Singular_jll.GMP_jll) + singular_prefix = jll_artifact_dir(Singular_jll) + + Pidfile.mkpidlock("$installdir.lock") do + # delete any previous build or install artifacts + rm(builddir; force=true, recursive=true) + rm(installdir; force=true, recursive=true) + + withenv("JULIA_LOAD_PATH" => nothing) do + run(`cmake + -DJulia_EXECUTABLE=$julia_exec + -DJlCxx_DIR=$(JlCxx_DIR) + -Dgmp_prefix=$gmp_prefix + -DSingular_PREFIX=$(singular_prefix) + -DCMAKE_INSTALL_PREFIX=$(installdir) + -DCMAKE_BUILD_TYPE=Release + -S $srcdir + -B $builddir + `) + + run(`cmake + --build $builddir + --config Release + --target install + -- + -j$(Sys.CPU_THREADS) + `) + end + + write(treehash_path, String(src_hash)) + end + + return lib_path + +end + +function locate_libsingular() + jll_path = joinpath(libsingular_julia_jll.find_artifact_dir(), "lib", "libsingular_julia.treehash") + jll_hash = chomp(read(jll_path, String)) + + # compare the sources used to build libsingular_julia_jll with bundled copies + # by comparing tree hashes + src_hash = bytes2hex(Pkg.GitTools.tree_hash(joinpath(@__DIR__, "..", "deps", "src"))) + + if jll_hash == src_hash + # if the tree hashes match then we use the JLL + path = libsingular_julia_jll.get_libsingular_julia_path() + else + # tree hashes differ: we use the bundled sources. + path = build_code(src_hash) + end + @debug "Use libsingular_julia from $path" + return path +end + end # module