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

Get Rhome and libR from Preferences.jl when provided #496

Merged
merged 39 commits into from
Jan 30, 2024

Conversation

frankier
Copy link
Contributor

@frankier frankier commented Aug 4, 2023

See: #490

@frankier frankier marked this pull request as draft August 4, 2023 11:48
@frankier frankier marked this pull request as ready for review August 4, 2023 12:12
@codecov
Copy link

codecov bot commented Aug 14, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (5d0ddeb) 75.76% compared to head (1273105) 75.77%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #496      +/-   ##
==========================================
+ Coverage   75.76%   75.77%   +0.01%     
==========================================
  Files          26       26              
  Lines        1642     1643       +1     
==========================================
+ Hits         1244     1245       +1     
  Misses        398      398              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@frankier
Copy link
Contributor Author

Hi @palday. This is ready for review now and the tests seem to pass.

An explanation of the approach is given in my documentation changes here. Please let me know if you need any extra info.

@frankier frankier marked this pull request as draft August 14, 2023 14:01
@frankier frankier marked this pull request as ready for review August 14, 2023 15:08
@frankier
Copy link
Contributor Author

One aim of this PR is to make it possible to install RCall without an R installation. The reason is that RCall may get installed at the same time as CondaPkg, but we may need CondaPkg to get our R installation.

At first it seems like it would be possible to proceed with precompilation of RCall with just a dummy value for Rhome, however, when other modules which import RCall are precompiled they will run the __init__ . I tried an approach that checked for currently_compiling() = ccall(:jl_generating_output, Cint, ()) != 0 in __init__ and skipped the init in that case, however this will mean an R interpreter is not started, and apparently this is needed even during precompliation time for the R_str macro. The resulting segfault was a bit surprising to me -- but I suppose the R runtime is needed even at this stage for such a close integration.

Therefore the only thing to do is disable precompilation entirely when no Rhome is available. Thanks to the usage of Preferences, the preference is marked as a compile time preference and precompilation will be retriggered. An error message is printed in case the module is actually imported at run-time without having a configured Rhome.

I am interested in whether there is a subset of this module which is safe to precompile without an R interpreter for the future, which might allow for a cleaner solution for people only needing this subset, but for now this PR is as far as I can tell a minimally invasive change to getting things working nicely with Preferences and things that can integrated using Preferences such as CondaPkg.

@palday
Copy link
Collaborator

palday commented Aug 29, 2023

@frankier I haven't forgotten you! But I also probably won't review this today, my apologies. 😦

Thanks for your contribution.

@ParadaCarleton
Copy link

This would definitely be super useful! I'd be very happy to see it merged.

@palday palday self-requested a review September 7, 2023 23:33
Project.toml Show resolved Hide resolved
docs/src/installation.md Outdated Show resolved Hide resolved
@frankier
Copy link
Contributor Author

Updated with your comments. I guess the tests are false negatives? They don't seem to be to do with any of the changes and weren't there before (apart from Windows latest which was on master)?

docs/src/installation.md Outdated Show resolved Hide resolved
@frankier
Copy link
Contributor Author

frankier commented Jan 8, 2024

Thanks for cleaning up the tests and for the feedback.

It looks like this test is failing https://github.com/JuliaInterop/RCall.jl/actions/runs/7444228626/job/20250301671?pr=496

Last time I looked it was failing due to a problem present on main, but now it seems to be an actual error. I guess the location of R.dll is being guessed incorrectly? Do you have any ideas? I guess it wasn't introduced during the test refactoring? I don't have a convenient way to test with Windows locally, but will try to set-up/fire-up a VM or something to troubleshoot in case the answer to those two questions is a negative.

@palday
Copy link
Collaborator

palday commented Jan 8, 2024

Thanks for cleaning up the tests and for the feedback.

It looks like this test is failing https://github.com/JuliaInterop/RCall.jl/actions/runs/7444228626/job/20250301671?pr=496

Last time I looked it was failing due to a problem present on main, but now it seems to be an actual error. I guess the location of R.dll is being guessed incorrectly? Do you have any ideas? I guess it wasn't introduced during the test refactoring? I don't have a convenient way to test with Windows locally, but will try to set-up/fire-up a VM or something to troubleshoot in case the answer to those two questions is a negative.

Same here -- I've got a Windows VM set up, but I'm really slow figuring it out. AFAICT the path is correct, but there's something about loading DLLs not in the system variable %PATH% that doesn't work. I haven't yet figured it out, but I'm working on it when I get a few minutes in the evenings. 🙁

There was also an issue with the CI on macOS, but it looked to be a more fundamental issue with Conda and the availability of md5 vs md5sum vs something else, so I just disabled that check. The last bit to get this merged is understanding the limitations on different platforms (e.g. "Linux can handle all this dynamically, but Windows requires setting XXX") and having the CI reflect that. Once we have that, I think this is good to go! So close!

@frankier
Copy link
Contributor Author

Hi! I just checked this on a Windows laptop I got access to. Using dependencywalker.exe, I found that BLAS wasn't being found which led me to realise that this was actually a bug in the test code that was only surfacing on Windows. The CondaPkg environment is not activated(!) Apparently on the other systems another version of BLAS just gets picked up. On non-Conda R it's not a problem because everything is compiled into the DLLs I think. I fixed this and added a note to the docs. I also marked the information about using with CondaPkg as experimental.

@frankier
Copy link
Contributor Author

Okay -- another failure on Windows. I feel like it worked correctly locally but I will look into it soon.

@palday
Copy link
Collaborator

palday commented Jan 21, 2024

Okay -- another failure on Windows. I feel like it worked correctly locally but I will look into it soon.

I feel like we're heading in the right direction -- thanks for your patience and efforts!

docs/src/installation.md Outdated Show resolved Hide resolved
docs/src/installation.md Outdated Show resolved Hide resolved
@@ -39,6 +39,7 @@ set_preferences!(RCALL_UUID,
"Rhome" => target_rhome, "libR" => locate_libR(target_rhome))
RCall = nothing
CondaPkg.withenv() do
Pkg.build("RCall")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this still needed?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seemed to be in my testing.

if Rhome == ""
error(
# This should actually error much sooner, but this is just in case
isempty(Rhome) && error(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ha! Mixed feelings about this sneaky hack to pass coverage. The reason there is no coverage here is because when we shell out in installation.jl coverage stops being measured. It's probably not worth tracking it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's definitely a hack but it's one I'm comfortable with for such "defense in depth" type measures.

@frankier
Copy link
Contributor Author

Thanks for the docs feedback. I just left a couple of small double-checking comments back and then I guess merge time?

@palday palday merged commit 31e7859 into JuliaInterop:master Jan 30, 2024
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants