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

pak often forgets how to build from source #103

Closed
hadley opened this issue Mar 15, 2019 · 15 comments
Closed

pak often forgets how to build from source #103

hadley opened this issue Mar 15, 2019 · 15 comments

Comments

@hadley
Copy link
Member

hadley commented Mar 15, 2019

remove.packages("ellipsis")
pak::pkg_install("r-lib/ellipsis")
#> ℹ Checking for package metadata updates
#> ✔ All 10 metadata files are current.                                            
#> ✔ Using session cached package metadata
#> ✔ Using cached package metadata                                                 
#>                                                                                 
#> → Will install 1 packages:
#>   r-lib/ellipsis
#>   
#> → Will not update 1 packages.
#> 
#> → Will download 1 packages with unknown size.
#> 
#> ℹ Building ellipsis 0.1.0.9000                                                  
#> Error: Could not find tools necessary to compile a package

After running

pak:::pkg_data$remote$run(function() pkgbuild::has_build_tools())
#> [1] TRUE

The problem appears to go away. Running pak_setup() also seems to fix the problem. I don't know why it fails in the first place (since I should always be able to compile packages). I can't reliably trigger it, but it happens to me pretty frequently.

@hadley hadley changed the title pak_sitrep() should include check_build_tools() pak often forgets how to build from source May 29, 2019
@hadley
Copy link
Member Author

hadley commented Jun 5, 2019

pak:::pkg_data$remote$run_with_output(function() pkgbuild::has_build_tools(TRUE))

@hadley
Copy link
Member Author

hadley commented Jun 24, 2019

Ok here it is

[master] > pak:::pkg_data$remote$run_with_output(function() pkgbuild::has_build_tools(TRUE))
$code
[1] 200

$message
[1] "done file1837474d2bd7f"

$result
[1] FALSE

$stdout
[1] "Running /Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB foo.c\nccache clang -Qunused-arguments  -I\"/Library/Frameworks/R.framework/Resources/include\" -DNDEBUG   -I/usr/local/include   -fPIC  -Wall -g -O2  -c foo.c -o foo.o\n\033[31m/bin/sh: ccache: command not found\n\033[39m\033[31mmake: *** [foo.o] Error 127\n\033[39m"

$stderr
[1] "Trying to compile a simple C file\n"

$error
NULL

attr(,"class")
[1] "callr_session_result"

@gaborcsardi
Copy link
Member

Aha! ccache!

@gaborcsardi
Copy link
Member

@hadley how did you install and set up ccache? Is it from brew? Do you have sg in your user Makevars? It is possible that it is because of this: r-lib/pkgbuild#76

@hadley
Copy link
Member Author

hadley commented Jun 24, 2019

My ~/.R/Makevars is:

CC=ccache clang -Qunused-arguments
CXX=ccache clang++ -Qunused-arguments

And which ccache gives /usr/local/bin/ccache.

@gaborcsardi
Copy link
Member

@hadley One last question. Do you have /usr/local/bin in /etc/paths? Or do you change the PATH somewhere else, e.g. your shell profile? I don't quite understand why R CMD SHLIB would not find ccache.

@hadley
Copy link
Member Author

hadley commented Jun 25, 2019

I change it in my bash profile:

export PATH="/usr/local/bin:$PATH:/usr/local/sbin:$HOME/bin:/usr/local/ggobi/bin:/Users/hadley/node_modules/.bin:/Library/TeX/texbin"

@gaborcsardi
Copy link
Member

I think that profile does not run when you start RStudio from the GUI.

But still, /usr/local/bin should be on the PATH by default. What do you have in /etc/paths? Or /private/etc/paths?

Also, can you pls run these from an RStudio that you started from a GUI:

Sys.getenv("PATH")
callr::r(function() Sys.getenv("PATH"))

Thanks!

@hadley
Copy link
Member Author

hadley commented Jun 25, 2019

By hand, from console

Sys.getenv("PATH")
#> [1] "/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/Library/TeX/texbin:/opt/X11/bin:/Applications/Wireshark.app/Contents/MacOS"
callr::r(function() Sys.getenv("PATH"))
#> [1] "/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/Library/TeX/texbin:/opt/X11/bin:/Applications/Wireshark.app/Contents/MacOS"

And as reprex, just to check they're the same:

Sys.getenv("PATH")
#> [1] "/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/Library/TeX/texbin:/opt/X11/bin:/Applications/Wireshark.app/Contents/MacOS"
callr::r(function() Sys.getenv("PATH"))
#> [1] "/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/Library/TeX/texbin:/opt/X11/bin:/Applications/Wireshark.app/Contents/MacOS"

Created on 2019-06-25 by the reprex package (v0.2.1.9000)

@hadley
Copy link
Member Author

hadley commented Jul 2, 2019

Run pak:::pkg_data$remote$run_with_output(function() Sys.getenv("PATH")) next time it happens

@hadley
Copy link
Member Author

hadley commented Jul 4, 2019

callr::r(function() Sys.getenv("PATH"))
#> [1] "/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/Library/TeX/texbin:/opt/X11/bin:/Applications/Wireshark.app/Contents/MacOS"
pak:::pkg_data$remote$run_with_output(function() Sys.getenv("PATH"))$result
#> [1] "/usr/bin:/bin:/usr/sbin:/sbin"

@gaborcsardi
Copy link
Member

So for record, this is what happens.

  1. When RStudio starts up, it starts running the .Rprofile immediately, before its setup is complete.
  2. On macOS, if you start RStudio from the GUI, PATH is not set "correctly" at the startup time. Rstudio reads /etc/paths as part of the startup process, and sets PATH, but that's too late for the subprocesses started from .Rprofile.
  3. pak is loaded in .Rprofile, and it immediately starts a background process.
  4. ~/.R/Makevars has CC=ccache clang and ccache is on /usr/local/bin.

So when RStudio starts up and runs the .Rprofile which starts the pak subprocess, the PATH does not include /usr/local/bin, and then the build fails, because ccache is not available.

@nlbjan1
Copy link

nlbjan1 commented Jul 12, 2019

@gaborcsardi Just saw your userR! presentation, regarding the question about caching compiled packages, I wanted to add on: Would it make sense to suggest installation of ccache and integrate it directly into pak so it will always be used and users don't have to bother with Makevars? Maybe not worth the extra complexity in pak itself?

@gaborcsardi
Copy link
Member

@nlbjan1 maybe we could suggest it in the documentation. I would probably not install it from pak, because that's a system task.

gaborcsardi added a commit that referenced this issue Jul 12, 2019
Need a : separator between the current path, and the newly
added values. Really fixes #103.
bobjansen added a commit to bobjansen/pak that referenced this issue Jul 12, 2019
As a reaction to a question raised in the audience during userR! and the
discussion on r-lib#103, an extra section in the README that explains
(hopefully clearly) how to setup ccache for use with R and pak to speed
up installation of packages that need compilation.

Credits to @eddelbuettel for making me aware of this idea. Settings taken
from his blog at

http://dirk.eddelbuettel.com/blog/2017/11/27/

Compared to the post I've reduced maximum cache size from 5G to 1G as
installation of packages tidyverse and data.table only generates of
127mb of cache and extended the inline comments somewhat.
bobjansen added a commit to bobjansen/pak that referenced this issue Jul 12, 2019
As a reaction to a question raised in the audience during userR! and the
discussion on r-lib#103, an extra section in the README that explains
(hopefully clearly) how to setup ccache for use with R and pak to speed
up installation of packages that need compilation.

Credits to @eddelbuettel for making me aware of this idea. Settings taken
from his blog at

http://dirk.eddelbuettel.com/blog/2017/11/27/

Compared to the post I've reduced maximum cache size from 5G to 1G as
installation of packages tidyverse, devtools and data.table only
generates less than 150M of cache and extended the inline comments
somewhat.
bobjansen added a commit to bobjansen/pak that referenced this issue Jul 12, 2019
As a reaction to a question raised in the audience during userR! and the
discussion on r-lib#103, an extra section in the README that explains
(hopefully clearly) how to setup ccache for use with R and pak to speed
up installation of packages that need compilation.

Credits to @eddelbuettel for making me aware of this idea. Settings taken
from his blog at

http://dirk.eddelbuettel.com/blog/2017/11/27/

Compared to the post I've reduced maximum cache size from 5G to 1G as
installation of packages tidyverse, devtools and data.table only
generates less than 150M of cache and extended the inline comments
somewhat.
bobjansen added a commit to bobjansen/pak that referenced this issue Jul 12, 2019
As a reaction to a question raised in the audience during userR! and the
discussion on r-lib#103, an extra section in the README that explains
(hopefully clearly) how to setup ccache for use with R and pak to speed
up installation of packages that need compilation.

Credits to @eddelbuettel for making me aware of this idea. Settings taken
from his blog at

http://dirk.eddelbuettel.com/blog/2017/11/27/

Compared to the post I've reduced maximum cache size from 5G to 1G as
installation of packages tidyverse, devtools and data.table only
generates less than 150M of cache and extended the inline comments
somewhat.
bobjansen added a commit to bobjansen/pak that referenced this issue Jul 12, 2019
As a reaction to a question raised in the audience during userR! and the
discussion on r-lib#103, an extra section in the README that explains
(hopefully clearly) how to setup ccache for use with R and pak to speed
up installation of packages that need compilation.

Credits to @eddelbuettel for making me aware of this idea. Settings taken
from his blog at

http://dirk.eddelbuettel.com/blog/2017/11/27/

Compared to the post I've reduced maximum cache size from 5G to 1G as
installation of packages tidyverse, devtools and data.table generates
less than 150M of cache files and extended the inline comments
somewhat.
@bobjansen
Copy link

I didn't realize that my reference in the commit and editing it would spam this thread :( In any case, I've added a paragraph on this in the README.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants