Skip to content

Commit

Permalink
Modify cc so it works in windows with MinGW #6423 (#6429)
Browse files Browse the repository at this point in the history
* cc.R:
  - add WIN32 define (-DWIN32) as -c99 do not definie it
  - in windows replace `system()` with `shell()`
  - in windows data_table.dll instead of data_table.so (dyn.load())

* Update cc.R

* Update cc.R

* Apply suggestions from code review

Co-authored-by: Michael Chirico <[email protected]>

* Update .dev/cc.R

Co-authored-by: Michael Chirico <[email protected]>

* use dt_object

* make log clearer

* make OMP clearer, use R"()" in other branch too

---------

Co-authored-by: Michael Chirico <[email protected]>
  • Loading branch information
rikivillalba and MichaelChirico authored Aug 29, 2024
1 parent eaa7cd3 commit 392a321
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions .dev/cc.R
Original file line number Diff line number Diff line change
Expand Up @@ -70,20 +70,35 @@ cc = function(test=FALSE, clean=FALSE, debug=FALSE, omp=!debug, path=Sys.getenv(
dll = grep("data_table.so", dll, fixed=TRUE, value=TRUE)
sapply(dll, dyn.unload)
gc()

# hack for windows under mingw-like environment
# PROJ_PATH must be windows like i.e.: export PROJ_PATH=$(Rscript -e 'getwd()')
if (.Platform$OS.type == "windows") {
system = function(command, ...) shell(shQuote(command, "sh"), shell = "sh",...)
# when -std=c99, macro WIN32 is not defined (MinGW) so we define it
# otherwise will fail as sys/mman.h does not exists in windows (fread.c)
W32 = "-DWIN32"
dt_object = "data_table"
} else {
W32 = ""
dt_object = "data_table.so"
}

old = getwd()
on.exit(setwd(old))
setwd(file.path(path,"src"))
if (!quiet) cat(getwd(),"\n")
if (clean) system("rm *.o *.so")
OMP = if (omp) "" else "no-"
OMP = if (omp) "openmp" else "no-openmp"
if (debug) {
ret = system(ignore.stdout=quiet, sprintf("MAKEFLAGS='-j CC=%s PKG_CFLAGS=-f%sopenmp CFLAGS=-std=c99\\ -O0\\ -ggdb\\ -pedantic' R CMD SHLIB -d -o data_table.so *.c", CC, OMP))
cmd = sprintf(R"(MAKEFLAGS='-j CC=%s PKG_CFLAGS=-f% CFLAGS=-std=c99\ -O0\ -ggdb\ %s\ -pedantic' R CMD SHLIB -d -o data_table.so *.c)", CC, OMP, W32)
} else {
ret = system(ignore.stdout=quiet, sprintf("MAKEFLAGS='-j CC=%s CFLAGS=-f%sopenmp\\ -std=c99\\ -O3\\ -pipe\\ -Wall\\ -pedantic\\ -Wstrict-prototypes\\ -isystem\\ /usr/share/R/include\\ -fno-common' R CMD SHLIB -o data_table.so *.c", CC, OMP))
cmd = sprintf(R"(MAKEFLAGS='-j CC=%s CFLAGS=-f%s\ -std=c99\ -O3\ -pipe\ -Wall\ -pedantic\ -Wstrict-prototypes\ -isystem\ /usr/share/R/include\ %s\ -fno-common' R CMD SHLIB -o data_table.so *.c)", CC, OMP, W32)
# the -isystem suppresses strict-prototypes warnings from R's headers, #5477. Look at the output to see what -I is and pass the same path to -isystem.
# TODO add -Wextra too?
}
cat(sprintf("Running command:\n%s\n", cmd))
ret = system(cmd, ignore.stdout=quiet)
if (ret) return()
# clang -Weverything includes -pedantic and issues many more warnings than gcc
# system("R CMD SHLIB -o data_table.so *.c")
Expand All @@ -93,7 +108,7 @@ cc = function(test=FALSE, clean=FALSE, debug=FALSE, omp=!debug, path=Sys.getenv(
break
}
}
dyn.load("data_table.so")
dyn.load(dt_object)
setwd(old)
xx = getDLLRegisteredRoutines("data_table",TRUE)
for (Call in xx$.Call)
Expand Down

0 comments on commit 392a321

Please sign in to comment.