The R Project SVN R

Rev

Rev 86225 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
78879 ripley 1
The R for Windows Build Process
2
===============================
3
 
4
from the point of view of a Unix installer of R.
5
 
6
Compilation of C/Fortran code is done in two pathways.
7
 
8
1) standard and add-on packages, the most similar to Unix.
9
 
10
The primary Makefiles are
11
$(R_HOME)/etc${R_ARCH}/Makeconf
12
share/make/winshlib.mk
13
 
78885 ripley 14
included in that order.  Some settings in Makeconf are substituted in
15
etc/Makeconf by fixed/Makefile, taken from MkRules.
78879 ripley 16
 
17
 
18
2) Everything else, where the primary Makefile is MkRules which is
19
where all the customization is done.  This is included by all
78892 ripley 20
Makefile.win files in directories above this one and
78879 ripley 21
 
22
./Makefile
23
./fixed/Makefile
24
./front-ends/Makefile
25
./getline/Makefile
26
./installer/Makefile
27
 
28
and replaces Unix's top-level Makeconf.
29
 
30
 
31
The largest difference from Unix (even a R-shlib build) is the use of
32
DLLs, which require the exported symbols to be listed (via nm) in a
33
.def file and fed to the compiler with the object files for linking.
34
 
35
In recent years DLLs are linked to directly as libraries, but there
36
remains provision for import libraries via lib%.dll.a: %.def rules.
37
 
38
Making executables has a number of Windows-specific features, done in
39
front-ends/Makefile:
40
 
78893 ripley 41
- A resource compiler is used to compile in version information, an
42
  icon and a manifest.  Also done for version information in all the
43
  other DLLs under bin and modules (R.dll Rblas.dll Rgraphapp.dll
81980 ligges 44
  Riconv.dll Rlapack.dll lapack.dll).
78879 ripley 45
 
82190 ripley 46
- LINKFLAGS includes flags for the stack size.
78879 ripley 47
 
78893 ripley 48
A resource compiler is used to add version information to the DLLs
49
under directories bin and modules.
50
 
78879 ripley 51
The default is to compile without debug info: this can be enabled by
52
using 'make DEBUG=T' from this directory, or install add-on packages
53
with Rcmd INSTALL --debug.  Otherwise DLLs and executables are
54
stripped.
78885 ripley 55
 
56
 
57
Link-Time Optimization
58
======================
59
 
78909 ripley 60
To enable LTO for building R set the LTO macro in MkRules.local, to
61
-flto or e.g. -flto=8 to use 8 threads.
78885 ripley 62
 
78909 ripley 63
Checking of packages with LTO can be performed by setting the LTO_OPT
64
macro to -flto in MkRules.local and using Rcmd INSTALL --use-LTO.
78885 ripley 65
 
78909 ripley 66
For an installed version of R it should suffice to edit the value of
78938 ripley 67
LTO_OPT in the etc/*/Makeconf files or to set it in a personal or site
68
Makevars file.
78907 ripley 69
 
78941 ripley 70
[Unlike a Unix-alike, LTO/LTO_OPT are used for Fortran as well as C/C++.]
78909 ripley 71
 
78922 ripley 72
 
78885 ripley 73
Cross-compilation
74
=================
75
 
82190 ripley 76
Versions of R prior to 4.2.0 could be cross-compiled using the tools
77
provided by Linux distributions including Fedora, Debian and Ubuntu.
78
However, these do not (at the time of writing) support UCRT-based builds.
78885 ripley 79
 
82190 ripley 80
https://cran.r-project.org/bin/windows/base/howto-R-devel.html
81
describes how to obtain a suitable cross-compilation toolchain for
82
x86_64 Linux (based on glibc).  Look at the section entitled something
83
like
78885 ripley 84
 
82190 ripley 85
'Setting up MXE build from pre-built tarballs',
78885 ripley 86
 
82190 ripley 87
and follow the instructions, which install the toolchain under a place
88
it (and we) call MXE_ROOT.  (To build R only the
86225 kalibera 89
'rtools44-toolchain-libs-base' version is required.)
78885 ripley 90
 
82190 ripley 91
You will also need to fetch the pre-built Tcl/Tk as described in the
92
section 'Building R from source using a toolchain tarball'.  The default
93
location for the latter is R_HOME/Tcl.
78885 ripley 94
 
82190 ripley 95
To build all the compiled code, edit MkRules.local to something like
78885 ripley 96
 
82190 ripley 97
MXE_ROOT = wherever you put it, or /usr/lib/mxe (which was set as a symlink)
98
BINPREF64 = $(MXE_ROOT)/usr/bin/x86_64-w64-mingw32.static.posix-
99
EXT_LIBS = $(MXE_ROOT)/usr/x86_64-w64-mingw32.static.posix
100
#CURL_CA_BUNDLE = /etc/pki/tls/certs/ca-bundle.crt
101
TEXI2ANY=/usr/bin/texi2any
78885 ripley 102
 
103
Setting LTO is supported.
104
 
105
Then in this directory
106
 
82190 ripley 107
make MkRules rbuild rpackages-cross cairodevices
78885 ripley 108
 
86225 kalibera 109
When targeting aarch64 Windows (rather than x86_64), use toolchain bundles
110
with "aarch64" in their name, such as 'rtools44-toolchain-libs-base-aarch64'
111
and 'rtools44-toolchain-libs-cross-aarch64', and Tcl bundle 'tcltk-aarch64'.
112
The cross-compilers run again on x86_64 Linux (based on glibc), such as when
113
targeting x86_64 Windows.
78885 ripley 114
 
86225 kalibera 115
For aarch64, use MkRules.local such as
116
 
117
MXE_ROOT = wherever you put it, or /usr/lib/mxe (which was set as a symlink)
118
USE_LLVM = 1
119
WIN =
120
BINPREF64 = $(MXE_ROOT)/usr_aarch64/bin/aarch64-w64-mingw32.static.posix-
121
EXT_LIBS = $(MXE_ROOT)/usr_aarch64/aarch64-w64-mingw32.static.posix
122
TEXI2ANY = /usr/bin/texi2any
123
 
78896 ripley 124
Cross-building packages
125
=======================
126
 
127
There is experimental minimal support for cross-building packages.
128
 
82190 ripley 129
Copy {bin,etc}/x64 from this build to a standard Linux build of R.
78896 ripley 130
 
82190 ripley 131
Edit the copy of etc/x64/Makeconf to have
78896 ripley 132
 
133
R_WIN = /path/to/top/directory/of/this/build
134
R_XTRA_CPPFLAGS = -I"$(R_WIN)/include" -DNDEBUG
135
 
82190 ripley 136
Set the environment variable R_CROSS_BUILD to x64.
78896 ripley 137
 
78898 ripley 138
Use R CMD INSTALL as usual. (This does not do a staged install nor
82216 ripley 139
test loading.)  --use-LTO is supported if LTO_OPT was set.  Use a
140
separate library tree (-l) as these are Windows and not Linux
141
binaries.
78896 ripley 142
 
143
R CMD INSTALL --build will produce a zipped installation.
144
 
86225 kalibera 145
The newly installed packages must not be visible to later builds, because
146
they are not Linux binaries, so cannot be loaded when they are needed as
147
dependencies.  You can use separate library for each package to achieve
148
this, or always move away the newly installed package.
149
 
78896 ripley 150
Should a package require external libraries, these can be placed under
82190 ripley 151
LOCAL_SOFT as defined in etc/x64/Makeconf in the copy.
78896 ripley 152
 
87146 kalibera 153
Some packages use pkg-config to query C flags or libraries to link and
154
unconditionally use "pkg-config" from PATH.  For such packages one has to
155
arrange for "pkg-config" on PATH to call to the appropriate pkg-config
156
wrapper for the target platform and toolchain.  With Rtools, it is
157
"x86_64-w64-mingw32.static.posix-pkg-config".  This is not needed for
158
building R itself, R uses the wrapper directly.
159
 
86225 kalibera 160
When targeting aarch64 Windows, copy etc/Makeconf from the cross-build
161
(R_WIN) over etc/Makeconf of the linux build and edit the copy to have the
162
R_XTRA_CPPFLAGS, pointing to the cross-build, as above.  Copy bin/*.dll from
163
the cross-build to bin/ in the linux build.  Set R_CROSS_BUILD to
164
"singlearch".
78896 ripley 165
 
86225 kalibera 166
Cross-building the aarch64 installer
167
====================================
78896 ripley 168
 
86225 kalibera 169
One can cross-compile binaries of R and recommended packages as above and
170
then, on Windows/x86_64, build an installer for Windows/aarch64 using these.
171
 
172
First, build a native x86_64 build of R on Windows, including
173
"cairodevices", "recommended", "vignettes" and "manuals". This is all done
174
automatically when building the installer ("distribution") for x86_64.
175
However, such installer has to be copied away because it would be ovewritten
176
in the next step.
177
 
178
Then run
179
 
180
make rinstaller CROSS_BUILD=<cross-compiled-binaries>
181
 
182
the tree with cross-compiled-binaries must include:
183
 
184
Tcl (the full Tcl bundle for aarch64)
185
library/*/libs/*.dll
186
modules/*.dll
187
bin/*.dll
188
bin/*.exe,
189
bin/config.sh
190
etc/Makeconf 
191
 
192
Recommended packages must be placed under library, together with the base
193
packages.
194
 
195
The version of R and recommended packages must be identical on the Linux and
196
the Windows host.
197