Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions etc/README.override.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# How to use the override scripts

## Using AlgebraicSolving.jl with a different version of msolve than what `msolve_jll` provides

This can be useful for various reasons e.g.,

- you need to test msolve.jl with a newer msolve version, perhaps even its master branch,
- you need to test with a msolve with custom compiler settings (e.g. to enable debugging),
- and so on.

For this to work, follow these instructions:

1. Obtain a copy of the msolve sources, probably from a clone of the msolve git repository.
Let's say this is in directory `MSOLVEROOT`.

2. Execute `./autogen.sh` in the `MSOLVEROOT` directory.

3. Build msolve by executing the `etc/setup_override_dir.jl` script in the `override` environment.
Arguments:
- first argument: the `MSOLVEROOT`
- second argument: the directory where the override environment shall be installed, e.g. `/tmp/msolve_jll_override`.
- third argument (optional): a temp build directory to make use of incremental builds,
e.g. `/tmp/msolve_jll_override_build`. If not given, a temporary directory will be created
and deleted after the build.
- `--no-configure` (optional): if given, the script will not execute `./configure` in the `MSOLVEROOT`,
but assume that this has already been done. This can be useful if you want to save time by doing incremental builds,
or if you need to pass special arguments to `./configure` that the script does not know about.
- `--yes` (optional): if given, the script will not ask for confirmation before deleting the override directory (if it already exists).
- `--verbose` (optional): if given, the script will print more verbose output.

To give a concrete example you could invoke

julia --proj=override etc/setup_override_dir.jl $MSOLVEROOT /tmp/msolve_jll_override /tmp/msolve_jll_override_build

for the first time, and then for subsequent builds (after making changes to the msolve sources) you could invoke

julia --proj=override etc/setup_override_dir.jl $MSOLVEROOT /tmp/msolve_jll_override /tmp/msolve_jll_override_build --no-configure --yes

4. Use the `etc/run_with_override.jl` script with the exact same Julia executable
and the override environment we just prepared.

julia --proj=override etc/run_with_override.jl /tmp/msolve_jll_override

5. This opens a Julia session with the override in effect. You can now e.g. load AlgebraicSolving.jl
via `using AlgebraicSolving`, or install other packages (such as Oscar) and test with them.
51 changes: 51 additions & 0 deletions etc/run_with_override.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#
# parse arguments
#
length(ARGS) >= 1 || error("must provide path of msolve override directory as first argument")
msolveoverride = popfirst!(ARGS)

isdir(msolveoverride) || error("The given override path '$(msolveoverride)' is not a valid directory")
msolveoverride = abspath(msolveoverride)

#
#
#
@info "Install needed packages"
using Pkg
Pkg.develop(path=dirname(@__DIR__))
Pkg.add(["msolve_jll"])
Pkg.instantiate()

#
#
#
function add_jll_override(depot, pkgname, newdir)
pkgid = Base.identify_package("$(pkgname)_jll")
pkguuid = string(pkgid.uuid)
mkpath(joinpath(depot, "artifacts"))
open(joinpath(depot, "artifacts", "Overrides.toml"), "a") do f
write(f, """
[$(pkguuid)]
$(pkgname) = "$(newdir)"
""")
end

# 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 $(Base.locate_package(pkgid))`)
end

tmpdepot = mktempdir(; cleanup=true)
@info "Created temporary depot at $(tmpdepot)"

# create override file for msolve_jll
add_jll_override(tmpdepot, "msolve", msolveoverride)

# prepend our temporary depot to the depot list...
withenv(
"JULIA_DEPOT_PATH"=>tmpdepot*":"*join(DEPOT_PATH, ":"),
) do

# ... and start Julia, by default with the same project environment
run(`$(Base.julia_cmd()) --project=$(Base.active_project()) $(ARGS)`)
end
100 changes: 100 additions & 0 deletions etc/setup_override_dir.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# This Julia script sets up a directory with msolve compiled from a local path,
# then "installs" this msolve for use by the `run_with_override.jl` script

#
# parse arguments
#
length(ARGS) >= 1 || error("must provide path of msolve source directory as first argument")
length(ARGS) >= 2 || error("must provide path of destination directory as second argument")
msolve_prefix = popfirst!(ARGS)
prefix = popfirst!(ARGS)

if length(ARGS) > 0 && !startswith(ARGS[1], "--")
build_dir = popfirst!(ARGS)
else
build_dir = mktempdir(; cleanup = true)
end

run_configure = true
overwrite_allow = false
verbose = false
left_ARGS = String[]
while !isempty(ARGS)
arg = popfirst!(ARGS)
if arg == "--no-configure"
global run_configure = false
elseif arg == "--yes"
global overwrite_allow = true
elseif arg == "--verbose"
global verbose = true
else
push!(left_ARGS, arg)
end
end


# validate arguments
isdir(msolve_prefix) || error("The given msolve prefix '$(msolve_prefix)' is not a valid directory")
if ispath(prefix)
if !overwrite_allow
print("The given installation prefix '$(prefix)' already exists. Overwrite? [Y/n] ")
overwrite_allow = lowercase(readline()) in ["y", "yes", ""]
end
if overwrite_allow
rm(prefix; force=true, recursive=true)
else
error("Aborting")
end
end

# convert into absolute paths
mkpath(prefix)
prefix = abspath(prefix)
msolve_prefix = abspath(msolve_prefix)
mkpath(build_dir)
build_dir = abspath(build_dir)

#
# Install needed packages
#
@info "Install needed packages"
using Pkg
using Artifacts
Pkg.add(["JLLPrefixes"])
Pkg.instantiate()

using JLLPrefixes

cd(build_dir)

if run_configure
@info "Configuring msolve in $(build_dir) for $(prefix)"

deps = ["GMP_jll", "FLINT_jll", "MPFR_jll"]
artifact_paths = collect_artifact_paths(deps)
deps_path = mktempdir(; cleanup=false)
deploy_artifact_paths(deps_path, artifact_paths) # collect all (transitive) dependencies into one tree

extraargs = [
"CFLAGS=-I$(joinpath(deps_path, "include"))",
"LDFLAGS=-L$(joinpath(deps_path, "lib"))",
]

configure_cmd = `$(msolve_prefix)/configure
--prefix=$(prefix)
$(extraargs)
$(left_ARGS)
`

verbose && @show configure_cmd

# TODO: redirect the output of configure into a log file
@show run(configure_cmd)
end


@info "Building msolve in $(build_dir)"
run(`make -j$(Sys.CPU_THREADS) $(verbose ? "V=1" : [])`)

@info "Installing msolve to $(prefix)"
run(`make install $(verbose ? "V=1" : [])`)
Loading