Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit 0f323b1

Browse files
committed
[[ Win64 ]] Sort out arch vars, and ensure prebuilts are fetched
This patch ensures that TARGET_ARCH is always x86_64 for 64-bit X86 processors, and that target_arch (the gyp variable) is always x64 for x86-64 on Win32. Additionally, it introduces a new gyp var uniform_arch, which is either x86_64 or x86. Finally, a 'fetch' phase has been added which fetches the prebuilts for host and target. This ensures that they are present before configuration (which eliminates missing file warnings from gyp) and that Visual Studio can build projects in its own order (which can cause failure to find prebuilt includes).
1 parent 5da4151 commit 0f323b1

File tree

9 files changed

+183
-25
lines changed

9 files changed

+183
-25
lines changed

buildbot.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434

3535
# LiveCode build configuration script
3636
import config
37+
import fetch
3738

3839
# The set of platforms for which this branch supports automated builds
3940
BUILDBOT_PLATFORM_TRIPLES = (
@@ -112,6 +113,18 @@ def exec_buildbot_make(target):
112113
print(' '.join(args))
113114
sys.exit(subprocess.call(args))
114115

116+
################################################################
117+
# Fetch prebuilts
118+
################################################################
119+
120+
def exec_fetch(args):
121+
print('fetch.py ' + ' '.join(args))
122+
sys.exit(fetch.fetch(args))
123+
124+
def do_fetch():
125+
check_target_triple()
126+
exec_fetch(['--target', get_target_triple()])
127+
115128
################################################################
116129
# Configure with gyp
117130
################################################################

config.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -215,26 +215,26 @@ def validate_target_arch(opts):
215215
platform = opts['PLATFORM']
216216
if platform == 'emscripten':
217217
opts['TARGET_ARCH'] = 'js'
218-
return
219-
220-
# Windows builds don't understand 'x86_64'
221-
if platform == 'win-x86_64':
222-
opts['TARGET_ARCH'] = 'x64'
218+
opts['UNIFORM_ARCH'] = opts['TARGET_ARCH']
223219
return
224220

225221
platform_arch = re.search('-(x86|x86_64|armv6)$', platform)
226222
if platform_arch is not None:
227223
opts['TARGET_ARCH'] = platform_arch.group(1)
224+
opts['UNIFORM_ARCH'] = opts['TARGET_ARCH']
228225
return
229226

230227
if re.match('^(ios|mac)', platform) is not None:
231228
validate_xcode_sdks(opts)
232229
arch = guess_xcode_arch(opts['XCODE_TARGET_SDK'])
233230
if arch is not None:
234231
opts['TARGET_ARCH'] = arch
232+
opts['UNIFORM_ARCH'] = opts['TARGET_ARCH']
235233
return
236234

237235
error("Couldn't guess target architecture for '{}'".format(platform))
236+
else:
237+
opts['UNIFORM_ARCH'] = opts['TARGET_ARCH']
238238

239239
################################################################
240240
# Guess other general options
@@ -474,6 +474,8 @@ def core_gyp_args(opts):
474474
if opts['BUILD_EDITION'] == 'commercial':
475475
args.append(os.path.join('..', 'livecode-commercial.gyp'))
476476

477+
args.append('-Duniform_arch=' + opts['UNIFORM_ARCH'])
478+
477479
return args
478480

479481
def export_opts(opts, names):
@@ -520,6 +522,14 @@ def configure_win(opts):
520522
validate_target_arch(opts)
521523
validate_windows_tools(opts)
522524

525+
# Make sure we strictly enforce TARGET_ARCH being x86 or x86_64
526+
if opts['TARGET_ARCH'] != 'x86' and opts['TARGET_ARCH'] != 'x86_64':
527+
error("TARGET_ARCH must be x86 or x86_64")
528+
529+
# Map target_arch for gyp - x86_64 -> x64
530+
if opts['TARGET_ARCH'] == 'x86_64':
531+
opts['TARGET_ARCH'] = 'x64'
532+
523533
args = core_gyp_args(opts) + ['-Gmsvs_version=' + opts['WIN_MSVS_VERSION']]
524534
args += gyp_define_args(opts, {'target_arch': 'TARGET_ARCH',
525535
'ms_speech_sdk5': 'MS_SPEECH_SDK5',

configure.bat

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,19 @@ IF NOT DEFINED BUILD_EDITION SET BUILD_EDITION="community"
1515
REM Target architecture currently defaults to 32-bit x86
1616
IF NOT DEFINED TARGET_ARCH SET TARGET_ARCH=x86
1717

18-
REM The internal MSVC/Gyp name for x86_64 is x64
19-
IF %TARGET_ARCH%==x86_64 (
20-
SET MSVC_ARCH=x64
21-
) ELSE (
22-
SET MSVC_ARCH=%TARGET_ARCH%
23-
)
18+
REM Make sure TARGET_ARCH is always x86 or x86_64
2419

25-
REM The LiveCode name for x86_64 is x86_64
26-
IF %MSVC_ARCH%==x64 (
27-
SET LC_ARCH=x86_64
20+
IF %TARGET_ARCH%==x64 (
21+
SET TARGET_ARCH=x86_64
22+
) ELSE IF %TARGET_ARCH%==i386 (
23+
SET TARGET_ARCH=x86
24+
) ELSE IF %TARGET_ARCH% ==x86 (
25+
REM Valid
26+
) ELSE IF %TARGET_ARCH% == x86_64 (
27+
REM Valid
2828
) ELSE (
29-
SET LC_ARCH=x86
29+
ECHO >&2 Error: invalid target arch %TARGET_ARCH%
30+
EXIT /B 1
3031
)
3132

3233
REM Note: to test whether a directory exists in batch script, you need to check
@@ -61,7 +62,7 @@ REM Pause so any warnings can be seen
6162
IF %warnings% NEQ 0 PAUSE
6263

6364
REM Run the configure step
64-
%python% config.py --platform win-%LC_ARCH% -Dtarget_arch=%MSVC_ARCH% %extra_options% %gypfile%
65+
%python% config.py --platform win-%TARGET_ARCH% %extra_options% %gypfile%
6566
PAUSE
6667

6768
REM Pause if there was an error so that the user gets a chance to see it

fetch.py

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
#!/usr/bin/env python
2+
# Copyright (C) 2017 LiveCode Ltd.
3+
#
4+
# This file is part of LiveCode.
5+
#
6+
# LiveCode is free software; you can redistribute it and/or modify it under
7+
# the terms of the GNU General Public License v3 as published by the Free
8+
# Software Foundation.
9+
#
10+
# LiveCode is distributed in the hope that it will be useful, but WITHOUT ANY
11+
# WARRANTY; without even the implied warranty of MERCHANTABILITY or
12+
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13+
# for more details.
14+
#
15+
# You should have received a copy of the GNU General Public License
16+
# along with LiveCode. If not see <http://www.gnu.org/licenses/>.
17+
18+
import sys
19+
import platform
20+
import os
21+
import subprocess
22+
23+
def usage(exit_status):
24+
print(
25+
"""Fetch prebuilts needed to build LiveCode.
26+
27+
Usage:
28+
fetch.py [--target TARGET]
29+
30+
Options:
31+
-p, --target TARGET
32+
Choose which target triple to build for
33+
-h, --help Print this message
34+
""")
35+
for p in KNOWN_PLATFORMS:
36+
print(" " + p)
37+
sys.exit(exit_status)
38+
39+
def error(message):
40+
print('ERROR: ' + message)
41+
sys.exit(1)
42+
43+
def guess_target():
44+
system = platform.system()
45+
arch = platform.machine()
46+
if system == 'Darwin':
47+
return 'mac'
48+
if system == 'Linux':
49+
if re.match('^(x|i.?)86$', arch) is not None:
50+
return 'linux-x86'
51+
else:
52+
return 'linux-' + arch
53+
if system == 'Windows':
54+
if arch == 'AMD64':
55+
return 'win32-x86_64'
56+
else:
57+
return 'win32-x86'
58+
59+
################################################################
60+
# Parse command-line options
61+
################################################################
62+
63+
def process_env_options(opts):
64+
vars = ('TARGET',)
65+
for v in vars:
66+
opts[v] = os.getenv(v)
67+
68+
def process_arg_options(opts, args):
69+
offset = 0
70+
while offset < len(args):
71+
key = args[offset]
72+
if offset + 1 < len(args):
73+
value = args[offset + 1]
74+
else:
75+
value = None
76+
77+
if key in ('-h', '--help'):
78+
usage(0)
79+
if key in ('-p', '--target'):
80+
opts['TARGET'] = value
81+
offset += 2
82+
continue
83+
84+
# Unrecognised option
85+
error("Unrecognised option '{}'".format(key))
86+
87+
################################################################
88+
# Validate
89+
################################################################
90+
91+
def validate_target(opts):
92+
target = opts['TARGET']
93+
if target is None:
94+
target = guess_target()
95+
if target is None:
96+
error("Cannot guess target; specify '--target <name>-'")
97+
98+
opts['TARGET'] = target
99+
100+
################################################################
101+
# Action
102+
################################################################
103+
104+
def exec_fetch_libraries(build_platform):
105+
if platform.system() == 'Windows':
106+
args = [".\util\invoke-unix.bat", "prebuilt/fetch-libraries.sh", build_platform]
107+
else:
108+
args = ["./prebuilt/fetch-libraries.sh", build_platform]
109+
print(' '.join(args))
110+
status = subprocess.call(args)
111+
if status != 0:
112+
sys.exit(status)
113+
114+
def fetch(args):
115+
opts = {}
116+
process_env_options(opts)
117+
process_arg_options(opts, args)
118+
119+
validate_target(opts)
120+
121+
# Get the host platform to pass to fetch-libraries
122+
host_platform = guess_target().split('-')[0]
123+
124+
# Get the target platform to pass to fetch-libraries
125+
target_platform = opts['TARGET'].split('-')[0]
126+
127+
print('Fetching host platform prebuilts (' + host_platform + ')')
128+
exec_fetch_libraries(host_platform)
129+
130+
print('Fetching target platform prebuilts (' + target_platform + ')')
131+
exec_fetch_libraries(target_platform)
132+
133+
if __name__ == '__main__':
134+
fetch(sys.argv[1:])

prebuilt/fetch-libraries.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,10 +195,9 @@ for PLATFORM in ${SELECTED_PLATFORMS} ; do
195195
for ARCH in "${ARCHS[@]}" ; do
196196
for LIB in "${LIBS[@]}" ; do
197197
echo "Monkey patching toolset/arch for ${LIB} library"
198-
for SUBPLATFORM in "${SUBPLATFORMS[@]}"; do
198+
for SUBPLATFORM in "${SUBPLATFORMS[@]} v140_static_fast"; do
199199
SRC_TRIPLE="${ARCH}-${PLATFORM}-${SUBPLATFORM}"
200200
DST_TRIPLE=$(echo "${SRC_TRIPLE}" | sed 's/v140/v141/')
201-
DST_TRIPLE=$(echo "${DST_TRIPLE}" | sed 's/x86_64/x64/')
202201
SRC_DIR="${WIN32_EXTRACT_DIR}/${LIB}/${SRC_TRIPLE}"
203202
DST_DIR="${WIN32_EXTRACT_DIR}/${LIB}/${DST_TRIPLE}"
204203
if [[ -d "${SRC_DIR}" && ! -d "${DST_DIR}" ]]; then

prebuilt/fetch.gyp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,7 @@
396396
'outputs':
397397
[
398398
'lib/win32/<(target_arch)',
399+
'unpacked',
399400
],
400401

401402
'action':

prebuilt/libcurl.gyp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
{
2626
'include_dirs':
2727
[
28-
'unpacked/curl/<(target_arch)-win32-$(PlatformToolset)_static_$(ConfigurationName)/include',
28+
'unpacked/curl/<(uniform_arch)-win32-$(PlatformToolset)_static_$(ConfigurationName)/include',
2929
],
3030
},
3131
],
@@ -74,7 +74,7 @@
7474
{
7575
'library_dirs':
7676
[
77-
'unpacked/curl/<(target_arch)-win32-$(PlatformToolset)_static_$(ConfigurationName)/lib',
77+
'unpacked/curl/<(uniform_arch)-win32-$(PlatformToolset)_static_$(ConfigurationName)/lib',
7878
],
7979

8080
'libraries':

prebuilt/libicu.gyp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
{
3434
'include_dirs':
3535
[
36-
'unpacked/icu/<(target_arch)-win32-$(PlatformToolset)_static_$(ConfigurationName)/include',
36+
'unpacked/icu/<(uniform_arch)-win32-$(PlatformToolset)_static_$(ConfigurationName)/include',
3737
],
3838
},
3939
],
@@ -146,7 +146,7 @@
146146
{
147147
'library_dirs':
148148
[
149-
'unpacked/icu/<(target_arch)-win32-$(PlatformToolset)_static_$(ConfigurationName)/lib',
149+
'unpacked/icu/<(uniform_arch)-win32-$(PlatformToolset)_static_$(ConfigurationName)/lib',
150150
],
151151

152152
'libraries':

prebuilt/libopenssl.gyp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
{
2525
'include_dirs':
2626
[
27-
'unpacked/openssl/<(target_arch)-win32-$(PlatformToolset)_static_$(ConfigurationName)/include',
27+
'unpacked/openssl/<(uniform_arch)-win32-$(PlatformToolset)_static_$(ConfigurationName)/include',
2828
],
2929
},
3030
],
@@ -58,7 +58,7 @@
5858
{
5959
'include_dirs':
6060
[
61-
'unpacked/openssl/<(target_arch)-win32-$(PlatformToolset)_static_$(ConfigurationName)/include',
61+
'unpacked/openssl/<(uniform_arch)-win32-$(PlatformToolset)_static_$(ConfigurationName)/include',
6262
],
6363
},
6464
],
@@ -138,7 +138,7 @@
138138
{
139139
'library_dirs':
140140
[
141-
'unpacked/openssl/<(target_arch)-win32-$(PlatformToolset)_static_$(ConfigurationName)/lib',
141+
'unpacked/openssl/<(uniform_arch)-win32-$(PlatformToolset)_static_$(ConfigurationName)/lib',
142142
],
143143

144144
'libraries':

0 commit comments

Comments
 (0)