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

Add ccache #143

Closed
krlmlr opened this issue Aug 21, 2020 · 10 comments
Closed

Add ccache #143

krlmlr opened this issue Aug 21, 2020 · 10 comments

Comments

@krlmlr
Copy link
Contributor

@krlmlr krlmlr commented Aug 21, 2020

for regular compiles and for building packages.

  • Define ccache package
    • upstream msys2 package works out of the box, perhaps remove man pages
  • Install ccache
    • It seems necessary to install in both {mingw32,mingw64}/{bin,lib}; installing via pacman -U puts it into /usr/{bin,lib}, makepkg-mingw doesn't seem to pick it up from there
  • Update makepkg*.conf
    • sed "/^BUILDENV/ s/!ccache/ccache/"
    • Add `PATH="/mingw{32,64}/lib/ccache/bin:${PATH}"
  • Add /usr/lib/ccache/bin to $PATH
  • Document how to turn off ccache (set CCACHE_DISABLE environment var)

Would you support that? How can I help?

@jeroen
Copy link
Member

@jeroen jeroen commented Aug 21, 2020

It seems necessary to install in both {mingw32,mingw64}/{bin,lib}; installing via pacman -U puts it into /usr/{bin,lib},

You are confusing mingw-packages with msys-packages. The latter are only used for the msys build environment itself, they are not useful for building native windows software like R.

You probably want to port this one: https://github.com/msys2/MINGW-packages/tree/master/mingw-w64-ccache

@krlmlr
Copy link
Contributor Author

@krlmlr krlmlr commented Aug 21, 2020

I successfully ported the mingw package you pointed to, happy to submit a PR. The package gets installed in /usr though, I believe we need it to live in /c/rtools40/{mingw32,mingw64} so that it is used by makepkg-mingw .

@jeroen
Copy link
Member

@jeroen jeroen commented Aug 21, 2020

If you build with makepkg-mingw it will be installed in /mingw{32,64}

@krlmlr
Copy link
Contributor Author

@krlmlr krlmlr commented Aug 21, 2020

Confirmed, I need to run pacman -U for both files created.

Will report with what is needed to enable ccache for building packages.

@krlmlr
Copy link
Contributor Author

@krlmlr krlmlr commented Aug 31, 2020

I have now successfully taught makepkg-mingw to use ccache -- need to set PATH in makepkg*.conf. The instructions in the ArchLinux documentation at https://wiki.archlinux.org/index.php/Ccache didn't work for me.

What's the best way to instruct R to use ccache for building R packages? Per https://github.com/r-windows/docs/blob/master/faq.md#how-does-r-find-compilers it won't be picked up from the $PATH. Should we tweak etc/*/Makeconf in R's installation, is there a better way?

An alternative way of running ccache is to replace gcc, g++ etc. with symlinks to the ccache binary. Need to ensure that the correct symlinks are restored when uninstalling ccache.

@jeroen
Copy link
Member

@jeroen jeroen commented Aug 31, 2020

You can override CC and CXX in your personal ~/.R/Makevars file. Maybe something like this:

CC=$(BINPREF)ccache $(BINPREF)gcc

Or from R:

dir.create("~/.R")
writeLines("CC=$(BINPREF)ccache $(BINPREF)gcc", "~/.R/Makevars")
writeLines("CXX=$(BINPREF)ccache $(BINPREF)g++", "~/.R/Makevars")
writeLines("CXX11=$(BINPREF)ccache $(BINPREF)g++", "~/.R/Makevars")
writeLines("CXX14=$(BINPREF)ccache $(BINPREF)g++", "~/.R/Makevars")
writeLines("CXX17=$(BINPREF)ccache $(BINPREF)g++", "~/.R/Makevars")
@krlmlr
Copy link
Contributor Author

@krlmlr krlmlr commented Aug 31, 2020

Thanks. Achieving great results with the following combo:

dir.create("~/.R")

vars <- c("CC", "CXX", "CXX11", "CXX14", "CXX17")
code <- paste0(vars, " := $(BINPREF)ccache $(", vars, ")")

writeLines(code, "~/.R/Makevars")

writeLines(
  c(
    'PATH="${RTOOLS40_HOME}\\usr\\bin;${PATH}"',
    paste0('MAKEFLAGS="-O -j', parallel::detectCores() + 1, '"')
  ),
  con = "~/.Renviron"
)

PR follows.

@krlmlr krlmlr mentioned this issue Aug 31, 2020
@jeroen jeroen closed this in #147 Sep 3, 2020
@krlmlr
Copy link
Contributor Author

@krlmlr krlmlr commented Sep 7, 2020

Can't install ccache on a fresh rtools40 install. pacman -Q doesn't list it. Any ideas?

@jeroen
Copy link
Member

@jeroen jeroen commented Sep 7, 2020

I haven't synced to CRAN yet. If you want to install now, edit the files c:/rtools40/etc/pacman.d/mingw{64,32}.conf and comment-out the cran mirrors, so that you use the bintray mirror, and then do pacman -Su.

@krlmlr
Copy link
Contributor Author

@krlmlr krlmlr commented Sep 7, 2020

When do you plan to sync next?

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

Successfully merging a pull request may close this issue.

2 participants
You can’t perform that action at this time.