Skip to content

Clang autocompletion with Makevars relies on random ordering #6384

Closed

Description

@DavisVaughan

Update:

For anyone reading this, jump straight to this comment, which has all the information
#6384 (comment)


CC @kevinushey since we talked about this

System details

RStudio Edition : Desktop
RStudio Version : 1.3.869
OS Version      : Mac
R Version       : 3.6.0

Setup

I have an R package with C code. I plan to model the src/ directory after rlang. The way this works is to have:

  • Possibly multiple folders of code, such as src/lib/
  • A corresponding top level file of the same name as the folder, like src/lib.c
    • This file #includes all of the .c files in the src/lib/ folder
  • A Makevars to compile this

The Makevars controls the compilation like this:

lib-files = lib/code2.c

all: $(SHLIB)

$(SHLIB): lib.o

lib.c: $(lib-files)
	touch lib.c

.PHONY: all

To the best of my knowledge, this works by telling the $(SHLIB) to wait until lib.o is ready, and for that to happen we compile lib.c. We compile lib.c if any of the files in lib/ have changed and then touch it to ensure we perform this check again next time we load_all().

Problem

The problem is that when I set it up in this way, Clang's autocomplete engine fails to autocomplete anything from <R.h> or <Rinternals.h> anymore. I've set up a dummy package to demonstrate this:

https://github.com/DavisVaughan/testnestedclang

Try going into code.c or lib/code2.c and deleting ATTRIB() and trying to get it to autocomplete. It should fail.

Turning on .rs.setClangDiagnostics(2) gives me:

CLANG INDEXING: /Users/davis/Desktop/r/playground/packages/testnestedclang/src/code.c
CLANG REMOVE INDEX: /Users/davis/Desktop/r/playground/packages/testnestedclang/src/code.c
COMPILATION ARGUMENTS:
[
    "-isystem",
    "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include",
    "-I/Library/Developer/CommandLineTools/usr/lib/clang/10.0.1/include",
    "-I/usr/local/include",
    "-I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1",
    "-I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/11.0.0/include",
    "-I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include",
    "-I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include",
    "-v"
]
  (Creating new index)
Apple LLVM version 10.0.1 (clang-1001.0.46.4)
Target: x86_64-apple-darwin18.6.0
Thread model: posix
InstalledDir: 
ignoring nonexistent directory "/usr/include"
ignoring duplicate directory "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include"
  as it is a non-system directory that duplicates a system directory
ignoring duplicate directory "/usr/local/include"
  as it is a non-system directory that duplicates a system directory
ignoring duplicate directory "/Library/Developer/CommandLineTools/usr/lib/clang/10.0.1/include"
  as it is a non-system directory that duplicates a system directory
#include "..." search starts here:
#include <...> search starts here:
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/11.0.0/include
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
 /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include
 /usr/local/include
 /Library/Developer/CommandLineTools/usr/lib/clang/10.0.1/include
 /Library/Developer/CommandLineTools/usr/include
 /System/Library/Frameworks (framework directory)
 /Library/Frameworks (framework directory)
End of search list.
/Users/davis/Desktop/r/playground/packages/testnestedclang/src/code.c:2:10: fatal error: 'R.h' file not found
TOTAL MEMORY: 379 kb (code.c)
PERFORMANCE 1.9 ms (code.c)
/Users/davis/Desktop/r/playground/packages/testnestedclang/src/code.c:2:10: fatal error: 'R.h' file not found

The main thing I notice is the fatal error: 'R.h' file not found. This seems to be a side effect of this not showing up in the #include search /Library/Frameworks/R.framework/Resources/include, which generally does show up in other R packages using C code

Activity

  1. DavisVaughan commented on Mar 25, 2020

    @DavisVaughan
    Author

    Okay I can offer much more insight here.

    I have a second simpler package here
    https://github.com/DavisVaughan/testnestedclang2

    If you go into src/code.c on the master branch, code completion works.

    If you change to the not-working branch, and then go into the src/code.c file, code completion is not working.

    The only difference between the two branches is that the not-working one has a second top level file (src/code3.c).

    When autocompletion works, the compilation args from .rs.setClangDiagnostics(2) look like:

    [
        "-isystem",
        "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include",
        "-I/Library/Developer/CommandLineTools/usr/lib/clang/10.0.1/include",
        "-I/usr/local/include",
        "-I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1",
        "-I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/11.0.0/include",
        "-I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include",
        "-I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include",
        "-I/Library/Frameworks/R.framework/Resources/include",
        "-DNDEBUG",
        "-isysroot",
        "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk",
        "-I/usr/local/include",
        "-I/Users/davis/Desktop/r/playground/packages/testrlib/src",
        "-fPIC",
        "-fno-common",
        "-v"
    ]
    

    when it fails:

    [
        "-isystem",
        "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include",
        "-I/Library/Developer/CommandLineTools/usr/lib/clang/10.0.1/include",
        "-I/usr/local/include",
        "-I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1",
        "-I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/11.0.0/include",
        "-I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include",
        "-I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include",
        "-v"
    ]
    

    So you can see that the chunk of includes starting with "-I/Library/Frameworks/R.framework/Resources/include" are missing, which is why we get fatal error: 'R.h' file not found from above.

    These includes are normally retrieved from RStudio running a R CMD SHLIB --dry-run call in a temp directory where a dummy C file is created named after one of the package's C files. The package's Makevars is also copied here so any includes in PKG_CFLAGS are picked up.

    That all happens here

    std::vector<std::string> RCompilationDatabase::compileArgsForPackage(
    const core::system::Options& env,
    const FilePath& srcDir,
    bool isCpp)
    {
    // create a temp dir to call R CMD SHLIB within
    FilePath tempDir = module_context::tempFile(kCompilationDbPrefix, "dir");
    Error error = tempDir.ensureDirectory();
    if (error)
    {
    LOG_ERROR(error);
    return {};
    }
    // copy Makevars to tempdir if it exists
    FilePath makevarsPath = srcDir.completeChildPath("Makevars");
    if (makevarsPath.exists())
    {
    Error error = makevarsPath.copy(tempDir.completeChildPath("Makevars"));
    if (error)
    {
    LOG_ERROR(error);
    return {};
    }
    }
    FilePath makevarsWinPath = srcDir.completeChildPath("Makevars.win");
    if (makevarsWinPath.exists())
    {
    Error error = makevarsWinPath.copy(tempDir.completeChildPath("Makevars.win"));
    if (error)
    {
    LOG_ERROR(error);
    return {};
    }
    }
    // try to generate an appropriate name for the C++ source file.
    // if we have Makevars / Makevars.site, they may define OBJECT
    // targets; if we pick a file name not matching any OBJECT target
    // then R CMD SHLIB will fail. (technically this implies that we
    // need OBJECT-specific compilation configs but in practice one
    // often just enumerates each OBJECT explicitly and re-uses the
    // same compilation config for each file)
    std::string ext = isCpp ? ".cpp" : ".c";
    std::string filename = kCompilationDbPrefix + core::system::generateUuid() + ext;
    std::vector<FilePath> children;
    srcDir.getChildren(children);
    for (const FilePath& child : children)
    {
    if (child.getExtension() == ext)
    {
    filename = child.getFilename();
    break;
    }
    }
    // call R CMD SHLIB on a temp file to capture the compilation args
    FilePath tempSrcFile = tempDir.completeChildPath(filename);
    std::vector<std::string> compileArgs = argsForRCmdSHLIB(env, tempSrcFile);
    // remove the tempDir
    error = tempDir.remove();
    if (error)
    LOG_ERROR(error);
    // return the compileArgs
    return compileArgs;
    }

    My guess (which @kevinushey also agrees with) is that this is failing for some reason. His exact words: "I suspect the way we form this temporary directory + file is breaking R CMD SHLIB here."

  2. DavisVaughan commented on Mar 25, 2020

    @DavisVaughan
    Author

    Kevin also mentioned: "I don't recall exactly why we do this dance, though. As opposed to just calling R CMD SHLIB directly in the src directory"

    I think you have to create the temp directory because if you run R CMD SHLIB --dry-run on a src directory that has already been compiled and is up to date, then the underlying make call won't spit out any information on the includes that would be used (which is what RStudio captures and parses). By creating a temp directory with a dummy C file, you guarantee that compilation is required.

  3. kevinushey commented on Mar 25, 2020

    @kevinushey
    Collaborator

    Perhaps the solution here is to preserve the directory structure, but only copy source files (leave out any compiled artefacts)

  4. DavisVaughan commented on Mar 25, 2020

    @DavisVaughan
    Author

    That might be useful as a more general solution because I'm also thinking of structuring a package with folders, and no top level C files

    src/exports/
    src/lib/
    src/rlib/
    

    so just looking at the children files of src/ wouldn't be good enough to find one that can be used in the SHLIB command. You'd either have to look recursively or preserve the directory structure as you say

  5. DavisVaughan commented on Mar 27, 2020

    @DavisVaughan
    Author

    Is it possible to get this include information in a different way? For example, you could look at the package level Makevars file and look for -I to get those.

    For the R level includes, they seem to be defined in the Makeconf file? The Matrix package finds the Makeconf file with this $(R_HOME)/etc${R_ARCH}/Makeconf
    https://github.com/cran/Matrix/blob/13baa504e0e1ede81c41388d01ae28662acf62d8/src/Makevars#L7

    And then it seems like .c files use ALL_CPPFLAGS and ALL_CFLAGS, which I found out by looking in my Makeconf

    CFLAGS = -Wall -g -O2 $(LTO)
    CPICFLAGS = -fPIC
    CPPFLAGS = -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -I/usr/local/include
    
    ALL_CFLAGS =  $(PKG_CFLAGS) $(CPICFLAGS) $(SHLIB_CFLAGS) $(CFLAGS)
    ALL_CPPFLAGS =  -I"$(R_INCLUDE_DIR)" -DNDEBUG $(PKG_CPPFLAGS) $(CLINK_CPPFLAGS) $(CPPFLAGS)
    
    .c.o:
    	$(CC) $(ALL_CPPFLAGS) $(ALL_CFLAGS) -c $< -o $@

    Full makeconf:

    Details
    # etc/Makeconf.  Generated from Makeconf.in by configure.
    #
    # ${R_HOME}/etc/Makeconf
    #
    # R was configured using the following call
    # (not including env. vars and site configuration)
    # configure  'CC=clang' 'CXX=clang++' 'OBJC=clang' 'CFLAGS=-Wall -g -O2' 'CPPFLAGS=-isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -I/usr/local/include' 'CXXFLAGS=-Wall -g -O2' 'OBJCFLAGS=-Wall -g -O2' 'FCFLAGS=-Wall -g -O2' 'F77FLAGS=-Wall -g -O2' '--enable-memory-profiling' '--x-libraries=/opt/X11/lib' '--enable-R-framework' 'PKG_CONFIG_PATH=/usr/lib/pkgconfig:/opt/X11/lib/pkgconfig:/usr/local/lib/pkgconfig'
    
    ## This fails if it contains spaces, or if it is quoted
    include $(R_SHARE_DIR)/make/vars.mk
    
    AR = ar
    BLAS_LIBS = -L"$(R_HOME)/lib$(R_ARCH)" -lRblas
    C_VISIBILITY = 
    CC = clang
    CFLAGS = -Wall -g -O2 $(LTO)
    CPICFLAGS = -fPIC
    CPPFLAGS = -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -I/usr/local/include
    CXX = clang++ -std=gnu++11
    CXXCPP = $(CXX) -E
    CXXFLAGS = -Wall -g -O2 $(LTO)
    CXXPICFLAGS = -fPIC
    CXX98 = clang++
    CXX98FLAGS = -Wall -g -O2 $(LTO)
    CXX98PICFLAGS = -fPIC
    CXX98STD = -std=gnu++98
    CXX11 = clang++
    CXX11FLAGS = -Wall -g -O2 $(LTO)
    CXX11PICFLAGS = -fPIC
    CXX11STD = -std=gnu++11
    CXX14 = clang++
    CXX14FLAGS = -Wall -g -O2 $(LTO)
    CXX14PICFLAGS = -fPIC
    CXX14STD = -std=gnu++14
    CXX17 = clang++
    CXX17FLAGS = -Wall -g -O2 $(LTO)
    CXX17PICFLAGS = -fPIC
    CXX17STD = -std=gnu++17
    CXX_VISIBILITY = 
    DYLIB_EXT = .dylib
    DYLIB_LD = $(CC)
    DYLIB_LDFLAGS = -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -fopenmp# $(CFLAGS) $(CPICFLAGS)
    DYLIB_LINK = $(DYLIB_LD) $(DYLIB_LDFLAGS) $(LDFLAGS)
    ECHO = echo
    ECHO_C = \c
    ECHO_N = 
    ECHO_T = 
    F_VISIBILITY = 
    ## FC is the compiler used for all Fortran as from R 3.6.0
    FC = gfortran
    FCFLAGS = -Wall -g -O2 $(LTO)
    ## additional libs needed when linking with $(FC), e.g. on some Oracle compilers
    FCLIBS_XTRA = 
    FFLAGS = -Wall -g -O2 $(LTO)
    FLIBS =  -L/usr/local/gfortran/lib/gcc/x86_64-apple-darwin15/6.1.0 -L/usr/local/gfortran/lib -lgfortran -lquadmath -lm
    FPICFLAGS = -fPIC
    FOUNDATION_CPPFLAGS = 
    FOUNDATION_LIBS = -framework Foundation
    JAR = /usr/bin/jar
    JAVA = /usr/bin/java
    JAVAC = /usr/bin/javac
    JAVAH = /usr/bin/javah
    ## JAVA_HOME might be used in the next three.  
    ## They are for packages 'JavaGD' and 'rJava'
    JAVA_HOME = /Library/Java/JavaVirtualMachines/jdk-11.0.1.jdk/Contents/Home
    JAVA_CPPFLAGS = -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/darwin
    JAVA_LIBS = -L$(JAVA_HOME)/lib/server -ljvm
    JAVA_LD_LIBRARY_PATH = $(JAVA_HOME)/lib/server
    LAPACK_LIBS = -L"$(R_HOME)/lib$(R_ARCH)" -lRlapack
    LDFLAGS = -L/usr/local/lib
    ## we only need this is if it is external, as otherwise link to R
    LIBINTL=   -Wl,-framework -Wl,CoreFoundation
    LIBM = 
    LIBR0 = -L"$(R_HOME)/lib$(R_ARCH)"
    LIBR1 = -lR
    LIBR = -F/Library/Frameworks/R.framework/.. -framework R
    LIBS =  -lpcre -llzma -lbz2 -lz -licucore -ldl -lm -liconv
    ## needed by R CMD config
    LIBnn = lib
    LIBTOOL = $(SHELL) "$(R_HOME)/bin/libtool"
    LTO = 
    ## needed to build applications linking to static libR
    MAIN_LD = $(CC)
    MAIN_LDFLAGS = -fopenmp
    MAIN_LINK = $(MAIN_LD) $(MAIN_LDFLAGS) $(LDFLAGS)
    MKINSTALLDIRS = "$(R_HOME)/bin/mkinstalldirs"
    OBJC = clang
    OBJCFLAGS = -Wall -g -O2 -fobjc-exceptions $(LTO)
    OBJC_LIBS = -lobjc 
    OBJCXX = clang++
    R_ARCH = 
    RANLIB = ranlib
    SAFE_FFLAGS = -Wall -g -O2 -msse2 -mfpmath=sse
    SED = /usr/bin/sed
    SHELL = /bin/sh
    SHLIB_CFLAGS = 
    SHLIB_CXXFLAGS = 
    SHLIB_CXXLD = $(CXX)
    SHLIB_CXXLDFLAGS = -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress
    SHLIB_CXX98LD = $(CXX98) $(CXX98STD)
    SHLIB_CXX98LDFLAGS = -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress
    SHLIB_CXX11LD = $(CXX11) $(CXX11STD)
    SHLIB_CXX11LDFLAGS = -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress
    SHLIB_CXX14LD = $(CXX14) $(CXX14STD)
    SHLIB_CXX14LDFLAGS = -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress
    SHLIB_CXX17LD = $(CXX17) $(CXX17STD)
    SHLIB_CXX17LDFLAGS = -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress
    SHLIB_EXT = .so
    SHLIB_FFLAGS = 
    SHLIB_LD = $(CC)
    SHLIB_LDFLAGS = -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress# $(CFLAGS) $(CPICFLAGS)
    SHLIB_LIBADD = 
    ## We want to ensure libR is picked up from $(R_HOME)/lib
    ## before e.g. /usr/local/lib if a version is already installed.
    SHLIB_LINK = $(SHLIB_LD) $(SHLIB_LDFLAGS) $(LIBR0) $(LDFLAGS)
    SHLIB_OPENMP_CFLAGS = -fopenmp
    SHLIB_OPENMP_CXXFLAGS = -fopenmp
    SHLIB_OPENMP_FFLAGS = -fopenmp
    STRIP_STATIC_LIB = strip -S
    STRIP_SHARED_LIB = strip -x
    TCLTK_CPPFLAGS = -I/usr/local/include -I/usr/local/include -I/opt/X11/include
    TCLTK_LIBS = -L/usr/local/lib -ltcl8.6 -L/usr/local/lib -ltk8.6 -L/opt/X11/lib -lX11 -Wl,-weak-lXss -lXext
    YACC = bison -y
    
    ## Legacy settings:  no longer used by R as of 3.6.0
    ## Setting FC often sets F77 (on Solaris make even if set)
    ## so must follow FC in this file.
    F77 = gfortran
    FCPICFLAGS = -fPIC
    F77_VISIBILITY = 
    SHLIB_FCLD = $(FC)
    SHLIB_FCLDFLAGS = -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress
    SHLIB_OPENMP_FCFLAGS = -fopenmp
    
    
    ## for linking to libR.a
    STATIC_LIBR = #  "$(R_HOME)/lib$(R_ARCH)/libR.a"  $(BLAS_LIBS) $(FLIBS)  $(LIBINTL) -lreadline  $(LIBS)
    
    ## These are recorded as macros for legacy use in packages
    ## set on AIX, formerly for old glibc (-D__NO_MATH_INLINES)
    R_XTRA_CFLAGS = 
    ##  was formerly set on HP-UX
    R_XTRA_CPPFLAGS =  -I"$(R_INCLUDE_DIR)" -DNDEBUG
    ## currently unset
    R_XTRA_CXXFLAGS = 
    ## currently unset
    R_XTRA_FFLAGS = 
    
    ## SHLIB_CFLAGS SHLIB_CXXFLAGS SHLIB_FFLAGS are apparently currently unused
    ## SHLIB_CXXFLAGS is undocumented, there is no SHLIB_FCFLAGS
    ALL_CFLAGS =  $(PKG_CFLAGS) $(CPICFLAGS) $(SHLIB_CFLAGS) $(CFLAGS)
    ALL_CPPFLAGS =  -I"$(R_INCLUDE_DIR)" -DNDEBUG $(PKG_CPPFLAGS) $(CLINK_CPPFLAGS) $(CPPFLAGS)
    ALL_CXXFLAGS =  $(PKG_CXXFLAGS) $(CXXPICFLAGS) $(SHLIB_CXXFLAGS) $(CXXFLAGS)
    ALL_OBJCFLAGS = $(PKG_OBJCFLAGS) $(CPICFLAGS) $(SHLIB_CFLAGS) $(OBJCFLAGS)
    ALL_OBJCXXFLAGS = $(PKG_OBJCXXFLAGS) $(CXXPICFLAGS) $(SHLIB_CXXFLAGS) $(OBJCXXFLAGS)
    ALL_FFLAGS =  $(PKG_FFLAGS) $(FPICFLAGS) $(SHLIB_FFLAGS) $(FFLAGS)
    ## can be overridden by R CMD SHLIB
    P_FCFLAGS = $(PKG_FFLAGS)
    ALL_FCFLAGS =  $(P_FCFLAGS) $(FPICFLAGS) $(SHLIB_FFLAGS) $(FCFLAGS)
    ## LIBR here as a couple of packages use this without SHLIB_LINK
    ALL_LIBS = $(PKG_LIBS) $(SHLIB_LIBADD) $(LIBR) $(LIBINTL)
    
    .SUFFIXES:
    .SUFFIXES: .c .cc .cpp .d .f .f90 .f95 .m .mm .M .o
    
    .c.o:
    	$(CC) $(ALL_CPPFLAGS) $(ALL_CFLAGS) -c $< -o $@
    .c.d:
    	@echo "making $@ from $<"
    	@$(CC) -MM $(ALL_CPPFLAGS) $< > $@
    .cc.o:
    	$(CXX) $(ALL_CPPFLAGS) $(ALL_CXXFLAGS) -c $< -o $@
    .cpp.o:
    	$(CXX) $(ALL_CPPFLAGS) $(ALL_CXXFLAGS) -c $< -o $@
    .cc.d:
    	@echo "making $@ from $<"
    	@$(CXX) -M $(ALL_CPPFLAGS) $< > $@
    .cpp.d:
    	@echo "making $@ from $<"
    	@$(CXX) -M $(ALL_CPPFLAGS) $< > $@
    .m.o:
    	$(OBJC) $(ALL_CPPFLAGS) $(ALL_OBJCFLAGS) -c $< -o $@
    .m.d:
    	@echo "making $@ from $<"
    	@clang -MM $(ALL_CPPFLAGS) $< > $@
    .mm.o:
    	$(OBJCXX) $(ALL_CPPFLAGS) $(ALL_OBJCXXFLAGS) -c $< -o $@
    .M.o:
    	$(OBJCXX) $(ALL_CPPFLAGS) $(ALL_OBJCXXFLAGS) -c $< -o $@
    .f.o:
    	$(FC) $(ALL_FFLAGS) -c $< -o $@
    ## @FCFLAGS_f9x@ are flags needed to recognise the extensions
    .f95.o:
    	$(FC) $(ALL_FCFLAGS) -c  $< -o $@
    .f90.o:
    	$(FC) $(ALL_FCFLAGS) -c  $< -o $@
    
    
  6. DavisVaughan commented on Mar 27, 2020

    @DavisVaughan
    Author

    Or maybe you could look in the package level Makevars for -I and parse that, and then you won't need to care about the package Makevars when running SHLIB.

    So you could run R CMD SHLIB in a temp directory with a single dummy C file and not copy over the package Makevars. Then you won't need to name it anything in particular

  7. DavisVaughan commented on Aug 10, 2020

    @DavisVaughan
    Author

    I am somewhat confident I know what is happening here. The TL;DR is that RStudio is only copying 1 file of the src/ directory over to a temp directory to run R CMD SHLIB in, but it is also copying the entire Makevars.

    If the Makevars uses a custom OBJECT ordering, and the first OBJECT of that Makevars corresponds with the file name of the 1 copied file, then R CMD SHLIB will work and will spit out the compilation information of that 1 file, and will then error on the next OBJECT (because that OBJECT won't have an equally named file). This is enough information for RStudio to parse to get the compilation args.

    However, if the 1 file copied over is not the same as the first OBJECT, then R CMD SHLIB will error immediately, and no compilation info is displayed, so RStudio has nothing to parse.

    I think the solution is as you suggested earlier. Preserve the directory structure but only copy source files (without any artifacts so R CMD SHLIB will do something).

    This actually has nothing to do with having subdirectories in src/. It instead has to do with having a custom OBJECT ordering in a Makevars.

    It is worth noting that the file that gets copied over into the temp directory has an undefined ordering, as it is the first .c file found by iterating over the src/ directory with a boost directory_iterator, and this page states: "The order of directory entries obtained by dereferencing successive increments of a directory_iterator is unspecified." This is just useful to keep in mind that it is not necessarily the first file in lexicographic order.


    As proof of all of this, I have constructed a third example package. It is much simpler than the others because it doesn't contain any subdirectories in src/
    https://github.com/DavisVaughan/testnestedclang3

    The master branch holds a non-working example. There are two files, code.c and code3.c, and a custom Makevars which species the OBJECTS to process. I suspect that directory_iterator finds code3.c first, so that is the file that gets copied into the temp directory. R CMD SHLIB chokes on this, because the Makevars that also gets copied over specifies that code.o should come first.

    I have confirmed my theories in a few ways, described below:


    Proof 1 - Swap OBJECT ordering

    Simply swapping the OBJECT ordering in the Makevars so that code3.o comes first makes auto-complete work again. Like:

    OBJECTS = \
    	code3.o \
    	code.o
    

    This would be proof that directory_iterator is finding code3.c first and that is the file that gets copied over.


    Proof 2 - Rename code3.c

    For some reason, if I rename code3.c to code2.c (and rename the corresponding OBJECT in the Makevars), then it starts working again. I imagine that somehow the directory_iterator now finds code.c first, and that aligns with the first OBJECT so all is well. Again, the ordering that directory_iterator uses when iterating is undefined, so this seems like a reasonable assumption.

    I did this in this working branch, the PR shows the changes
    DavisVaughan/testnestedclang3#1


    Proof 3 - R CMD SHLIB output

    This is really just a test of R CMD SHLIB directly so I can show that the output of it does depend on the 1 file that gets copied over by RStudio. I'm going to mock the two possible choices of what RStudio might be doing (either copying over code.c or code3.c).

    In the master branch of testnestedclang3, do the following:

    1. devtools::clean_dll()

    2. Delete code3.c. This mocks copying over code.c and Makevars to a tempdir.

    3. In terminal, change to the src/ directory of this package and run: R CMD SHLIB --dry-run code.c.

    daviss-mbp-2:src davis$ R CMD SHLIB --dry-run code.c
    make cmd is
      make -f 'Makevars' -f '/Library/Frameworks/R.framework/Resources/etc/Makeconf' -f '/Library/Frameworks/R.framework/Resources/share/make/shlib.mk' -f '/Users/davis/.R/Makevars' SHLIB='code.so' 
    
    make would use
    clang -mmacosx-version-min=10.13 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG   -I/usr/local/include   -fPIC  -O2 -g -fno-common -Wall -c code.c -o code.o
    make: *** No rule to make target `code3.o', needed by `code.so'.  Stop.
    

    Above I see the clang line containing the compilation args that RStudio parses, which makes sense.

    Now, we mock the other way, by deleting code.c.

    1. devtools::clean_dll()

    2. Delete code.c. This mocks copying over code3.c and Makevars to a tempdir.

    3. In terminal, change to the src/ directory of this package and run: R CMD SHLIB --dry-run code3.c.

    daviss-mbp-2:src davis$ R CMD SHLIB --dry-run code3.c
    make cmd is
      make -f 'Makevars' -f '/Library/Frameworks/R.framework/Resources/etc/Makeconf' -f '/Library/Frameworks/R.framework/Resources/share/make/shlib.mk' -f '/Users/davis/.R/Makevars' SHLIB='code3.so' 
    
    make would use
    make: *** No rule to make target `code.o', needed by `code3.so'.  Stop.
    

    Above I do not see the clang line, so RStudio has nothing to parse! This happens because the Makevars specifies code.o as the first object, but code3.c is the file that is copied over. I believe this is what is currently happening.

  8. added this to the v1.5 milestone on Aug 10, 2020
  9. modified the milestones: v1.5, Later on Aug 17, 2020
  10. changed the title [-]Clang autocompletion with Makevars and nested C folders [/-] [+]Clang autocompletion with Makevars relies on random ordering[/+] on Nov 12, 2020
  11. kevinushey commented on Jan 3, 2022

    @kevinushey
    Collaborator

    @jennybc is now bumping into this with readxl, which similarly uses OBJECTS:

    https://github.com/tidyverse/readxl/blob/main/src/Makevars

    The relevant invocation of R CMD SHLIB lives here:

    // try to generate an appropriate name for the C++ source file.
    // if we have Makevars / Makevars.site, they may define OBJECT
    // targets; if we pick a file name not matching any OBJECT target
    // then R CMD SHLIB will fail. (technically this implies that we
    // need OBJECT-specific compilation configs but in practice one
    // often just enumerates each OBJECT explicitly and re-uses the
    // same compilation config for each file)
    std::string ext = isCpp ? ".cpp" : ".c";
    std::string filename = kCompilationDbPrefix + core::system::generateUuid() + ext;
    std::vector<FilePath> children;
    srcDir.getChildren(children);
    for (const FilePath& child : children)
    {
    if (child.getExtension() == ext)
    {
    filename = child.getFilename();
    break;
    }
    }
    // call R CMD SHLIB on a temp file to capture the compilation args
    FilePath tempSrcFile = tempDir.completeChildPath(filename);
    std::vector<std::string> compileArgs = argsForRCmdSHLIB(env, tempSrcFile);

    The main question is, I think -- why don't we just preserve the file names as-is? Do we really need to make these names unique, if we're already doing the work to work in a custom temporary directory?

    (For that matter, why not just call R CMD SHLIB --dry-run directly in the src/ directory? Presumedly we do this dance for a reason; e.g. to avoid R writing some unexpected outputs into the src/ directory, but is that really necessary?)

    This loop also looks kind of bogus to me...

    std::vector<FilePath> children;
    srcDir.getChildren(children);
    for (const FilePath& child : children)
    {
    if (child.getExtension() == ext)
    {
    filename = child.getFilename();
    break;
    }
    }

  12. DavisVaughan commented on Jan 3, 2022

    @DavisVaughan
    Author

    For that matter, why not just call R CMD SHLIB --dry-run directly in the src/ directory?

    I think that was because of this:
    #6384 (comment)

  13. 6 remaining items

  14. romainfrancois commented on Aug 30, 2022

    @romainfrancois
    Contributor

    It seems that it does the trick. e.g. here with readxl on build 153:

    Enregistrement.de.l.ecran.2022-08-30.a.10.03.35.mov
    # PARSE COMPILATION RESULTS ----
    [
        "-std=gnu++11",
        "-I/Library/Frameworks/R.framework/Resources/include",
        "-DNDEBUG",
        "-Iunix",
        "-I.",
        "-I/opt/R/arm64/include",
        "-fPIC",
        "-falign-functions=64"
    ]
    
    # PACKAGE COMPILATION ARGS ----
    [
        "-std=gnu++11",
        "-I/Library/Frameworks/R.framework/Resources/include",
        "-DNDEBUG",
        "-Iunix",
        "-I.",
        "-I/opt/R/arm64/include",
        "-fPIC",
        "-falign-functions=64"
    ]
    
    # PACKAGE COMPILATION ARGS ----
    [
        "-std=gnu++11",
        "-I/Library/Frameworks/R.framework/Resources/include",
        "-DNDEBUG",
        "-Iunix",
        "-I/Users/romainfrancois/Desktop/readxl/src",
        "-I/opt/R/arm64/include",
        "-fPIC",
        "-falign-functions=64",
        "-I/Users/romainfrancois/.R/library/4.2/cpp11/include",
        "-I/Users/romainfrancois/.R/library/4.2/progress/include",
        "-DEIGEN_DONT_VECTORIZE",
        "-I/Library/Developer/CommandLineTools/usr/lib/clang/13.1.6/include",
        "-I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1",
        "-I/Library/Developer/CommandLineTools/usr/lib/clang/13.1.6/include",
        "-I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include",
        "-I/Library/Developer/CommandLineTools/usr/include"
    ]
    

    as opposed to build 152:

    Enregistrement.de.l.ecran.2022-08-30.a.10.09.14.mov
    CLANG INDEXING: /Users/romainfrancois/Desktop/readxl/src/zip.cpp
    # BASE COMPILATION ARGS ----
    [
        "-DEIGEN_DONT_VECTORIZE",
        "-I/Library/Developer/CommandLineTools/usr/lib/clang/13.1.6/include",
        "-I/usr/local/include",
        "-I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1",
        "-I/Library/Developer/CommandLineTools/usr/lib/clang/13.1.6/include",
        "-I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include",
        "-I/Library/Developer/CommandLineTools/usr/include"
    ]
    
    # LINKINGTO INCLUDES ----
    [
        "-I/Users/romainfrancois/.R/library/4.2/cpp11/include",
        "-I/Users/romainfrancois/.R/library/4.2/progress/include"
    ]
    
    # PARSING COMPILATION OUTPUT ----
    make cmd is
      make -f 'Makevars' -f '/Library/Frameworks/R.framework/Resources/etc/Makeconf' -f '/Library/Frameworks/R.framework/Resources/share/make/shlib.mk' -f '/Users/romainfrancois/.R/Makevars' CXX='$(CXX11) $(CXX11STD)' CXXFLAGS='$(CXX11FLAGS)' CXXPICFLAGS='$(CXX11PICFLAGS)' SHLIB_LDFLAGS='$(SHLIB_CXX11LDFLAGS)' SHLIB_LD='$(SHLIB_CXX11LD)' SHLIB='Read.so' 
    
    make would use
    
    # PARSE COMPILATION RESULTS ----
    []
    
    # PACKAGE COMPILATION ARGS ----
    []
    
    # PACKAGE COMPILATION ARGS ----
    [
        "-I/Users/romainfrancois/.R/library/4.2/cpp11/include",
        "-I/Users/romainfrancois/.R/library/4.2/progress/include",
        "-DEIGEN_DONT_VECTORIZE",
        "-I/Library/Developer/CommandLineTools/usr/lib/clang/13.1.6/include",
        "-I/usr/local/include",
        "-I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1",
        "-I/Library/Developer/CommandLineTools/usr/lib/clang/13.1.6/include",
        "-I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include",
        "-I/Library/Developer/CommandLineTools/usr/include"
    ]
    
  15. romainfrancois commented on Aug 30, 2022

    @romainfrancois
    Contributor

    one pitfall though is that the compilation setting might be restored, so with build 153 you have to force it to rebuild, e.g. by modifying the Makevars file.

    Trying to fix this in this follow up: #11865

  16. DavisVaughan commented on Aug 30, 2022

    @DavisVaughan
    Author

    @kevinushey yea I'm definitely up for trying it out on a few packages once @romainfrancois feels like it is in a decent place

  17. romainfrancois commented on Aug 30, 2022

    @romainfrancois
    Contributor

    I believe it's good to go, but should be easier to test once #11865 is merged

  18. romainfrancois commented on Aug 31, 2022

    @romainfrancois
    Contributor

    rlang works for me with build 157.

  19. DavisVaughan commented on Aug 31, 2022

    @DavisVaughan
    Author

    rlang and readxl do seem to be working now!

    It seems like {ps} isn't working with autocomplete still. I searched for packages that use OBJECTS. This is my compilation output with the latest daily after touching Makevars (so you can see the make cmd). It looks like the make part is failing because it says make would use but nothing after that like it normally does

    FYI, when working on {ps} you might have to load_all() once, which forces it to auto-generate a config.h file

    Here are my details:

    Details
    CLANG INDEXING: /Users/davis/Desktop/r/packages/ps/src/common.c
    # BASE COMPILATION ARGS ----
    [
        "-DEIGEN_DONT_VECTORIZE",
        "-I/Library/Developer/CommandLineTools/usr/lib/clang/13.1.6/include",
        "-I/usr/local/include",
        "-I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1",
        "-I/Library/Developer/CommandLineTools/usr/lib/clang/13.1.6/include",
        "-I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include",
        "-I/Library/Developer/CommandLineTools/usr/include"
    ]
    
    # PARSING COMPILATION OUTPUT ----
    make cmd is
      make -f 'Makevars' -f '/Library/Frameworks/R.framework/Versions/4.1/Resources/etc/Makeconf' -f '/Library/Frameworks/R.framework/Versions/4.1/Resources/share/make/shlib.mk' -f '/Users/davis/.R/Makevars' SHLIB='clang-compilation-db-13b4d231-88fb-4a3f-bedd-bd310f11cabe.so' OBJECTS='clang-compilation-db-13b4d231-88fb-4a3f-bedd-bd310f11cabe.o'
    
    make would use
    
    # PARSE COMPILATION RESULTS ----
    []
    
    # PACKAGE COMPILATION ARGS ----
    []
    
    # PACKAGE COMPILATION ARGS ----
    [
        "-DEIGEN_DONT_VECTORIZE",
        "-I/Library/Developer/CommandLineTools/usr/lib/clang/13.1.6/include",
        "-I/usr/local/include",
        "-I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1",
        "-I/Library/Developer/CommandLineTools/usr/lib/clang/13.1.6/include",
        "-I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include",
        "-I/Library/Developer/CommandLineTools/usr/include"
    ]
    
    PACKAGE PCH: (none)
    # SAVING PACKAGE COMPILATION CONFIG ----
    /Users/davis/Desktop/r/packages/ps/.Rproj.user/49404F48/compilation-database/config.json
    {
        "args": [
            "-DEIGEN_DONT_VECTORIZE",
            "-I/Library/Developer/CommandLineTools/usr/lib/clang/13.1.6/include",
            "-I/usr/local/include",
            "-I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1",
            "-I/Library/Developer/CommandLineTools/usr/lib/clang/13.1.6/include",
            "-I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include",
            "-I/Library/Developer/CommandLineTools/usr/include"
        ],
        "pch": "",
        "is_cpp": false,
        "hash": "166195315216619529741661953075",
        "compiler": "6773731173356695494",
        "rversion": "4.1.3",
        "dbversion": 2
    }
    
    CLANG REMOVE INDEX: /Users/davis/Desktop/r/packages/ps/src/common.c
    # COMPILATION ARGUMENTS ----
    [
        "-DEIGEN_DONT_VECTORIZE",
        "-I/Library/Developer/CommandLineTools/usr/lib/clang/13.1.6/include",
        "-I/usr/local/include",
        "-I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1",
        "-I/Library/Developer/CommandLineTools/usr/lib/clang/13.1.6/include",
        "-I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include",
        "-I/Library/Developer/CommandLineTools/usr/include",
        "-v"
    ]
      (Creating new index)
    Apple clang version 13.1.6 (clang-1316.0.21.2.5)
    Target: x86_64-apple-darwin21.6.0
    Thread model: posix
    InstalledDir: /Library/Developer/CommandLineTools/usr/bin
    ignoring nonexistent directory "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/local/include"
    ignoring nonexistent directory "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/Library/Frameworks"
    ignoring duplicate directory "/Library/Developer/CommandLineTools/usr/lib/clang/13.1.6/include"
    ignoring duplicate directory "/Library/Developer/CommandLineTools/usr/lib/clang/13.1.6/include"
      as it is a non-system directory that duplicates a system directory
    ignoring duplicate directory "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include"
      as it is a non-system directory that duplicates a system directory
    ignoring duplicate directory "/Library/Developer/CommandLineTools/usr/include"
      as it is a non-system directory that duplicates a system directory
    #include "..." search starts here:
    #include <...> search starts here:
     /usr/local/include
     /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1
     /Library/Developer/CommandLineTools/usr/lib/clang/13.1.6/include
     /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include
     /Library/Developer/CommandLineTools/usr/include
     /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks (framework directory)
    End of search list.
    /Users/davis/Desktop/r/packages/ps/src/common.h:6:10: fatal error: 'Rinternals.h' file not found
    TOTAL MEMORY: 1698 kb (common.c)
    PERFORMANCE 271 ms (common.c)
    

    Another one to try would be processx, which also uses OBJECTS (update: looks like this doesn't work either)

  20. kevinushey commented on Aug 31, 2022

    @kevinushey
    Collaborator

    It's working for me 😞

    CLANG INDEXING: /Users/kevin/r/pkg/ps/src/common.c
    # BASE COMPILATION ARGS ----
    [
        "-DEIGEN_DONT_VECTORIZE",
        "-I/Library/Developer/CommandLineTools/usr/lib/clang/13.1.6/include",
        "-I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1",
        "-I/Library/Developer/CommandLineTools/usr/lib/clang/13.1.6/include",
        "-I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include",
        "-I/Library/Developer/CommandLineTools/usr/include"
    ]
    
    # PARSING COMPILATION OUTPUT ----
    make cmd is
      make -f '/Library/Frameworks/R.framework/Resources/etc/Makeconf' -f '/Library/Frameworks/R.framework/Resources/share/make/shlib.mk' -f '/Users/kevin/.R/Makevars' SHLIB='clang-compilation-db-562490f3-5962-4d98-9e2e-77580200ebfc.so' OBJECTS='clang-compilation-db-562490f3-5962-4d98-9e2e-77580200ebfc.o'
    
    make would use
    clang -arch arm64 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG   -I/opt/R/arm64/include   -fPIC  -falign-functions=64 -Wall -g -O2  -c clang-compilation-db-562490f3-5962-4d98-9e2e-77580200ebfc.c -o clang-compilation-db-562490f3-5962-4d98-9e2e-77580200ebfc.o
    if test  "zclang-compilation-db-562490f3-5962-4d98-9e2e-77580200ebfc.o" != "z"; then \
    	  echo clang -arch arm64 -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L"/Library/Frameworks/R.framework/Resources/lib" -L/opt/R/arm64/lib -L/opt/homebrew/lib -o clang-compilation-db-562490f3-5962-4d98-9e2e-77580200ebfc.so clang-compilation-db-562490f3-5962-4d98-9e2e-77580200ebfc.o   -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation; \
    	  clang -arch arm64 -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L"/Library/Frameworks/R.framework/Resources/lib" -L/opt/R/arm64/lib -L/opt/homebrew/lib -o clang-compilation-db-562490f3-5962-4d98-9e2e-77580200ebfc.so clang-compilation-db-562490f3-5962-4d98-9e2e-77580200ebfc.o   -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation; \
    	fi
    
    # PARSE COMPILATION RESULTS ----
    [
        "-I/Library/Frameworks/R.framework/Resources/include",
        "-DNDEBUG",
        "-I/opt/R/arm64/include",
        "-fPIC",
        "-falign-functions=64"
    ]
    
    # PACKAGE COMPILATION ARGS ----
    [
        "-I/Library/Frameworks/R.framework/Resources/include",
        "-DNDEBUG",
        "-I/opt/R/arm64/include",
        "-fPIC",
        "-falign-functions=64"
    ]
    
    # PACKAGE COMPILATION ARGS ----
    [
        "-I/Library/Frameworks/R.framework/Resources/include",
        "-DNDEBUG",
        "-I/opt/R/arm64/include",
        "-fPIC",
        "-falign-functions=64",
        "-DEIGEN_DONT_VECTORIZE",
        "-I/Library/Developer/CommandLineTools/usr/lib/clang/13.1.6/include",
        "-I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1",
        "-I/Library/Developer/CommandLineTools/usr/lib/clang/13.1.6/include",
        "-I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include",
        "-I/Library/Developer/CommandLineTools/usr/include"
    ]
    
    PACKAGE PCH: (none)
    # SAVING PACKAGE COMPILATION CONFIG ----
    /Users/kevin/r/pkg/ps/.Rproj.user/2FA46A95/compilation-database/config.json
    {
        "args": [
            "-I/Library/Frameworks/R.framework/Resources/include",
            "-DNDEBUG",
            "-I/opt/R/arm64/include",
            "-fPIC",
            "-falign-functions=64",
            "-DEIGEN_DONT_VECTORIZE",
            "-I/Library/Developer/CommandLineTools/usr/lib/clang/13.1.6/include",
            "-I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1",
            "-I/Library/Developer/CommandLineTools/usr/lib/clang/13.1.6/include",
            "-I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include",
            "-I/Library/Developer/CommandLineTools/usr/include"
        ],
        "pch": "",
        "is_cpp": false,
        "hash": "16581639011661966127",
        "compiler": "1260550346557374676",
        "rversion": "4.2.1",
        "dbversion": 2
    }
    
    CLANG REMOVE INDEX: /Users/kevin/r/pkg/ps/src/common.c
    # COMPILATION ARGUMENTS ----
    [
        "-I/Library/Frameworks/R.framework/Resources/include",
        "-DNDEBUG",
        "-I/opt/R/arm64/include",
        "-fPIC",
        "-falign-functions=64",
        "-DEIGEN_DONT_VECTORIZE",
        "-I/Library/Developer/CommandLineTools/usr/lib/clang/13.1.6/include",
        "-I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1",
        "-I/Library/Developer/CommandLineTools/usr/lib/clang/13.1.6/include",
        "-I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include",
        "-I/Library/Developer/CommandLineTools/usr/include",
        "-v"
    ]
      (Creating new index)
    Apple clang version 13.1.6 (clang-1316.0.21.2.5)
    Target: arm64-apple-darwin21.6.0
    Thread model: posix
    InstalledDir: /Library/Developer/CommandLineTools/usr/bin
    ignoring nonexistent directory "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/local/include"
    ignoring nonexistent directory "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/Library/Frameworks"
    ignoring duplicate directory "/Library/Developer/CommandLineTools/usr/lib/clang/13.1.6/include"
    ignoring duplicate directory "/Library/Developer/CommandLineTools/usr/lib/clang/13.1.6/include"
      as it is a non-system directory that duplicates a system directory
    ignoring duplicate directory "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include"
      as it is a non-system directory that duplicates a system directory
    ignoring duplicate directory "/Library/Developer/CommandLineTools/usr/include"
      as it is a non-system directory that duplicates a system directory
    #include "..." search starts here:
    #include <...> search starts here:
     /Library/Frameworks/R.framework/Resources/include
     /opt/R/arm64/include
     /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1
     /Library/Developer/CommandLineTools/usr/lib/clang/13.1.6/include
     /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include
     /Library/Developer/CommandLineTools/usr/include
     /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks (framework directory)
    End of search list.
    /Users/kevin/r/pkg/ps/src/ps-internal.h:5:10: fatal error: 'config.h' file not found
    TOTAL MEMORY: 2 mb (common.c)
    PERFORMANCE 129 ms (common.c)
    

    EDIT: Ah, it stops working after I devtools::load_all(). So somehow that's implicated here... it seems like it creates / mutates a Makevars file and that causes things to stop working.

  21. kevinushey commented on Aug 31, 2022

    @kevinushey
    Collaborator
    kevin@MBP-P2MQ:/tmp/RtmpwMd4YC/clang-compilation-db-9d9d1eef8201.dir
    $ R CMD SHLIB --dry-run clang-compilation-db-dcc23e94-02da-41a1-b231-1a533af4e82a.c
    make cmd is
      make -f 'Makevars' -f '/Library/Frameworks/R.framework/Resources/etc/Makeconf' -f '/Library/Frameworks/R.framework/Resources/share/make/shlib.mk' -f '/Users/kevin/.R/Makevars' SHLIB='clang-compilation-db-dcc23e94-02da-41a1-b231-1a533af4e82a.so' OBJECTS='clang-compilation-db-dcc23e94-02da-41a1-b231-1a533af4e82a.o'
    
    make would use
    make: *** No rule to make target `px.c', needed by `px'.  Stop.
    

    The extra dependencies in the Makevars file are confusing RStudio here.

  22. kevinushey commented on Aug 31, 2022

    @kevinushey
    Collaborator

    processx is likely to have similar issues since the all target depends on building other tools.

  23. kevinushey commented on Aug 31, 2022

    @kevinushey
    Collaborator

    I don't know what the best solution here is.

    • Copy all of the source files to the compilation directory, so that required targets could in theory be made?
    • Copy only some subset of the Makevars file to the compilation directory? (e.g. only copy flags / CXX_STD / things like that)
    • Figure out a way to make R CMD SHLIB --dry-run work in the src/ directory even if the .o and .so targets already exist?
    • Figure out a different way to get the compilation flags than R CMD SHLIB?
  24. DavisVaughan commented on Aug 31, 2022

    @DavisVaughan
    Author

    I feel like 3 would be a nice option if possible, since that keeps everything "in place"

    The R CMD SHLIB --dry-run stuff only runs when you recompile the database right? Which is an extremely uncommon thing to do? i.e. it seems to only happen for me if I touch Makevars.

    What if .o and .so targets were just cleaned out by RStudio before it had to run this, just so R CMD SHLIB --dry-run could be run?

    If it only happened once in a blue moon then I wouldn't be mad about having to recompile after it

  25. kevinushey commented on Aug 31, 2022

    @kevinushey
    Collaborator

    My main worry would be if we did this while the user was already trying to build / compile things in the package. I'm not sure if there's a clean way for us to avoid that.

    Maybe (at least on Linux / macOS) we could symlink all of the non-object files into the compilation directory? That should be relatively cheap...

  26. mikebessuille commented on Sep 13, 2022

    @mikebessuille
    Contributor

    @DavisVaughan this fix is now in the latest daily; could you please have a look and see if it resolves the problem?

  27. DavisVaughan commented on Sep 13, 2022

    @DavisVaughan
    Author

    I tried with vctrs, slider, ps, readxl, and rlang and all seem to be working as expected!

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

Metadata

Metadata

Labels

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions