29
29
30
30
ANDROID_TARGET_VERSION : str = '31'
31
31
32
- CONFIG_TOML_TEMPLATE : Path = TEMPLATES_PATH / 'config.toml.template'
33
- DEVICE_CC_WRAPPER_TEMPLATE : Path = TEMPLATES_PATH / 'device_cc_wrapper.template'
34
- DEVICE_TARGET_TEMPLATE : Path = TEMPLATES_PATH / 'device_target.template'
35
- HOST_CC_WRAPPER_TEMPLATE : Path = TEMPLATES_PATH / 'host_cc_wrapper.template'
36
- HOST_CXX_WRAPPER_TEMPLATE : Path = TEMPLATES_PATH / 'host_cxx_wrapper.template'
37
- HOST_TARGET_TEMPLATE : Path = TEMPLATES_PATH / 'host_target.template'
38
-
39
- # Add the path at which libc++ can be found in Android checkouts
40
- CXX_LINKER_FLAGS : str = ' -Wl,-rpath,'
41
- if build_platform .system () == 'darwin' :
42
- CXX_LINKER_FLAGS += '@loader_path/../lib64'
43
- CXX_LINKER_FLAGS += ' -mmacosx-version-min=10.14'
44
- else :
45
- CXX_LINKER_FLAGS += '\\ $ORIGIN/../lib64'
46
- # Add the path at which libc++ can be found during the build
47
- CXX_LINKER_FLAGS += (' -L' + LLVM_CXX_RUNTIME_PATH .as_posix () +
48
- ' -Wl,-rpath,' + LLVM_CXX_RUNTIME_PATH .as_posix ())
49
-
50
- LD_OPTIONS : str = None
51
- if build_platform .system () == 'linux' :
52
- LD_OPTIONS = '-fuse-ld=lld -Wno-unused-command-line-argument'
53
- else :
54
- LD_OPTIONS = ''
32
+ CONFIG_TOML_TEMPLATE : Path = TEMPLATES_PATH / 'config.toml.template'
33
+ DEVICE_CC_WRAPPER_TEMPLATE : Path = TEMPLATES_PATH / 'device_cc_wrapper.template'
34
+ DEVICE_LINKER_WRAPPER_TEMPLATE : Path = TEMPLATES_PATH / 'device_linker_wrapper.template'
35
+ DEVICE_TARGET_TEMPLATE : Path = TEMPLATES_PATH / 'device_target.template'
36
+ HOST_CC_WRAPPER_TEMPLATE : Path = TEMPLATES_PATH / 'host_cc_wrapper.template'
37
+ HOST_CXX_WRAPPER_TEMPLATE : Path = TEMPLATES_PATH / 'host_cxx_wrapper.template'
38
+ HOST_LINKER_WRAPPER_TEMPLATE : Path = TEMPLATES_PATH / 'host_linker_wrapper.template'
39
+ HOST_TARGET_TEMPLATE : Path = TEMPLATES_PATH / 'host_target.template'
40
+
41
+ MACOSX_VERSION_FLAG : str = '-mmacosx-version-min=10.14'
55
42
56
43
57
44
def instantiate_template_exec (template_path : Path , output_path : Path , ** kwargs ):
@@ -66,39 +53,47 @@ def instantiate_template_file(template_path: Path, output_path: Path, make_exec:
66
53
output_path .chmod (output_path .stat ().st_mode | stat .S_IEXEC )
67
54
68
55
69
- def host_config (target : str , toolchain_flags : str ) -> str :
70
- cc_wrapper_name = OUT_PATH_WRAPPERS / ('clang-%s' % target )
71
- cxx_wrapper_name = OUT_PATH_WRAPPERS / ('clang++-%s' % target )
56
+ def host_config (target : str , macosx_flags : str , linker_flags : str ) -> str :
57
+ cc_wrapper_name = OUT_PATH_WRAPPERS / ('clang-%s' % target )
58
+ cxx_wrapper_name = OUT_PATH_WRAPPERS / ('clang++-%s' % target )
59
+ linker_wrapper_name = OUT_PATH_WRAPPERS / ('linker-%s' % target )
72
60
73
61
instantiate_template_exec (
74
62
HOST_CC_WRAPPER_TEMPLATE ,
75
63
cc_wrapper_name ,
76
64
real_cc = CC_PATH ,
77
- ld_option = LD_OPTIONS ,
78
65
target = target ,
79
- toolchain_flags = toolchain_flags )
66
+ macosx_flags = macosx_flags )
80
67
81
68
instantiate_template_exec (
82
69
HOST_CXX_WRAPPER_TEMPLATE ,
83
70
cxx_wrapper_name ,
84
71
real_cxx = CXX_PATH ,
85
- ld_option = LD_OPTIONS ,
86
72
target = target ,
87
- toolchain_flags = toolchain_flags ,
88
- cxxstd = CXXSTD_PATH ,
89
- cxx_linker_flags = CXX_LINKER_FLAGS )
73
+ macosx_flags = macosx_flags ,
74
+ cxxstd = CXXSTD_PATH )
75
+
76
+ instantiate_template_exec (
77
+ HOST_LINKER_WRAPPER_TEMPLATE ,
78
+ linker_wrapper_name ,
79
+ real_cxx = CXX_PATH ,
80
+ target = target ,
81
+ macosx_flags = macosx_flags ,
82
+ linker_flags = linker_flags )
90
83
91
84
with open (HOST_TARGET_TEMPLATE , 'r' ) as template_file :
92
85
return Template (template_file .read ()).substitute (
93
86
target = target ,
94
87
cc = cc_wrapper_name ,
95
88
cxx = cxx_wrapper_name ,
89
+ linker = linker_wrapper_name ,
96
90
ar = AR_PATH ,
97
91
ranlib = RANLIB_PATH )
98
92
99
93
100
94
def device_config (target : str ) -> str :
101
- cc_wrapper_name = OUT_PATH_WRAPPERS / ('clang-%s' % target )
95
+ cc_wrapper_name = OUT_PATH_WRAPPERS / ('clang-%s' % target )
96
+ linker_wrapper_name = OUT_PATH_WRAPPERS / ('linker-%s' % target )
102
97
103
98
clang_target = target + ANDROID_TARGET_VERSION
104
99
@@ -109,28 +104,51 @@ def device_config(target: str) -> str:
109
104
target = clang_target ,
110
105
sysroot = NDK_SYSROOT_PATH )
111
106
107
+ instantiate_template_exec (
108
+ DEVICE_LINKER_WRAPPER_TEMPLATE ,
109
+ linker_wrapper_name ,
110
+ real_cc = CC_PATH ,
111
+ target = clang_target ,
112
+ sysroot = NDK_SYSROOT_PATH )
113
+
112
114
with open (DEVICE_TARGET_TEMPLATE , 'r' ) as template_file :
113
115
return Template (template_file .read ()).substitute (
114
- target = target , cc = cc_wrapper_name , ar = AR_PATH )
116
+ target = target ,
117
+ cc = cc_wrapper_name ,
118
+ linker = linker_wrapper_name ,
119
+ ar = AR_PATH )
115
120
116
121
117
122
def configure ():
118
- """Generates config.toml for the rustc build."""
119
- host_toolchain_flags = None
123
+ """Generates config.toml and compiler wrapers for the rustc build."""
124
+
125
+ macosx_flags : str = ''
126
+ host_ld_selector : str = '-fuse-ld=lld' if build_platform .is_linux () else ''
127
+ host_bin_search : str = ('-B' + GCC_TOOLCHAIN_PATH .as_posix ()) if build_platform .is_linux () else ''
128
+ host_llvm_libpath : str = '-L' + LLVM_CXX_RUNTIME_PATH .as_posix ()
129
+ host_rpath_buildtime : str = '-Wl,-rpath,' + LLVM_CXX_RUNTIME_PATH .as_posix ()
130
+ host_rpath_runtime : str = '-Wl,-rpath,' + (
131
+ '$ORIGIN/../lib64' if build_platform .is_linux () else '@loader_path/../lib64' )
120
132
121
- if build_platform .system () == 'darwin' :
133
+ if build_platform .is_darwin () :
122
134
# Apple removed the normal sysroot at / on Mojave+, so we need
123
135
# to go hunt for it on OSX
124
136
# On pre-Mojave, this command will output the empty string.
125
137
output = subprocess .check_output (
126
138
['xcrun' , '--sdk' , 'macosx' , '--show-sdk-path' ])
127
- host_toolchain_flags = "--sysroot " + output .rstrip ().decode ('utf-8' )
128
- else :
129
- # On Linux build hosts we need to set the path to the gcc toolchain.
130
- host_toolchain_flags = "-B " + GCC_TOOLCHAIN_PATH .as_posix ()
139
+ macosx_flags = (
140
+ MACOSX_VERSION_FLAG +
141
+ " --sysroot " + output .rstrip ().decode ('utf-8' ))
142
+
143
+ host_linker_flags = ' ' .join ([
144
+ host_ld_selector ,
145
+ host_bin_search ,
146
+ host_llvm_libpath ,
147
+ host_rpath_buildtime ,
148
+ host_rpath_runtime ])
131
149
132
150
host_configs = '\n ' .join (
133
- [host_config (target , host_toolchain_flags ) for target in HOST_TARGETS ])
151
+ [host_config (target , macosx_flags , host_linker_flags ) for target in HOST_TARGETS ])
134
152
device_configs = '\n ' .join (
135
153
[device_config (target ) for target in DEVICE_TARGETS ])
136
154
@@ -140,6 +158,7 @@ def configure():
140
158
instantiate_template_file (
141
159
CONFIG_TOML_TEMPLATE ,
142
160
OUT_PATH_RUST_SOURCE / 'config.toml' ,
161
+ llvm_ldflags = host_linker_flags ,
143
162
all_targets = all_targets ,
144
163
cargo = CARGO_PATH ,
145
164
rustc = RUSTC_PATH ,
0 commit comments