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

Update GitHub Actions workflows, and make necessary tweaks to support them #279

Merged
merged 11 commits into from
Aug 25, 2022

Conversation

DavisVaughan
Copy link
Member

@DavisVaughan DavisVaughan commented Aug 22, 2022

This PR was originally intended to update the GitHub Actions workflow files in cpp11, but doing so proved to be quite challenging since they haven't been updated in awhile.

Note that there are more files changed here than just the workflow files, because we needed to tweak some of the actual cpp11 tests to accommodate some other problems. I will point them out with inline comments describing them in detail.

You should also be able to look at the individual commits to track the changes, I have tried to make them meaningful.

@DavisVaughan DavisVaughan marked this pull request as ready for review August 22, 2022 13:14
@DavisVaughan DavisVaughan changed the title Bump Ubuntu version from 18.04 to 20.04 Fully update GitHub Actions workflow files Aug 22, 2022
@DavisVaughan DavisVaughan force-pushed the feature/bump-gha branch 2 times, most recently from deeaa25 to 7ac5c77 Compare August 23, 2022 00:52
@DavisVaughan DavisVaughan force-pushed the feature/bump-gha branch 2 times, most recently from ea01b66 to 0fbdcb1 Compare August 23, 2022 14:29
@DavisVaughan

This comment was marked as outdated.

Otherwise this will incorrectly return `TRUE` because it compiles a C program rather than a C++ one to check if color support is available, which adds the `-fdiagnostics-color=always` flag, but g++ 4.8 doesn't actually support that, so the compilation of the C++ code in the vignettes would fail
@DavisVaughan DavisVaughan changed the title Fully update GitHub Actions workflow files Update GitHub Actions workflows, and make necessary tweaks to support them Aug 24, 2022
- {os: windows-latest, r: 'release'}
- {os: windows-latest, r: '3.6', rspm: "https://packagemanager.rstudio.com/cran/latest"}
- {os: ubuntu-18.04, r: 'devel', rspm: "https://packagemanager.rstudio.com/cran/__linux__/bionic/latest", http-user-agent: "R/4.1.0 (ubuntu-18.04) R (4.1.0 x86_64-pc-linux-gnu x86_64 linux-gnu) on GitHub Actions" }
Copy link
Member Author

Choose a reason for hiding this comment

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

GitHub Actions is no longer supporting Ubuntu 18.04, so we switched to 20.04.

Note that r-lib/actions actually just switched to ubuntu-latest as the default, but I think for cpp11 it is worth trying to continue to test on "older" Ubuntu versions like 20.04 r-lib/actions#612

Comment on lines +57 to +69
# We check on this old compiler specifically to support CentOS 7,
# which uses this gcc version. RStudio products support CentOS 7 through
# June 2024.
# https://github.com/r-lib/cpp11/pull/78
# https://www.rstudio.com/about/platform-support/
# Ubuntu 20.04 technically dropped support for gcc 4.8, so we have to
# add old archives back in manually to install it
# https://github.com/r-lib/cpp11/pull/279
if: matrix.config.custom == 'gcc 4.8'
run: |
echo "deb http://dk.archive.ubuntu.com/ubuntu/ xenial main" | sudo tee -a /etc/apt/sources.list
echo "deb http://dk.archive.ubuntu.com/ubuntu/ xenial universe" | sudo tee -a /etc/apt/sources.list
sudo apt update
Copy link
Member Author

Choose a reason for hiding this comment

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

I have retained support for testing gcc 4.8, but it wasn't easy. The move to Ubuntu 20.04 means that sudo apt-get install -y g++-4.8 doesn't work out of the box anymore.

The way to fix this is to add older archives into the sources.list manually. This was proposed on a number of stack overflow questions, like these
https://stackoverflow.com/questions/68805002/i-need-to-install-gcc4-9-on-ubuntu-20-04-matlab-mex
https://askubuntu.com/questions/1036108/install-gcc-4-9-at-ubuntu-18-04

Corresponds to this commit 6a2994a

Copy link
Member

Choose a reason for hiding this comment

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

Calling out the fact that RStudio are doing this to support CentOS7, I wonder if it would make sense to move to using docker for CentOS 7 explicitly, in order to better replicate the environment you are trying to support, IIRC you would have to use Docker for everything then, so maybe not worth it, or you could run this in a separate workflow...

Copy link
Member Author

@DavisVaughan DavisVaughan Aug 25, 2022

Choose a reason for hiding this comment

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

I opened #281 to consider this

Arrow uses a docker image in this way, so we could probably do the same

sudo apt-get install -y g++-4.8
mkdir ~/.R/
echo $'CXX1X=g++-4.8\nCXX11=g++-4.8' >> ~/.R/Makevars
echo $'CXX1X=g++-4.8\nCXX11=g++-4.8\nCC=gcc-4.8' >> ~/.R/Makevars
Copy link
Member Author

@DavisVaughan DavisVaughan Aug 24, 2022

Choose a reason for hiding this comment

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

The addition of CC is fairly tricky. If you don't add this, the FAQ vignette fails to build with errors about -fdiagnostics-color=always being a flag that isn't supported. Note that the FAQ vignette has {cpp11} knitr chunks that it compiles, and while it was compiling those chunks it was indeed setting the -fdiagnostics-color=always flag.

Some research turned up that this flag was only supported in gcc >=4.9, so gcc is right that it shouldn't be there.

It turns out this flag was being added by pkgbuild during pkgbuild::build().
https://github.com/r-lib/pkgbuild/blob/80762db02d9273997ed6234f654633359269cc9e/R/compiler-flags.R#L51-L58
https://github.com/r-lib/pkgbuild/blob/80762db02d9273997ed6234f654633359269cc9e/R/build.R#L54

It gets added if it looks like the compiler supports colored diagnostics, i.e. the has_compiler_colored_diagnostics() check there. This helper works by attempting to compile a simple C program with -fdiagnostics-color=always set in the Makevars https://github.com/r-lib/pkgbuild/blob/80762db02d9273997ed6234f654633359269cc9e/R/compiler-flags.R#L76. If the compilation fails, we assume there is no color support. The problem is that it attempts this on a C program which uses a compiler that does support color, but the C++ compiler we set through CXX11 does not.

So my fix for this is to just force the C compiler to also be gcc 4.8 so this helper returns FALSE.

Reported to pkgbuild here r-lib/pkgbuild#141

Corresponds to this commit f59c833

Copy link
Member

Choose a reason for hiding this comment

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

yeah, that sounds right, I wonder if pkgbuild should test both the CC and CXX points.

Alternatively perhaps it is better practice to use the same toolchain for C and C++ anyway (even though there is no C code being compiled here)

Copy link
Member Author

Choose a reason for hiding this comment

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

I wonder if pkgbuild should test both the CC and CXX points.

Gabor and I are talking about exactly that in r-lib/pkgbuild#141

needs: website

- name: Deploy package
- name: Build site
env:
CPP11_EVAL: true
Copy link
Member Author

Choose a reason for hiding this comment

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

In particular, made sure to retain this!

Comment on lines -26 to +33
extra-packages: local::. local::cpp11test pkgdown
extra-packages: any::pkgdown, local::., local::cpp11test
Copy link
Member Author

Choose a reason for hiding this comment

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

Retained installation of cpp11test here

Comment on lines -50 to +33
pak::local_install(dependencies = FALSE)
options(warn = 2)
pak::local_install_dev_deps("cpp11test", dependencies = TRUE)
install.packages("cpp11test", repos = NULL, INSTALL_opts = "--install-tests")
pak::local_install(dependencies = TRUE)
pak::pkg_install("covr")
install.packages("cpp11test", repos = NULL, INSTALL_opts = "--install-tests", type = "source")
Copy link
Member Author

Choose a reason for hiding this comment

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

Mainly just syncing this to what is in R-CMD-check.yaml

DESCRIPTION Outdated
Comment on lines 63 to 64
Remotes:
r-lib/testthat
Copy link
Member Author

Choose a reason for hiding this comment

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

There was a testthat issue that was causing some warnings when compiling cpp11test on Windows with the "latest" version of R. Since we use options(warn = 2) before compiling it was causing the build to fail r-lib/testthat#1672

Corresponds to this commit 7a479d8

Copy link
Member

Choose a reason for hiding this comment

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

wonder if we should pin this to a commit SHA rather than having it float, and remove the pin after the changes are on CRAN.

I worry that having it float with the HEAD would cause builds to fail due to unrelated testthat development

Comment on lines 187 to 193
SEXP x = PROTECT(Rf_coerceVector(R_compact_intrange(1, 5), REALSXP));
// ALTREP compact-seq
auto seq = cpp11::package("base")[":"];
cpp11::sexp range = seq(cpp11::as_sexp(1), cpp11::as_sexp(5));

SEXP x = PROTECT(Rf_coerceVector(range, REALSXP));
expect_true(ALTREP(x));
Copy link
Member Author

Choose a reason for hiding this comment

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

It turns out that R_compact_intrange() wasn't supposed to be exposed to us, and R core has moved it to Defn.h in R 4.2.0 (or maybe 4.2.1, not sure)
wch/r-source@86b4a06

I've replaced it with a call to 1:5, which does make an ALTREP object that we can use here, and seemed like a reasonable way to make one for now (with the alternative being that we create a full altrep dummy class in cpp11test to test with)

Corresponds to this commit 29cc833

Copy link
Member

Choose a reason for hiding this comment

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

Makes sense, wonder if it is more readable to use seq rather than :, though the former is a S3 generic, so not quite the same thing, I don't think it will ever matter in practice.

Comment on lines +1 to +12
// Avoid unused variable warnings regarding `cpp11::preserved`
// clang-format off
#ifdef __clang__
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wunused-variable"
#endif

#ifdef __GNUC__
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wunused-variable"
#endif
// clang-format on
Copy link
Member Author

Choose a reason for hiding this comment

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

Another thing that showed up on the Windows build with the "latest" version of R while compiling cpp11test was a warning about cpp11::preserved being an unused variable in this test-protect.cpp file.

I guess that makes sense, because it isn't used anywhere in this test file but is created as a static struct in the header file so each compilation unit gets a copy of it and is "expected" to use it. Not sure why we don't get this warning on other OSes, but I just copied over the same pragma from protect.cpp that is also used to ignore some unused variable warnings

static struct {

#ifdef __clang__

Corresponds to this commit 0fbdcb1

@DavisVaughan
Copy link
Member Author

@jimhester would you mind reviewing this PR for me? There are a number of things here where I want to be sure that I am correctly preserving what was already there, and I think having a review from you would be very helpful for that.

I would have broken it up into smaller individual PRs if I could, but it seemed more useful to have 1 PR with well defined commits that results in all builds passing again.

Copy link
Member

@jimhester jimhester left a comment

Choose a reason for hiding this comment

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

Looks good to me, sorry about all the finickiness, cpp11 is kind of in a weird place with its interaction with CI

@DavisVaughan DavisVaughan merged commit 3e23b30 into r-lib:main Aug 25, 2022
@DavisVaughan DavisVaughan deleted the feature/bump-gha branch August 25, 2022 14:06
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.

3 participants