Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

switch to using Wolfram app discovery #68

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
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
15 changes: 12 additions & 3 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ jobs:
- uses: julia-actions/cache@v1
- uses: julia-actions/julia-buildpkg@v1
- uses: julia-actions/julia-runtest@v1
env:
JULIA_DEBUG: MathLink
- uses: julia-actions/julia-processcoverage@v1
- uses: codecov/codecov-action@v1
with:
Expand All @@ -40,11 +42,17 @@ jobs:
echo 'Installing Wolfram Engine...'
brew install --cask wolfram-engine
echo 'Installed Wolfram Engine.'

- uses: julia-actions/setup-julia@v1
- uses: julia-actions/cache@v1
- uses: julia-actions/julia-buildpkg@v1
- run: mdfind "kMDItemCFBundleIdentifier == 'com.wolfram.*'"
- run: mdls "/Applications/Wolfram Engine.app"
- run: julia --project -e 'using WolframAppDiscovery_jll; run(`$(wolfram_app_discovery()) default`)'
- uses: julia-actions/julia-runtest@v1
env:
JULIA_DEBUG: MathLink
RUST_BACKTRACE: full
- uses: julia-actions/julia-processcoverage@v1
- uses: codecov/codecov-action@v1
with:
Expand Down Expand Up @@ -102,9 +110,10 @@ jobs:
- uses: julia-actions/setup-julia@v1
- uses: julia-actions/cache@v1
- uses: julia-actions/julia-buildpkg@v1
env:
JULIA_WOLFRAM_DIR: '${{ runner.temp }}\${{ env.WOLFRAMENGINE_INSTALLATION_SUBDIRECTORY }}'
- uses: julia-actions/julia-runtest@v1
env:
JULIA_DEBUG: MathLink
WOLFRAM_APP_DIRECTORY: '${{ runner.temp }}\${{ env.WOLFRAMENGINE_INSTALLATION_SUBDIRECTORY }}'
- uses: julia-actions/julia-processcoverage@v1
- uses: codecov/codecov-action@v1
with:
Expand Down
1 change: 1 addition & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ version = "0.5.1"
[deps]
Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
WolframAppDiscovery_jll = "630c5959-bfb3-598a-bb45-cbcabe526631"

[compat]
julia = "1"
Expand Down
42 changes: 3 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ This package provides access to Mathematica/Wolfram Engine via the MathLink libr

## Installation

The package requires an installation of either [Mathematica](http://www.wolfram.com/mathematica/) or the free [Wolfram Engine](https://www.wolfram.com/engine/). It will attempt to find the installation at build time; if this fails, please see the [installation troubleshoot](#installation-troubleshoot) below.
The package requires an installation of either [Mathematica](http://www.wolfram.com/mathematica/) or the free [Wolfram Engine](https://www.wolfram.com/engine/). It will attempt to find the installation at load time using [wolfram-app-discovery](https://github.com/WolframResearch/wolfram-app-discovery-rs). A precise location can be specied by setting the `WOLFRAM_APP_DIRECTORY` environment variable.


## Usage

The main interface consists of the `W""` string macro for specifying symbols. These are call-overloaded for building more complicated expressions.
Expand Down Expand Up @@ -166,42 +166,6 @@ julia> W2Mstr(W`b/(c^(a+c))`)
Printing in Jupyter notebooks is, by default, done in latex.
This can be turned off with the command `MathLink.set_texOutput(false)`

## Installation Troubleshoot
The package requires an installation of either [Mathematica](http://www.wolfram.com/mathematica/) or the free [Wolfram Engine](https://www.wolfram.com/engine/). It will attempt to find the installation at build time; if this fails, you will need to set the following environment variables:
- `JULIA_MATHKERNEL`: the path of the MathKernel executable
- `JULIA_MATHLINK`: the path of the MathLink dynamic library named
- `libML64i4.so`/ `libML32i4.so` on Linux
- `ml64i4.dll`/`ml32i4.dll`/`libML64.dll`/ `libML32.dll` on Windows

After setting, you may need to manually build the package
```julia
(@v1.X) pkg> build MathLink
```

A separate workaround is to directly edit the deps/deps.jl file, which should be located (on Linux) at `~/.julia/packages/MathLink/<version dependent>/deps/deps.jl`

The contents of `deps.jl` could for instance, read
```julia
const mlib = "/usr/local/Wolfram/Mathematica/11.3/SystemFiles/Links/MathLink/DeveloperKit/Linux-x86-64/CompilerAdditions/libML64i4"
const mker = "WolframKernel"
```
After creating the file `deps.jl` try loading MathLink the usual way
```julia
(@v1.X) pkg> using MathLink
```
If you do not have a Mathematica installation at all, the above trick still works, but then you must leave the path blank
```julia
const mlib = ""
const mker = "WolframKernel"
```
Loading `MathLink` then proclaims
```julia
julia> using MathLink
[ Info: Precompiling MathLink [18c93696-a329-5786-9845-8443133fa0b4]
[ Info: Pretending fake installation works
```


## Notes

- Mathematica, Wolfram, MathLink are all trademarks of Wolfram Research.
114 changes: 0 additions & 114 deletions deps/build.jl

This file was deleted.

18 changes: 5 additions & 13 deletions src/MathLink.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,14 @@ using Printf

export @W_str, @W_cmd, weval

using WolframAppDiscovery_jll

###Checking that the deps.jl file exists. And throwing a readable error if it does not!

FilePath=@__DIR__
FilePath=FilePath[1:end-4]*"/deps/deps.jl"


#if isfile("../deps/deps.jl")
#include("../deps/deps.jl")
if isfile(FilePath)
include(FilePath)
if VERSION >= v"1.8"
libwstp::String = ""
else
error("The file $FilePath does not exist.\n"
*"This usually means that the MathLink installation failed.\n"
*"Have you checked that Mathematica is installed on your system?")
libwstp = ""
end

include("types.jl")
include("consts.jl")
include("init.jl")
Expand Down
30 changes: 22 additions & 8 deletions src/init.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,34 @@ function refcount_dec()
# refcount zero, all objects finalized, now finalize MathLink
if Threads.atomic_sub!(REFCOUNT, 1) == 1
# void WSDeinitialize(WSENV env)
ccall((:MLDeinitialize, mlib), Cvoid, (CEnv,), env)
ccall((:WSDeinitialize, libwstp), Cvoid, (CEnv,), env)
env.ptr = C_NULL
end
end


function __init__()
if mlib == ""
###when JULIA_REGISTRYCI_AUTOMERGE=true the mlib is an empty string, and we can test for that
# We need to be able to install and load this package without error for
# Julia's registry AutoMerge to work. Skip initialization of the mathlink library.
@info "Pretending fake installation works"
else

out = IOBuffer()
if !success(pipeline(`$(wolfram_app_discovery()) default --raw-value wstp-compiler-additions-directory`, out))
@debug "Could not find WSTP installation"
return
end
wstp_dir = String(take!(out))

if Sys.iswindows()
global libwstp = joinpath(wstp_dir, "..", "SystemAdditions", "wstp$(Sys.WORD_SIZE)i4.dll")
elseif Sys.isapple()
global libwstp = joinpath(wstp_dir, "wstp.framework", "wstp")
elseif Sys.isunix()
global libwstp = joinpath(wstp_dir, "libWSTP$(Sys.WORD_SIZE)i4.so")
end

@debug "WSTP installation found" wstp_dir libwstp

if libwstp != ""
# WSENV WSInitialize(WSEnvironmentParameter p)
env.ptr = ccall((:MLInitialize, mlib), CEnv, (Ptr{Cvoid},), C_NULL)
env.ptr = ccall((:WSInitialize, libwstp), CEnv, (Ptr{Cvoid},), C_NULL)
if env.ptr == C_NULL
error("Could not initialize MathLink library")
end
Expand Down
Loading