Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # Copyright (c) 2013 The Native Client Authors. All rights reserved. | 2 # Copyright (c) 2013 The Native Client Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """Recipes for PNaCl toolchain packages. | 6 """Recipes for PNaCl toolchain packages. |
| 7 | 7 |
| 8 Recipes consist of specially-structured dictionaries, with keys for package | 8 Recipes consist of specially-structured dictionaries, with keys for package |
| 9 name, type, commands to execute, etc. The structure is documented in the | 9 name, type, commands to execute, etc. The structure is documented in the |
| 10 PackageBuilder docstring in toolchain_main.py. | 10 PackageBuilder docstring in toolchain_main.py. |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 132 | 132 |
| 133 def TripleIsMac(t): | 133 def TripleIsMac(t): |
| 134 return fnmatch.fnmatch(t, '*-darwin*') | 134 return fnmatch.fnmatch(t, '*-darwin*') |
| 135 | 135 |
| 136 def TripleIsX8664(t): | 136 def TripleIsX8664(t): |
| 137 return fnmatch.fnmatch(t, 'x86_64*') | 137 return fnmatch.fnmatch(t, 'x86_64*') |
| 138 | 138 |
| 139 def HostIsDebug(options): | 139 def HostIsDebug(options): |
| 140 return options.host_flavor == 'debug' | 140 return options.host_flavor == 'debug' |
| 141 | 141 |
| 142 # Return a tuple (C compiler, C++ compiler) of the compilers to compile the host | 142 # Return a tuple (C compiler, C++ compiler, ar, ranlib) of the compilers and |
| 143 # toolchains | 143 # tools to compile the host toolchains. |
| 144 def CompilersForHost(host): | 144 def CompilersForHost(host): |
| 145 compiler = { | 145 compiler = { |
| 146 # For now we only do native builds for linux and mac | 146 # For now we only do native builds for linux and mac |
| 147 # treat 32-bit linux like a native build | 147 # treat 32-bit linux like a native build |
| 148 'i686-linux': (CHROME_CLANG, CHROME_CLANGXX, 'ar', 'ranlib'), | 148 'i686-linux': (CHROME_CLANG, CHROME_CLANGXX, 'ar', 'ranlib'), |
| 149 'x86_64-linux': (CHROME_CLANG, CHROME_CLANGXX, 'ar', 'ranlib'), | 149 'x86_64-linux': (CHROME_CLANG, CHROME_CLANGXX, 'ar', 'ranlib'), |
| 150 'x86_64-apple-darwin': (CHROME_CLANG, CHROME_CLANGXX, 'ar', 'ranlib'), | 150 'x86_64-apple-darwin': (CHROME_CLANG, CHROME_CLANGXX, 'ar', 'ranlib'), |
| 151 # Windows build should work for native and cross | 151 # Windows build should work for native and cross |
| 152 'i686-w64-mingw32': ( | 152 'i686-w64-mingw32': ( |
| 153 'i686-w64-mingw32-gcc', 'i686-w64-mingw32-g++', 'ar', 'ranlib'), | 153 'i686-w64-mingw32-gcc', 'i686-w64-mingw32-g++', 'ar', 'ranlib'), |
| 154 # TODO: add arm-hosted support | 154 # TODO: add arm-hosted support |
| 155 'i686-pc-cygwin': ('gcc', 'g++', 'ar', 'ranlib'), | 155 'i686-pc-cygwin': ('gcc', 'g++', 'ar', 'ranlib'), |
| 156 } | 156 } |
| 157 if host == 'le32-nacl': | 157 if host == 'le32-nacl': |
| 158 nacl_sdk = os.environ.get('NACL_SDK_ROOT') | 158 nacl_sdk = os.environ.get('NACL_SDK_ROOT') |
| 159 assert nacl_sdk, 'NACL_SDK_ROOT not set' | 159 assert nacl_sdk, 'NACL_SDK_ROOT not set' |
| 160 pnacl_bin_dir = os.path.join(nacl_sdk, 'toolchain/linux_pnacl/bin') | 160 pnacl_bin_dir = os.path.join(nacl_sdk, 'toolchain/linux_pnacl/bin') |
| 161 glibc_bin_dir = os.path.join(nacl_sdk, 'toolchain/linux_x86_glibc/bin') | |
| 162 compiler.update({ | 161 compiler.update({ |
| 163 'le32-nacl': (os.path.join(pnacl_bin_dir, 'pnacl-clang'), | 162 'le32-nacl': (os.path.join(pnacl_bin_dir, 'pnacl-clang'), |
| 164 os.path.join(pnacl_bin_dir, 'pnacl-clang++'), | 163 os.path.join(pnacl_bin_dir, 'pnacl-clang++'), |
| 165 os.path.join(pnacl_bin_dir, 'pnacl-ar'), | 164 os.path.join(pnacl_bin_dir, 'pnacl-ar'), |
| 166 os.path.join(pnacl_bin_dir, 'pnacl-ranlib')), | 165 os.path.join(pnacl_bin_dir, 'pnacl-ranlib')), |
| 167 }) | 166 }) |
| 168 return compiler[host] | 167 return compiler[host] |
| 169 | 168 |
| 170 | 169 |
| 171 def GSDJoin(*args): | 170 def GSDJoin(*args): |
| 172 return '_'.join([pynacl.gsd_storage.LegalizeName(arg) for arg in args]) | 171 return '_'.join([pynacl.gsd_storage.LegalizeName(arg) for arg in args]) |
| 173 | 172 |
| 174 # name of a build target, including build flavor (debug/release) | 173 # name of a build target, including build flavor (debug/release) |
| 175 def FlavoredName(component_name, host, options): | 174 def FlavoredName(component_name, host, options): |
| 176 joined_name = GSDJoin(component_name, host) | 175 joined_name = GSDJoin(component_name, host) |
| 177 if HostIsDebug(options): | 176 if HostIsDebug(options): |
| 178 joined_name= joined_name + '_debug' | 177 joined_name= joined_name + '_debug' |
| 179 return joined_name | 178 return joined_name |
| 180 | 179 |
| 180 | |
| 181 def HostArchToolFlags(host, extra_cflags, opts): | |
| 182 """Return the appropriate CFLAGS, CXXFLAGS, and LDFLAGS based on host | |
| 183 and opts. Does not attempt to determine flags that are attached | |
| 184 to CC and CXX directly. | |
| 185 """ | |
| 186 extra_cc_flags = list(extra_cflags) | |
| 187 result = { 'LDFLAGS' : [], | |
| 188 'CFLAGS' : [], | |
| 189 'CXXFLAGS' : []} | |
| 190 if TripleIsWindows(host): | |
| 191 result['LDFLAGS'] += ['-L%(abs_libdl)s', '-ldl'] | |
| 192 result['CFLAGS'] += ['-isystem','%(abs_libdl)s'] | |
| 193 result['CXXFLAGS'] += ['-isystem', '%(abs_libdl)s'] | |
| 194 else: | |
| 195 if TripleIsLinux(host) and not TripleIsX8664(host): | |
| 196 # Chrome clang defaults to 64-bit builds, even when run on 32-bit Linux. | |
| 197 extra_cc_flags += ['-m32'] | |
| 198 elif TripleIsMac(host): | |
| 199 # This is required for building with recent libc++ against OSX 10.6 | |
| 200 extra_cc_flags += ['-U__STRICT_ANSI__'] | |
| 201 if opts.gcc or host == 'le32-nacl': | |
| 202 result['CFLAGS'] += extra_cc_flags | |
| 203 result['CXXFLAGS'] += extra_cc_flags | |
| 204 else: | |
| 205 result['CFLAGS'] += extra_cc_flags | |
| 206 result['LDFLAGS'] += ['-L%(' + FlavoredName('abs_libcxx', | |
| 207 host, opts) + ')s/lib'] | |
| 208 result['CXXFLAGS'] += ([ | |
| 209 '-stdlib=libc++', | |
| 210 '-I%(' + FlavoredName('abs_libcxx', host, opts) + ')s/include/c++/v1'] + | |
| 211 extra_cc_flags) | |
| 212 return result | |
| 213 | |
| 214 | |
| 181 def ConfigureHostArchFlags(host, extra_cflags, options, extra_configure=None): | 215 def ConfigureHostArchFlags(host, extra_cflags, options, extra_configure=None): |
| 182 """ Return flags passed to LLVM and binutils configure for compilers and | 216 """ Return flags passed to LLVM and binutils configure for compilers and |
| 183 compile flags. """ | 217 compile flags. """ |
| 184 configure_args = [] | 218 configure_args = [] |
| 185 extra_cc_args = [] | 219 extra_cc_args = [] |
| 186 | 220 |
| 187 configure_args += options.extra_configure_args | 221 configure_args += options.extra_configure_args |
| 188 if extra_configure is not None: | 222 if extra_configure is not None: |
| 189 configure_args += extra_configure | 223 configure_args += extra_configure |
| 190 if options.extra_cc_args is not None: | 224 if options.extra_cc_args is not None: |
| 191 extra_cc_args += [options.extra_cc_args] | 225 extra_cc_args += [options.extra_cc_args] |
| 192 | 226 |
| 193 native = pynacl.platform.PlatformTriple() | 227 native = pynacl.platform.PlatformTriple() |
| 194 is_cross = host != native | 228 is_cross = host != native |
| 195 if is_cross: | 229 if is_cross: |
| 196 if (pynacl.platform.IsLinux64() and | 230 if (pynacl.platform.IsLinux64() and |
| 197 fnmatch.fnmatch(host, '*-linux*')): | 231 fnmatch.fnmatch(host, '*-linux*')): |
| 198 # 64 bit linux can build 32 bit linux binaries while still being a native | 232 # 64 bit linux can build 32 bit linux binaries while still being a native |
| 199 # build for our purposes. But it's not what config.guess will yield, so | 233 # build for our purposes. But it's not what config.guess will yield, so |
| 200 # use --build to force it and make sure things build correctly. | 234 # use --build to force it and make sure things build correctly. |
| 201 configure_args.append('--build=' + host) | 235 configure_args.append('--build=' + host) |
| 202 else: | 236 else: |
| 203 configure_args.append('--host=' + host) | 237 configure_args.append('--host=' + host) |
| 204 if TripleIsLinux(host) and not TripleIsX8664(host): | |
| 205 # Chrome clang defaults to 64-bit builds, even when run on 32-bit Linux. | |
| 206 extra_cc_args += ['-m32'] | |
| 207 | 238 |
| 208 extra_cxx_args = list(extra_cc_args) | 239 extra_cxx_args = list(extra_cc_args) |
| 209 | 240 |
| 210 if not options.gcc: | 241 if not options.gcc: |
| 211 cc, cxx, ar, ranlib = CompilersForHost(host) | 242 cc, cxx, ar, ranlib = CompilersForHost(host) |
| 212 | 243 |
| 213 configure_args.append('CC=' + ' '.join([cc] + extra_cc_args)) | 244 configure_args.append('CC=' + ' '.join([cc] + extra_cc_args)) |
| 214 configure_args.append('CXX=' + ' '.join([cxx] + extra_cxx_args)) | 245 configure_args.append('CXX=' + ' '.join([cxx] + extra_cxx_args)) |
| 215 configure_args.append('AR=' + ar) | 246 configure_args.append('AR=' + ar) |
| 216 configure_args.append('RANLIB=' + ranlib) | 247 configure_args.append('RANLIB=' + ranlib) |
| 217 | 248 |
| 249 tool_flags = HostArchToolFlags(host, extra_cflags, options) | |
| 250 configure_args.extend( | |
| 251 ['CFLAGS=' + ' '.join(tool_flags['CFLAGS']), | |
| 252 'CXXFLAGS=' + ' '.join(tool_flags['CXXFLAGS']), | |
| 253 'LDFLAGS=' + ' '.join(tool_flags['LDFLAGS']), | |
| 254 ]) | |
| 218 if TripleIsWindows(host): | 255 if TripleIsWindows(host): |
| 219 # The i18n support brings in runtime dependencies on MinGW DLLs | 256 # The i18n support brings in runtime dependencies on MinGW DLLs |
| 220 # that we don't want to have to distribute alongside our binaries. | 257 # that we don't want to have to distribute alongside our binaries. |
| 221 # So just disable it, and compiler messages will always be in US English. | 258 # So just disable it, and compiler messages will always be in US English. |
| 222 configure_args.append('--disable-nls') | 259 configure_args.append('--disable-nls') |
| 223 configure_args.extend(['LDFLAGS=-L%(abs_libdl)s -ldl', | |
| 224 'CFLAGS=-isystem %(abs_libdl)s', | |
| 225 'CXXFLAGS=-isystem %(abs_libdl)s']) | |
| 226 if is_cross: | 260 if is_cross: |
| 227 # LLVM's linux->mingw cross build needs this | 261 # LLVM's linux->mingw cross build needs this |
| 228 configure_args.append('CC_FOR_BUILD=gcc') | 262 configure_args.append('CC_FOR_BUILD=gcc') |
| 229 else: | |
| 230 if TripleIsMac(host): | |
| 231 # This is required for building with recent libc++ against OSX 10.6 | |
| 232 extra_cflags.append('-U__STRICT_ANSI__') | |
| 233 if options.gcc or host == 'le32-nacl': | |
| 234 configure_args.extend(['CFLAGS=' + ' '.join(extra_cflags), | |
| 235 'CXXFLAGS=' + ' '.join(extra_cflags)]) | |
| 236 else: | |
| 237 configure_args.extend( | |
| 238 ['CFLAGS=' + ' '.join(extra_cflags), | |
| 239 'LDFLAGS=-L%(' + FlavoredName('abs_libcxx', | |
| 240 host, | |
| 241 options) + ')s/lib', | |
| 242 'CXXFLAGS=-stdlib=libc++ -I%(' + | |
| 243 FlavoredName('abs_libcxx', host, options) + | |
| 244 ')s/include/c++/v1 ' + ' '.join(extra_cflags)]) | |
| 245 | |
| 246 return configure_args | 263 return configure_args |
| 247 | 264 |
| 248 | 265 |
| 249 def LibCxxHostArchFlags(host): | 266 def LibCxxHostArchFlags(host): |
| 250 cc, cxx, _, _ = CompilersForHost(host) | 267 cc, cxx, _, _ = CompilersForHost(host) |
| 251 cmake_flags = [] | 268 cmake_flags = [] |
| 252 cmake_flags.extend(['-DCMAKE_C_COMPILER='+cc, '-DCMAKE_CXX_COMPILER='+cxx]) | 269 cmake_flags.extend(['-DCMAKE_C_COMPILER='+cc, '-DCMAKE_CXX_COMPILER='+cxx]) |
| 253 if TripleIsLinux(host) and not TripleIsX8664(host): | 270 if TripleIsLinux(host) and not TripleIsX8664(host): |
| 254 # Chrome clang defaults to 64-bit builds, even when run on 32-bit Linux | 271 # Chrome clang defaults to 64-bit builds, even when run on 32-bit Linux |
| 255 cmake_flags.extend(['-DCMAKE_C_FLAGS=-m32', | 272 cmake_flags.extend(['-DCMAKE_C_FLAGS=-m32', |
| 256 '-DCMAKE_CXX_FLAGS=-m32']) | 273 '-DCMAKE_CXX_FLAGS=-m32']) |
| 257 return cmake_flags | 274 return cmake_flags |
| 258 | 275 |
| 276 | |
| 259 def CmakeHostArchFlags(host, options): | 277 def CmakeHostArchFlags(host, options): |
| 260 """ Set flags passed to LLVM cmake for compilers and compile flags. """ | 278 """ Set flags passed to LLVM cmake for compilers and compile flags. """ |
| 261 cmake_flags = [] | 279 cmake_flags = [] |
| 262 cc, cxx, _, _ = CompilersForHost(host) | 280 cc, cxx, _, _ = CompilersForHost(host) |
| 263 | 281 |
| 264 cmake_flags.extend(['-DCMAKE_C_COMPILER='+cc, '-DCMAKE_CXX_COMPILER='+cxx]) | 282 cmake_flags.extend(['-DCMAKE_C_COMPILER='+cc, '-DCMAKE_CXX_COMPILER='+cxx]) |
| 265 | 283 |
| 266 # There seems to be a bug in chrome clang where it exposes the msan interface | 284 # There seems to be a bug in chrome clang where it exposes the msan interface |
| 267 # (even when compiling without msan) but then does not link with an | 285 # (even when compiling without msan) but then does not link with an |
| 268 # msan-enabled compiler_rt, leaving references to __msan_allocated_memory | 286 # msan-enabled compiler_rt, leaving references to __msan_allocated_memory |
| 269 # undefined. | 287 # undefined. |
| 270 cmake_flags.append('-DHAVE_SANITIZER_MSAN_INTERFACE_H=FALSE') | 288 cmake_flags.append('-DHAVE_SANITIZER_MSAN_INTERFACE_H=FALSE') |
| 271 | 289 tool_flags = HostArchToolFlags(host, [], options) |
| 272 if options.sanitize: | 290 if options.sanitize: |
| 273 cmake_flags.extend(['-DCMAKE_%s_FLAGS=-fsanitize=%s' % (c, options.sanitize) | 291 for f in ['CFLAGS', 'CXXFLAGS', 'LDFLAGS']: |
| 274 for c in ('C', 'CXX')]) | 292 tool_flags[f] += '-fsanitize=%s' % options.sanitize |
| 275 cmake_flags.append('-DCMAKE_EXE_LINKER_FLAGS=-fsanitize=%s' % | 293 cmake_flags.extend(['-DCMAKE_C_FLAGS=' + ' '.join(tool_flags['CFLAGS'])]) |
| 276 options.sanitize) | 294 cmake_flags.extend(['-DCMAKE_CXX_FLAGS=' + ' '.join(tool_flags['CXXFLAGS'])]) |
| 277 | 295 cmake_flags.extend(['-DCMAKE_EXE_LINKER_FLAGS=' + |
| 296 ' '.join(tool_flags['LDFLAGS'])]) | |
| 278 return cmake_flags | 297 return cmake_flags |
| 279 | 298 |
| 280 | 299 |
| 281 def ConfigureBinutilsCommon(): | 300 def ConfigureBinutilsCommon(): |
| 282 return ['--with-pkgversion=' + PACKAGE_NAME, | 301 return ['--with-pkgversion=' + PACKAGE_NAME, |
| 283 '--with-bugurl=' + BUG_URL, | 302 '--with-bugurl=' + BUG_URL, |
| 284 '--without-zlib', | 303 '--without-zlib', |
| 285 '--prefix=', | 304 '--prefix=', |
| 286 '--disable-silent-rules', | 305 '--disable-silent-rules', |
| 287 '--enable-deterministic-archives', | 306 '--enable-deterministic-archives', |
| (...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 619 '-DCMAKE_INSTALL_RPATH=$ORIGIN/../lib', | 638 '-DCMAKE_INSTALL_RPATH=$ORIGIN/../lib', |
| 620 '-DLLVM_APPEND_VC_REV=ON', | 639 '-DLLVM_APPEND_VC_REV=ON', |
| 621 '-DLLVM_BINUTILS_INCDIR=%(abs_binutils_pnacl_src)s/include', | 640 '-DLLVM_BINUTILS_INCDIR=%(abs_binutils_pnacl_src)s/include', |
| 622 '-DLLVM_BUILD_TESTS=ON', | 641 '-DLLVM_BUILD_TESTS=ON', |
| 623 '-DLLVM_ENABLE_ASSERTIONS=ON', | 642 '-DLLVM_ENABLE_ASSERTIONS=ON', |
| 624 '-DLLVM_ENABLE_LIBCXX=OFF', | 643 '-DLLVM_ENABLE_LIBCXX=OFF', |
| 625 '-LLVM_ENABLE_WERROR=' + ('ON' if llvm_do_werror else 'OFF'), | 644 '-LLVM_ENABLE_WERROR=' + ('ON' if llvm_do_werror else 'OFF'), |
| 626 '-DLLVM_ENABLE_ZLIB=OFF', | 645 '-DLLVM_ENABLE_ZLIB=OFF', |
| 627 '-DLLVM_EXTERNAL_CLANG_SOURCE_DIR=%(clang_src)s', | 646 '-DLLVM_EXTERNAL_CLANG_SOURCE_DIR=%(clang_src)s', |
| 628 '-DLLVM_TARGETS_TO_BUILD=X86;ARM;Mips', | 647 '-DLLVM_TARGETS_TO_BUILD=X86;ARM;Mips', |
| 629 '%(llvm_src)s']), | 648 '%(llvm_src)s'], |
| 630 command.Command(['ninja', '-v']), | 649 # Older CMake ignore CMAKE_*_LINKER_FLAGS during config step. |
|
jvoung (off chromium)
2015/03/09 22:42:32
Well, I too ran into a trycompile link failure.
T
| |
| 631 command.Command(['ninja', 'install']), | 650 # https://public.kitware.com/Bug/view.php?id=14066 |
| 632 ] + | 651 # The workaround is to set LDFLAGS in the environment. |
| 633 CreateSymLinksToDirectToNaClTools(host) | 652 env={'LDFLAGS' : ' '.join( |
| 653 HostArchToolFlags(host, [], options)['LDFLAGS'])})] + | |
| 654 CopyHostLibcxxForLLVMBuild(host, 'lib', options) + | |
| 655 [command.Command(['ninja', '-v']), | |
| 656 command.Command(['ninja', 'install'])] + | |
| 657 CreateSymLinksToDirectToNaClTools(host) | |
| 634 }, | 658 }, |
| 635 } | 659 } |
| 636 cleanup_static_libs = [] | 660 cleanup_static_libs = [] |
| 637 shared = [] | 661 shared = [] |
| 638 if host != 'le32-nacl': | 662 if host != 'le32-nacl': |
| 639 shared = ['--enable-shared'] | 663 shared = ['--enable-shared'] |
| 640 cleanup_static_libs = [ | 664 cleanup_static_libs = [ |
| 641 command.Remove(*[os.path.join('%(output)s', 'lib', f) for f | 665 command.Remove(*[os.path.join('%(output)s', 'lib', f) for f |
| 642 in '*.a', '*Hello.*', 'BugpointPasses.*']), | 666 in '*.a', '*Hello.*', 'BugpointPasses.*']), |
| 643 ] | 667 ] |
| (...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1119 'x86-32-%s' % pynacl.platform.GetOS(), unsandboxed_irt_canonical)) | 1143 'x86-32-%s' % pynacl.platform.GetOS(), unsandboxed_irt_canonical)) |
| 1120 | 1144 |
| 1121 if args.build_sbtc and not args.pnacl_in_pnacl: | 1145 if args.build_sbtc and not args.pnacl_in_pnacl: |
| 1122 packages.update(pnacl_sandboxed_translator.SandboxedTranslators( | 1146 packages.update(pnacl_sandboxed_translator.SandboxedTranslators( |
| 1123 SANDBOXED_TRANSLATOR_ARCHES)) | 1147 SANDBOXED_TRANSLATOR_ARCHES)) |
| 1124 | 1148 |
| 1125 tb = toolchain_main.PackageBuilder(packages, | 1149 tb = toolchain_main.PackageBuilder(packages, |
| 1126 upload_packages, | 1150 upload_packages, |
| 1127 leftover_args) | 1151 leftover_args) |
| 1128 tb.Main() | 1152 tb.Main() |
| OLD | NEW |