Skip to content

Two small tweaks for cross compiling#208

Merged
kevinushey merged 2 commits into
RcppCore:masterfrom
jeroen:master
Jan 11, 2024
Merged

Two small tweaks for cross compiling#208
kevinushey merged 2 commits into
RcppCore:masterfrom
jeroen:master

Conversation

@jeroen

@jeroen jeroen commented Jan 10, 2024

Copy link
Copy Markdown
Contributor

Two more tiny tweaks that will smoothen the cross compile process:

First the arch detection in libtbb relies on /usr/sbin/sysctl which does not work on linux or macos-cross. As a result it ends up falling back on arch=ia32 which is completely wrong.

ifndef arch
ifeq ($(shell /usr/sbin/sysctl -n hw.machine),Power Macintosh)
ifeq ($(shell /usr/sbin/sysctl -n hw.optional.64bitops),1)
export arch:=ppc64
else
export arch:=ppc32
endif
else
ifeq ($(shell /usr/sbin/sysctl -n hw.machine),arm64)
export arch:=arm64
else
ifeq ($(shell /usr/sbin/sysctl -n hw.optional.x86_64 2>/dev/null),1)
export arch:=intel64
else
export arch:=ia32
endif
endif
endif
endif

The robust way to detect the target arch on Mac is uname -m (the cross environments shim uname to return the target). So we pre-set that in the RcppParallel Makevars, the same way as is done for Windows.

And one final tweak: we introduce a variable TBB_LINK_LIB that we can use to set the location of the target libtbb, without affecting the runtime TBB. If the variable is unset, the current behavior remains the same.

This is needed, because when we cross compile packages that link against RcppParallel, we need have two copies of RcppParallel: one on the host architecture, that is use to load RcppParallel in order to call RcppParallel::RcppParallelLibs(). And then we need a separate installation of RcppParallel for the cross target architecture, that the package we are building should link against.

Currently we have no way of doing this: if we set TBB_LIB to the cross target arch, the RcppParallel won't load, but if we set it to the host (or we leave it undefined) the path returned by RcppParallel::RcppParallelLibs() returns the host architecture and gives a linking error for the cross build.

@kevinushey kevinushey left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM; thanks!

@kevinushey
kevinushey merged commit 02b86ca into RcppCore:master Jan 11, 2024
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.

2 participants