@@ -84,6 +84,26 @@ def get_module_name(package_name):
84
84
return module_name .replace ('-' , '_' )
85
85
86
86
87
+ def have_flang_new ():
88
+ env_path = os .environ .get ('PATH' , '' ).split (os .pathsep )
89
+ for p in env_path :
90
+ flang_new = os .path .join (p , 'flang-new' )
91
+ if os .path .isfile (flang_new ):
92
+ return True
93
+ return False
94
+
95
+
96
+ def get_flang_new_lib_dir ():
97
+ try :
98
+ output = subprocess .check_output (['flang-new' , '--version' ])
99
+ except (OSError , subprocess .CalledProcessError ):
100
+ pass
101
+ else :
102
+ flang_dir = output .splitlines ()[- 1 ].split ()[- 1 ].strip ().decode ("utf-8" )
103
+ return os .path .normpath (os .path .join (flang_dir , '..' , 'lib' ))
104
+ return None
105
+
106
+
87
107
def get_path_env_var (var ):
88
108
env_var = os .environ .get (var , None )
89
109
if isinstance (env_var , str ) and env_var .lower () == 'none' :
@@ -406,10 +426,13 @@ def make_site_cfg(root):
406
426
append_env_var (numpy_build_env , 'CFLAGS' , '-Wno-error=implicit-function-declaration' )
407
427
info (f"have lapack or blas ... CLFAGS={ numpy_build_env ['CFLAGS' ]} " )
408
428
409
- numpy_build_env ["FC" ] = "flang-new"
410
- install_from_pypi ("numpy==1.23.5" , build_cmd = ["build_ext" , "--disable-optimization" ,
411
- "config" , "--fcompiler=flang-new" ], env = numpy_build_env ,
412
- pre_install_hook = make_site_cfg , ** kwargs )
429
+ with_flang = have_flang_new ()
430
+ build_cmd = ["build_ext" , "--disable-optimization" ]
431
+ if with_flang :
432
+ numpy_build_env ["FC" ] = "flang-new"
433
+ build_cmd += ["config" , "--fcompiler=flang-new" ]
434
+ install_from_pypi ("numpy==1.23.5" , build_cmd = build_cmd , env = numpy_build_env , pre_install_hook = make_site_cfg ,
435
+ ** kwargs )
413
436
414
437
# print numpy configuration
415
438
if sys .implementation .name != 'graalpy' or __graalpython__ .platform_id != 'managed' :
@@ -491,7 +514,6 @@ def scipy(**kwargs):
491
514
xit ("SciPy can only be installed within a venv." )
492
515
from distutils .sysconfig import get_config_var
493
516
scipy_build_env ["LDFLAGS" ] = get_config_var ("LDFLAGS" )
494
- scipy_build_env ["FC" ] = "flang-new"
495
517
496
518
if have_lapack () or have_openblas ():
497
519
append_env_var (scipy_build_env , 'CFLAGS' , '-Wno-error=implicit-function-declaration' )
@@ -502,8 +524,34 @@ def scipy(**kwargs):
502
524
pybind11 (** kwargs )
503
525
pythran (** kwargs )
504
526
505
- install_from_pypi ("scipy==1.8.1" , build_cmd = ["config" , "--fcompiler=flang-new" ],
506
- env = scipy_build_env , ** kwargs )
527
+ scipy_version = "1.8.1"
528
+ # scipy_version = "1.9.3"
529
+ with_meson = False
530
+ if scipy_version >= "1.9.1" :
531
+ meson (** kwargs )
532
+ ninja (** kwargs )
533
+ with_flang = have_flang_new ()
534
+ with_meson = True
535
+ if with_flang :
536
+ # until flang-new can compile propack we disable it (during runtime)
537
+ scipy_build_env ["USE_PROPACK" ] = "0"
538
+ scipy_build_env ['CC' ] = 'clang'
539
+ scipy_build_env ['CXX' ] = 'clang++'
540
+ scipy_build_env ['FC' ] = 'flang-new'
541
+ if sys .implementation .name == "graalpy" :
542
+ cflags = "-flto=full"
543
+ else :
544
+ ld = 'lld'
545
+ cflags = "-flto=full -fuse-ld=lld -Wl,--mllvm=-lto-embed-bitcode=optimized,--lto-O0"
546
+ scipy_build_env ['CC_LD' ] = ld
547
+ scipy_build_env ['CXX_LD' ] = ld
548
+ scipy_build_env ['FC_LD' ] = ld
549
+ scipy_build_env ['CFLAGS' ] = cflags
550
+ scipy_build_env ['CXXFLAGS' ] = cflags
551
+ scipy_build_env ['FFLAGS' ] = cflags
552
+ scipy_build_env ['FFLAGS' ] = cflags
553
+ append_env_var (scipy_build_env , 'LDFLAGS' , f'-L{ get_flang_new_lib_dir ()} ' )
554
+ install_from_pypi (f"scipy=={ scipy_version } " , env = scipy_build_env , with_meson = with_meson , ** kwargs )
507
555
508
556
@pip_package ()
509
557
def scikit_learn (** kwargs ):
@@ -631,7 +679,7 @@ def _download_with_curl_and_extract(dest_dir, url, quiet=False):
631
679
632
680
633
681
def _install_from_url (url , package , extra_opts = None , add_cflags = "" , ignore_errors = False , env = None , version = None ,
634
- pre_install_hook = None , build_cmd = None , debug_build = False ):
682
+ pre_install_hook = None , build_cmd = None , debug_build = False , with_meson = False ):
635
683
if build_cmd is None :
636
684
build_cmd = []
637
685
if env is None :
@@ -683,24 +731,36 @@ def _install_from_url(url, package, extra_opts=None, add_cflags="", ignore_error
683
731
os .path .join (tempdir , bare_name , subdir )
684
732
run_cmd (["patch" , "-d" , os .path .join (tempdir , bare_name , subdir ), "-p1" , "-i" , patch_file_path ], quiet = quiet )
685
733
734
+ tmp_cwd = os .path .join (tempdir , bare_name )
686
735
if pre_install_hook :
687
- pre_install_hook (os . path . join ( tempdir , bare_name ) )
736
+ pre_install_hook (tmp_cwd )
688
737
689
738
if "--user" not in extra_opts and "--prefix" not in extra_opts and site .ENABLE_USER_SITE :
690
739
user_arg = ["--user" ]
691
740
else :
692
741
user_arg = []
742
+
693
743
start = time .time ()
694
- cmd = [sys .executable ]
695
- if debug_build and sys .implementation .name == 'graalpy' :
696
- cmd += ["-debug-java" , "--python.ExposeInternalSources" , "--python.WithJavaStacktrace=2" ]
697
- cmd += ["setup.py" ] + build_cmd + ["install" ] + user_arg + extra_opts
698
- status = run_cmd (cmd , env = setup_env ,
699
- cwd = os .path .join (tempdir , bare_name ), quiet = quiet )
744
+ if with_meson :
745
+ for cmd in [
746
+ ['meson' , 'setup' , f'--prefix={ os .environ .get ("VIRTUAL_ENV" )} ' , 'build' ],
747
+ ['meson' , 'compile' , '-C' , 'build' , '--ninja-args=-j4' ], # limit concurrency to 4
748
+ ['meson' , 'install' , '-C' , 'build' ],
749
+ ]:
750
+ status = run_cmd (cmd , env = setup_env , cwd = tmp_cwd , quiet = quiet )
751
+ if status != 0 and not ignore_errors :
752
+ xit (f"An error occurred trying to run `{ ' ' .join (cmd )} '" )
753
+ else :
754
+ cmd = [sys .executable ]
755
+ if debug_build and sys .implementation .name == 'graalpy' :
756
+ cmd += ["-debug-java" , "--python.ExposeInternalSources" , "--python.WithJavaStacktrace=2" ]
757
+ cmd += ["setup.py" ] + build_cmd + ["install" ] + user_arg + extra_opts
758
+ status = run_cmd (cmd , env = setup_env , cwd = tmp_cwd , quiet = quiet )
759
+ if status != 0 and not ignore_errors :
760
+ xit ("An error occurred trying to run `setup.py install {!s} {}'" , user_arg , " " .join (extra_opts ))
761
+
700
762
end = time .time ()
701
- if status != 0 and not ignore_errors :
702
- xit ("An error occurred trying to run `setup.py install {!s} {}'" , user_arg , " " .join (extra_opts ))
703
- elif quiet :
763
+ if quiet :
704
764
info ("{} successfully installed (took {:.2f} s)" , package , (end - start ))
705
765
706
766
@@ -754,7 +814,7 @@ def package_from_path(pth):
754
814
755
815
756
816
def install_from_pypi (package , extra_opts = None , add_cflags = "" , ignore_errors = True , env = None , pre_install_hook = None ,
757
- build_cmd = None , debug_build = False ):
817
+ build_cmd = None , debug_build = False , with_meson = False ):
758
818
if build_cmd is None :
759
819
build_cmd = []
760
820
if extra_opts is None :
@@ -810,7 +870,7 @@ def set_if_exists(env_var, conf_var):
810
870
if url :
811
871
_install_from_url (url , package = package , extra_opts = extra_opts , add_cflags = add_cflags ,
812
872
ignore_errors = ignore_errors , env = env , version = version , pre_install_hook = pre_install_hook ,
813
- build_cmd = build_cmd , debug_build = debug_build )
873
+ build_cmd = build_cmd , debug_build = debug_build , with_meson = with_meson )
814
874
else :
815
875
xit ("Package not found: '{!s}'" , package )
816
876
0 commit comments