Skip to content

Commit 669ef08

Browse files
authored
Update build for OSX and windows (#18)
* Update build configuration, goal is to make cross-compilation (used for osx-arm64 by conda-forge) actually work * Update SConstruct to take into account different build configurations (including osx_arm64 cross-compilation) based on environment variables (PREFIX, BUILD_PREFIX, CONDA_PREFIX..)
1 parent ce2de47 commit 669ef08

File tree

4 files changed

+63
-55
lines changed

4 files changed

+63
-55
lines changed

SConstruct

+50-46
Original file line numberDiff line numberDiff line change
@@ -48,54 +48,76 @@ env.EnsureSConsVersion(0, 98, 1)
4848
# Customizable compile variables
4949
vars = Variables('sconsvars.py')
5050

51-
# TODO: also amend paths when VIRTUAL_ENV variable exists,
52-
# if CONDA_PREFIX does not exist ?
53-
if 'CONDA_PREFIX' in os.environ:
51+
# Set PREFIX for installation and linking
52+
# TODO: also amend paths when VIRTUAL_ENV variable exists ?
53+
if 'PREFIX' in os.environ:
54+
# building with a set prefix
55+
vars.Add(PathVariable(
56+
'prefix',
57+
'installation prefix directory',
58+
os.environ['PREFIX']))
59+
vars.Update(env)
60+
elif 'CONDA_PREFIX' in os.environ:
5461
# building for a conda environment
5562
vars.Add(PathVariable(
5663
'prefix',
5764
'installation prefix directory',
5865
os.environ['CONDA_PREFIX']))
5966
vars.Update(env)
60-
if platform.system().lower() == "windows":
61-
vars.Add(PathVariable(
62-
'libdir',
63-
'installation directory for compiled library [prefix/Library/lib]',
64-
pjoin(env['prefix'], 'Library', 'Lib'),
65-
PathVariable.PathAccept))
66-
vars.Add(PathVariable(
67-
'includedir',
68-
'installation directory for C++ header files [prefix/Library/include]',
69-
pjoin(env['prefix'], 'Library', 'include'),
70-
PathVariable.PathAccept))
71-
else:
72-
vars.Add(PathVariable(
73-
'libdir',
74-
'installation directory for compiled library [prefix/lib]',
75-
pjoin(env['prefix'], 'lib'),
76-
PathVariable.PathAccept))
77-
vars.Add(PathVariable(
78-
'includedir',
79-
'installation directory for C++ header files [prefix/include]',
80-
pjoin(env['prefix'], 'include'),
81-
PathVariable.PathAccept))
8267
else:
68+
# Default: install in /usr/local
8369
vars.Add(PathVariable(
8470
'prefix',
8571
'installation prefix directory',
8672
'/usr/local'))
87-
vars.Update(env)
73+
74+
if platform.system().lower() == "windows":
75+
# Installation paths
76+
vars.Add(PathVariable(
77+
'libdir',
78+
'installation directory for compiled library [prefix/Library/lib]',
79+
pjoin(env['prefix'], 'Library', 'Lib'),
80+
PathVariable.PathAccept))
81+
vars.Add(PathVariable(
82+
'includedir',
83+
'installation directory for C++ header files [prefix/Library/include]',
84+
pjoin(env['prefix'], 'Library', 'include'),
85+
PathVariable.PathAccept))
86+
87+
# See https://scons.org/faq.html#Linking_on_Windows_gives_me_an_error
88+
env['ENV']['TMP'] = os.environ['TMP']
89+
# Prevent the generation of an import lib (.lib) in addition to the dll
90+
# Unused as we are using as static library for windows
91+
# env.AppendUnique(no_import_lib=1)
92+
93+
# Compilation and linking paths
94+
env.Append(CPPPATH=[pjoin(env['prefix'], 'include')])
95+
env.Append(CPPPATH=[pjoin(env['prefix'], 'Library', 'include')])
96+
env.Append(LIBPATH=pjoin(env['prefix'], 'Library', 'lib'))
97+
else:
98+
# Installation paths
8899
vars.Add(PathVariable(
89100
'libdir',
90101
'installation directory for compiled library [prefix/lib]',
91-
env['prefix'] + '/lib',
102+
pjoin(env['prefix'], 'lib'),
92103
PathVariable.PathAccept))
93104
vars.Add(PathVariable(
94105
'includedir',
95106
'installation directory for C++ header files [prefix/include]',
96-
env['prefix'] + '/include',
107+
pjoin(env['prefix'], 'include'),
97108
PathVariable.PathAccept))
98109

110+
# Compilation and linking paths
111+
env.Append(CPPPATH=[pjoin(env['prefix'], 'include')])
112+
env.Append(LIBPATH=[pjoin(env['prefix'], 'lib')])
113+
114+
# Specify minimum C++ standard. Allow later standard from sconscript.local.
115+
# In case of multiple `-std` options the last option holds.
116+
env.PrependUnique(CXXFLAGS='-std=c++11', delete_existing=1)
117+
118+
# for k, v in env.Dictionary().items():
119+
# print(k, v)
120+
99121
vars.Add(EnumVariable(
100122
'build',
101123
'compiler settings',
@@ -114,24 +136,6 @@ vars.Add(BoolVariable(
114136
vars.Update(env)
115137
env.Help(MY_SCONS_HELP % vars.GenerateHelpText(env))
116138

117-
if platform.system().lower() == "windows":
118-
# See https://scons.org/faq.html#Linking_on_Windows_gives_me_an_error
119-
env['ENV']['TMP'] = os.environ['TMP']
120-
# Prevent the generation of an import lib (.lib) in addition to the dll
121-
# Unused as we are using as static library for windows
122-
# env.AppendUnique(no_import_lib=1)
123-
if 'CONDA_PREFIX' in os.environ:
124-
env.Append(CPPPATH=[pjoin(os.environ['CONDA_PREFIX'], 'include')])
125-
env.Append(CPPPATH=[pjoin(os.environ['CONDA_PREFIX'], 'Library', 'include')])
126-
env.Append(LIBPATH=pjoin(os.environ['CONDA_PREFIX'], 'Library', 'lib'))
127-
else:
128-
if 'CONDA_PREFIX' in os.environ:
129-
env.Append(CPPPATH=pjoin(os.environ['CONDA_PREFIX'], 'include'))
130-
env.Append(LIBPATH=pjoin(os.environ['CONDA_PREFIX'], 'lib'))
131-
# Specify minimum C++ standard. Allow later standard from sconscript.local.
132-
# In case of multiple `-std` options the last option holds.
133-
env.PrependUnique(CXXFLAGS='-std=c++11', delete_existing=1)
134-
135139
# the CPPPATH directories are checked by scons dependency scanner
136140
cpppath = getsyspaths('CPLUS_INCLUDE_PATH', 'CPATH')
137141
env.AppendUnique(CPPPATH=cpppath)

conda-recipe/conda_build_config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
boost:
2-
- 1.73
2+
- 1.78
33

44
# only for local build ? see https://github.com/conda/conda-build/issues/4064#issuecomment-702983257
55
#CONDA_BUILD_SYSROOT:

conda-recipe/sconscript.local

+11-7
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,18 @@ Import('env')
55
import os
66
import platform
77

8-
if platform.system() != 'Darwin':
9-
# Apply environment settings for Anaconda compilers
10-
env.Replace(CXX=os.environ['CXX'])
11-
env.MergeFlags(os.environ['CFLAGS'])
12-
env.MergeFlags(os.environ['CPPFLAGS'])
13-
env.MergeFlags(os.environ['CXXFLAGS'])
14-
env.MergeFlags(os.environ['LDFLAGS'])
8+
if platform.system().lower() == 'darwin' and 'CONDA_BUILD_SYSROOT' in os.environ:
9+
env.AppendUnique(CPPFLAGS=['-isysroot', os.environ['CONDA_BUILD_SYSROOT']])
10+
env.AppendUnique(LINKFLAGS=['-isysroot', os.environ['CONDA_BUILD_SYSROOT']])
11+
12+
# Apply environment settings for Anaconda compilers
13+
env.Replace(CXX=os.environ['CXX'])
14+
env.MergeFlags(os.environ['CFLAGS'])
15+
env.MergeFlags(os.environ['CPPFLAGS'])
16+
env.MergeFlags(os.environ['CXXFLAGS'])
17+
env.MergeFlags(os.environ['LDFLAGS'])
1518

19+
if platform.system() != 'Darwin':
1620
# Use the default c++98 language standard
1721
cxxflags98 = [f for f in env['CXXFLAGS'] if not f.startswith('-std=')]
1822
env.Replace(CXXFLAGS=cxxflags98)

site_scons/fallback_version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
Update FALLBACK_VERSION when tagging a new release.
88
'''
99

10-
FALLBACK_VERSION = '2022.1.post0'
10+
FALLBACK_VERSION = '2022.1.1.post0'

0 commit comments

Comments
 (0)