Skip to content

Commit

Permalink
Add check for libatomic requirement to Python build system (#7184)
Browse files Browse the repository at this point in the history
* Add check for libatomic requirement to Python build system

* More thorough check

* Fix typos
  • Loading branch information
wintersteiger committed Mar 23, 2024
1 parent 648e057 commit 80642e5
Showing 1 changed file with 31 additions and 7 deletions.
38 changes: 31 additions & 7 deletions scripts/mk_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,26 @@ def test_fpmath(cc):
FPMATH_FLAGS=""
return "UNKNOWN"

def test_atomic_required(cc):
t = TempFile('tstatomic.cpp')
t.add("""
#include <atomic>
std::atomic<int> x;
std::atomic<short> y;
std::atomic<char> z;
std::atomic<long long> w;
int main() {
++z;
++y;
++w;
return ++x;
}
""")
t.commit()
fails_without = exec_compiler_cmd([cc, CPPFLAGS, '', 'tstatomic.cpp', LDFLAGS, '']) != 0
ok_with = exec_compiler_cmd([cc, CPPFLAGS, '', 'tstatomic.cpp', LDFLAGS + ' -latomic', '']) == 0
return fails_without and ok_with


def find_jni_h(path):
for root, dirs, files in os.walk(path):
Expand Down Expand Up @@ -555,19 +575,19 @@ def set_version(major, minor, build, revision):
print("Set Assembly Version (BUILD):", VER_MAJOR, VER_MINOR, VER_BUILD, VER_TWEAK)
return

# use parameters to set up version if not provided by script args
# use parameters to set up version if not provided by script args
VER_MAJOR = major
VER_MINOR = minor
VER_BUILD = build
VER_TWEAK = revision

# update VER_TWEAK base on github
# update VER_TWEAK base on github
if GIT_DESCRIBE:
branch = check_output(['git', 'rev-parse', '--abbrev-ref', 'HEAD'])
VER_TWEAK = int(check_output(['git', 'rev-list', '--count', 'HEAD']))

print("Set Assembly Version (DEFAULT):", VER_MAJOR, VER_MINOR, VER_BUILD, VER_TWEAK)

def get_version():
return (VER_MAJOR, VER_MINOR, VER_BUILD, VER_TWEAK)

Expand Down Expand Up @@ -1858,7 +1878,7 @@ def mk_makefile(self, out):
os.path.join('api', 'java', 'Native'))
elif IS_OSX and IS_ARCH_ARM64:
out.write('\t$(SLINK) $(SLINK_OUT_FLAG)libz3java$(SO_EXT) $(SLINK_FLAGS) -arch arm64 %s$(OBJ_EXT) libz3$(SO_EXT)\n' %
os.path.join('api', 'java', 'Native'))
os.path.join('api', 'java', 'Native'))
else:
out.write('\t$(SLINK) $(SLINK_OUT_FLAG)libz3java$(SO_EXT) $(SLINK_FLAGS) %s$(OBJ_EXT) libz3$(SO_EXT)\n' %
os.path.join('api', 'java', 'Native'))
Expand Down Expand Up @@ -2600,6 +2620,9 @@ def mk_config():
CXXFLAGS = '%s -fvisibility=hidden -fvisibility-inlines-hidden -c' % CXXFLAGS
FPMATH = test_fpmath(CXX)
CXXFLAGS = '%s %s' % (CXXFLAGS, FPMATH_FLAGS)
atomic_required = test_atomic_required(CXX)
if atomic_required:
LDFLAGS = '%s -latomic' % LDFLAGS
if LOG_SYNC:
CXXFLAGS = '%s -DZ3_LOG_SYNC' % CXXFLAGS
if SINGLE_THREADED:
Expand Down Expand Up @@ -2710,6 +2733,7 @@ def mk_config():
print('Prefix: %s' % PREFIX)
print('64-bit: %s' % is64())
print('FP math: %s' % FPMATH)
print('libatomic: %s' % ('required' if atomic_required else 'not required'))
print("Python pkg dir: %s" % PYTHON_PACKAGE_DIR)
if GPROF:
print('gprof: enabled')
Expand Down Expand Up @@ -2854,7 +2878,7 @@ def update_version():
revision = VER_TWEAK

print("UpdateVersion:", get_full_version_string(major, minor, build, revision))

if major is None or minor is None or build is None or revision is None:
raise MKException("set_version(major, minor, build, revision) must be used before invoking update_version()")
if not ONLY_MAKEFILES:
Expand Down Expand Up @@ -3068,7 +3092,7 @@ def mk_bindings(api_files):
z3py_output_dir=get_z3py_dir(),
dotnet_output_dir=dotnet_output_dir,
java_input_dir=java_input_dir,
java_output_dir=java_output_dir,
java_output_dir=java_output_dir,
java_package_name=java_package_name,
ml_output_dir=ml_output_dir,
ml_src_dir=ml_output_dir
Expand Down

0 comments on commit 80642e5

Please sign in to comment.