Skip to content

Commit d739e2b

Browse files
committed
some more comments
1 parent a0ff6b4 commit d739e2b

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

python/build.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,17 @@
1313

1414

1515
def flexlink_library_dir_option(self, dir):
16-
# replace c:\ by /c/
17-
return "-L" + dir.replace("C:", "/c").replace("D:", "/d").replace("\\", "/")
16+
# replace /LIB: by -L for flexlink
17+
return "-L" + dir
18+
19+
20+
def flexlink_spawn(self, cmd):
21+
# even if the environment variable is set, it would fail if not passed here
22+
flexdir = "d:/a/facile/facile/_opam/lib/ocaml/flexdll/"
23+
env = dict(os.environ, PATH=self._paths, FLEXDIR=flexdir)
24+
with self._fallback_spawn(cmd, env) as fallback:
25+
return super().spawn(cmd, env=env)
26+
return fallback.value
1827

1928

2029
def flexlink_link(
@@ -33,6 +42,7 @@ def flexlink_link(
3342
build_temp=None,
3443
target_lang=None,
3544
):
45+
# Rewrite the link() method for flexlink
3646
from setuptools._distutils._log import log
3747
from setuptools._distutils._msvccompiler import gen_lib_options
3848
from setuptools._distutils.errors import DistutilsExecError, LinkError
@@ -82,7 +92,6 @@ def flexlink_link(
8292
output_dir = os.path.dirname(os.path.abspath(output_filename))
8393
self.mkpath(output_dir)
8494
try:
85-
print('Executing "%s" %s', self.linker, " ".join(ld_args))
8695
log.debug('Executing "%s" %s', self.linker, " ".join(ld_args))
8796
self.spawn([self.linker, *ld_args])
8897
except DistutilsExecError as msg:
@@ -130,8 +139,6 @@ def build() -> None:
130139
compileargs += " -std=c99"
131140
# elif sys.platform.startswith("win"):
132141
elif sysconfig.get_platform().startswith("win"):
133-
os.environ["FLEXDIR"] = "/d/a/facile/facile/_opam/lib/ocaml/flexdll/"
134-
135142
ocamlpath = os.popen("opam exec -- ocamlopt -where").readline().strip()
136143
if ocamlpath == "":
137144
raise SystemError("ocamlopt not found")
@@ -141,6 +148,7 @@ def build() -> None:
141148
" /wd4024" # different types for formal and actual parameter
142149
" /wd4047" # 'value *' differs in levels of indirection
143150
)
151+
# directly in the flexlink format
144152
extra_link_args += [
145153
"-lvcruntime",
146154
"-lversion",
@@ -184,6 +192,7 @@ def build_extensions(self):
184192

185193
self.compiler.linker = flexlink_path
186194

195+
# with /GL (by default), the symbols are not found by flexlink
187196
self.compiler.compile_options = [
188197
"/nologo",
189198
"/O2",
@@ -194,6 +203,7 @@ def build_extensions(self):
194203
]
195204

196205
self.compiler.__class__.link = flexlink_link
206+
self.compiler.__class__.spawn = flexlink_spawn
197207
self.compiler.__class__.library_dir_option = (
198208
flexlink_library_dir_option
199209
)

0 commit comments

Comments
 (0)