Skip to content

Commit 01501ed

Browse files
committed
Improve cross-compiling w/o native deps
We now install dummy versions of the dependencies when cross-compiling, so native dependencies are not needed. This fixes compilation on PPM. [ci skip]
1 parent af10882 commit 01501ed

File tree

27 files changed

+150
-13
lines changed

27 files changed

+150
-13
lines changed

src/dummy/cli/DESCRIPTION

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Package: cli
2+
Version: 100.0.0

src/dummy/cli/NAMESPACE

Whitespace-only changes.

src/dummy/curl/DESCRIPTION

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Package: curl
2+
Version: 100.0.0

src/dummy/curl/NAMESPACE

Whitespace-only changes.

src/dummy/desc/DESCRIPTION

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Package: desc
2+
Version: 100.0.0

src/dummy/desc/NAMESPACE

Whitespace-only changes.

src/dummy/filelock/DESCRIPTION

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Package: filelock
2+
Version: 100.0.0

src/dummy/filelock/NAMESPACE

Whitespace-only changes.

src/dummy/jsonlite/DESCRIPTION

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Package: jsonlite
2+
Version: 100.0.0

src/dummy/jsonlite/NAMESPACE

Whitespace-only changes.

src/dummy/lpSolve/DESCRIPTION

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Package: lpSolve
2+
Version: 100.0.0

src/dummy/lpSolve/NAMESPACE

Whitespace-only changes.

src/dummy/pkgbuild/DESCRIPTION

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Package: pkgbuild
2+
Version: 100.0.0

src/dummy/pkgbuild/NAMESPACE

Whitespace-only changes.

src/dummy/pkgcache/DESCRIPTION

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Package: pkgcache
2+
Version: 100.0.0

src/dummy/pkgcache/NAMESPACE

Whitespace-only changes.

src/dummy/ps/DESCRIPTION

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Package: ps
2+
Version: 100.0.0

src/dummy/ps/NAMESPACE

Whitespace-only changes.

src/dummy/zip/DESCRIPTION

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Package: zip
2+
Version: 100.0.0

src/dummy/zip/NAMESPACE

Whitespace-only changes.

src/install-embedded.R

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,89 @@ install_order <- function() {
9696
pkgs
9797
}
9898

99+
install_dummies <- function(lib) {
100+
pkgs <- dir("dummy")
101+
dir.create(lib, showWarnings = FALSE, recursive = TRUE)
102+
on.exit(Sys.unsetenv("PAK_INSTALL_DUMMY_CROSS"), add = TRUE)
103+
Sys.setenv(PAK_INSTALL_DUMMY_CROSS = "true")
104+
message("Dummy packages")
105+
for (pkg in pkgs) {
106+
install.packages(
107+
paste0("dummy/", pkg),
108+
lib = lib,
109+
repos = NULL,
110+
type = "source",
111+
INSTALL_opts = opts()
112+
)
113+
if (!file.exists(file.path(lib, pkg))) {
114+
stop("Failed to install dummy ", pkg)
115+
}
116+
}
117+
118+
# need real R6
119+
message("Real R6")
120+
install.packages(
121+
"library/R6",
122+
lib = lib,
123+
repos = NULL,
124+
type = "source",
125+
INSTALL_opts = opts()
126+
)
127+
if (!file.exists(file.path(lib, "R6"))) {
128+
stop("Failed to install dummy R6")
129+
}
130+
131+
# real processx
132+
message("Real-ish processx")
133+
install.packages(
134+
"library/processx",
135+
lib = lib,
136+
repos = NULL,
137+
type = "source",
138+
INSTALL_opts = c(opts(), "--no-libs")
139+
)
140+
if (!file.exists(file.path(lib, "processx"))) {
141+
stop("Failed to install dummy processx")
142+
}
143+
nspath <- file.path(lib, "processx", "NAMESPACE")
144+
ns <- readLines(nspath)
145+
ns2 <- grep("useDynLib", ns, invert = TRUE, value = TRUE)
146+
writeLines(ns2, nspath)
147+
nsipath <- file.path(lib, "processx", "Meta", "nsInfo.rds")
148+
nsi <- readRDS(nsipath)
149+
nsi$dynlibs <- character()
150+
saveRDS(nsi, nsipath)
151+
152+
# real callr
153+
message("Real-ish callr")
154+
install.packages(
155+
"library/callr",
156+
lib = lib,
157+
repos = NULL,
158+
type = "source",
159+
INSTALL_opts = opts()
160+
)
161+
if (!file.exists(file.path(lib, "callr"))) {
162+
stop("Failed to install dummy callr")
163+
}
164+
}
165+
99166
install_all <- function(lib = NULL) {
100167
pkgs <- install_order()
101168
if (Sys.getenv("CROSS_COMPILING") == "yes") {
169+
# create dummy library
170+
lib <- get_lib(lib)
171+
dummy <- paste0(lib, "-dummy")
172+
.libPaths(c(dummy, .libPaths()))
173+
Sys.setenv(R_LIBS_USER = dummy)
174+
print(Sys.getenv("R_LIBS_USER"))
175+
install_dummies(lib = dummy)
176+
102177
# Update 'Built' field in package itself
103178
update_description_build(
104179
Sys.getenv("R_PACKAGE_DIR"),
105180
Sys.getenv("R_TARGET_PLATFORM")
106181
)
107-
lib <- get_lib(lib)
108182
for (pkg in pkgs) {
109183
install_one(pkg, lib = paste0(lib, "-", pkg))
110184
}

src/library/processx.patch

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
diff --git a/src/library/processx/R/client-lib.R b/src/library/processx/R/client-lib.R
2+
index ab77dfa6..3eefd93a 100644
3+
--- a/src/library/processx/R/client-lib.R
4+
+++ b/src/library/processx/R/client-lib.R
5+
@@ -1,6 +1,8 @@
6+
7+
client <- new.env(parent = emptyenv())
8+
9+
+if (Sys.getenv("PAK_INSTALL_DUMMY_CROSS") != "true") {
10+
+
11+
local({
12+
ext <- .Platform$dynlib.ext
13+
arch <- .Platform$r_arch
14+
@@ -47,6 +49,8 @@ local({
15+
}
16+
})
17+
18+
+}
19+
+
20+
# This is really only here for testing
21+
22+
load_client_lib <- function(client) {
23+
diff --git a/src/library/processx/R/on-load.R b/src/library/processx/R/on-load.R
24+
index 6ade28dd..eca25dc3 100644
25+
--- a/src/library/processx/R/on-load.R
26+
+++ b/src/library/processx/R/on-load.R
27+
@@ -1,6 +1,8 @@
28+
29+
## nocov start
30+
31+
+if (Sys.getenv("PAK_INSTALL_DUMMY_CROSS") != "true") {
32+
+
33+
.onLoad <- function(libname, pkgname) {
34+
## This is needed to fix the boot time to a given value,
35+
## because in a Docker container (maybe elsewhere as well?) on
36+
@@ -26,4 +28,5 @@
37+
supervisor_reset()
38+
}
39+
40+
+}
41+
## nocov end

src/library/processx/R/client-lib.R

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11

22
client <- new.env(parent = emptyenv())
33

4+
if (Sys.getenv("PAK_INSTALL_DUMMY_CROSS") != "true") {
5+
46
local({
57
ext <- .Platform$dynlib.ext
68
arch <- .Platform$r_arch
@@ -47,6 +49,8 @@ local({
4749
}
4850
})
4951

52+
}
53+
5054
# This is really only here for testing
5155

5256
load_client_lib <- function(client) {

src/library/processx/R/on-load.R

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11

22
## nocov start
33

4+
if (Sys.getenv("PAK_INSTALL_DUMMY_CROSS") != "true") {
5+
46
.onLoad <- function(libname, pkgname) {
57
## This is needed to fix the boot time to a given value,
68
## because in a Docker container (maybe elsewhere as well?) on
@@ -26,4 +28,5 @@
2628
supervisor_reset()
2729
}
2830

31+
}
2932
## nocov end

tools/build/linux/Dockerfile-aarch64

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ WORKDIR /root
1616

1717
# need to install the native package first --------------------------------
1818

19-
# TODO: aboid this, by using dummy packages.
19+
# this is not needed for the cross-compilation, but it is easier to use
20+
# the native package for deployment, as long as the deploy code is
21+
# inside the pak package itself.
2022

2123
COPY pak_*.tar.gz /root/
2224

tools/build/macos/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ export PKGFILES := $(patsubst %,lib/%/pak_$(PAKVERSION).tgz,$(RVERSIONS))
4545

4646
deploy:
4747
@echo "----- DEPLOYING packages -----------------------------------"
48+
# this is somewhat redundant, but needed when cross-compiling, to have
49+
# a native package installed.
4850
$(R) CMD INSTALL pak_$(PAKVERSION).tar.gz
4951
R_LIBS=$(RLIB) $(R) -q -e 'pak::pkg_install("deps::$(PKGROOT)", dependencies = "Config/Needs/deploy")'
5052
R_LIBS=$(RLIB) $(R) -q -e \

tools/build/macos/build.sh

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,9 @@ fi
3131

3232
echo "Cross compiling for R ${RVER} using R ${RVERX86}."
3333

34-
# Need to install all dependencies for the build arch first.
35-
# TODO: look up the needed packages automatically
36-
# TODO: should make sure the right versions are installed
37-
38-
R_MAKEVARS_USER="`pwd`/Makevars-macos-${RVERX86}" \
39-
R_COMPILE_AND_INSTALL_PACKAGES=always \
40-
"/usr/local/bin/R-${RVERX86}" -q \
41-
-e 'install.packages(c("pkgdepends", "pkgsearch"))'
42-
43-
# TODO: we will need to hsve R-version specific platform triplets,
34+
# TODO: we will need to have R-version specific platform triplets,
4435
# when a version of R starts using a newer build than the current
45-
# Big Sur (darwin 20).
36+
# Big Sur (darwin 20). (Maybe?)
4637

4738
R_MAKEVARS_USER="`pwd`/Makevars-macos-${RVER}" \
4839
"/usr/local/bin/R-${RVERX86}" CMD INSTALL \

0 commit comments

Comments
 (0)