Skip to content

Commit

Permalink
also support dll linking
Browse files Browse the repository at this point in the history
commit_hash:ebafc271047aa3ae660b813c3dcaee05324895bf
  • Loading branch information
pg committed Feb 13, 2025
1 parent 2997345 commit 8cad053
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 21 deletions.
2 changes: 2 additions & 0 deletions build/conf/linkers/ld.conf
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ REAL_LINK_EXEC_DYN_LIB_CMDLINE =\
$YMAKE_PYTHON ${input:"build/scripts/link_dyn_lib.py"} \
${hide;input:"build/scripts/link_exe.py"} \
--target $TARGET
REAL_LINK_EXEC_DYN_LIB_CMDLINE+=--start-plugins ${ext=.pyplugin:SRCS_GLOBAL} --end-plugins
REAL_LINK_EXEC_DYN_LIB_CMDLINE+=$_LD_LINKER_OUTPUT
REAL_LINK_EXEC_DYN_LIB_CMDLINE+=\
$_ROOT_FLAGS \
Expand Down Expand Up @@ -271,6 +272,7 @@ REAL_LINK_DYN_LIB_CMDLINE =\
$YMAKE_PYTHON ${input:"build/scripts/link_dyn_lib.py"} \
${hide;input:"build/scripts/link_exe.py"} \
--target $TARGET
REAL_LINK_DYN_LIB_CMDLINE+=--start-plugins ${ext=.pyplugin:SRCS_GLOBAL} --end-plugins
REAL_LINK_DYN_LIB_CMDLINE+=$_LD_LINKER_OUTPUT
REAL_LINK_DYN_LIB_CMDLINE+=\
${pre=--whole-archive-peers :WHOLE_ARCHIVE_PEERS} \
Expand Down
35 changes: 19 additions & 16 deletions build/scripts/link_dyn_lib.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import print_function
import sys
import os
import json
import subprocess
import tempfile
import collections
Expand Down Expand Up @@ -129,8 +130,6 @@ def fix_windows_param(ex):
return ['/DEF:{}'.format(def_file.name)]


MUSL_LIBS = '-lc', '-lcrypt', '-ldl', '-lm', '-lpthread', '-lrt', '-lutil'

CUDA_LIBRARIES = {
'-lcublas_static': '-lcublas',
'-lcublasLt_static': '-lcublasLt',
Expand Down Expand Up @@ -179,14 +178,6 @@ def do_fix(p):
return sum((do_fix(x) for x in c), [])


def fix_cmd_for_musl(cmd):
flags = []
for flag in cmd:
if flag not in MUSL_LIBS:
flags.append(flag)
return flags


def fix_cmd_for_dynamic_cuda(cmd):
flags = []
for flag in cmd:
Expand All @@ -208,7 +199,7 @@ def fix_blas_resolving(cmd):
return cmd


def parse_args():
def parse_args(args):
parser = optparse.OptionParser()
parser.disable_interspersed_args()
parser.add_option('--arch')
Expand All @@ -218,7 +209,6 @@ def parse_args():
parser.add_option('--build-root')
parser.add_option('--fix-elf')
parser.add_option('--linker-output')
parser.add_option('--musl', action='store_true')
parser.add_option('--dynamic-cuda', action='store_true')
parser.add_option('--cuda-architectures',
help='List of supported CUDA architectures, separated by ":" (e.g. "sm_52:compute_70:lto_90a"')
Expand All @@ -229,11 +219,26 @@ def parse_args():
parser.add_option('--custom-step')
parser.add_option('--python')
thinlto_cache.add_options(parser)
return parser.parse_args()
return parser.parse_args(args)


if __name__ == '__main__':
opts, args = parse_args()
args = sys.argv[1:]
plugins = []

if '--start-plugins' in args:
ib = args.index('--start-plugins')
ie = args.index('--end-plugins')
plugins = args[ib + 1:ie]
args = args[:ib] + args[ie + 1:]

for p in plugins:
res = subprocess.check_output([sys.executable, p] + args).decode().strip()

if res:
args = json.loads(res)

opts, args = parse_args(args)

assert opts.arch
assert opts.target
Expand All @@ -242,8 +247,6 @@ def parse_args():
cmd = fix_cmd(opts.arch, cmd)
cmd = fix_py2(cmd)

if opts.musl:
cmd = fix_cmd_for_musl(cmd)
if opts.dynamic_cuda:
cmd = fix_cmd_for_dynamic_cuda(cmd)
else:
Expand Down
11 changes: 7 additions & 4 deletions build/scripts/link_exe.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,10 +335,13 @@ def parse_args(args):

if __name__ == '__main__':
args = sys.argv[1:]
ib = args.index('--start-plugins')
ie = args.index('--end-plugins')
plugins = args[ib + 1:ie]
args = args[:ib] + args[ie + 1:]
plugins = []

if '--start-plugins' in args:
ib = args.index('--start-plugins')
ie = args.index('--end-plugins')
plugins = args[ib + 1:ie]
args = args[:ib] + args[ie + 1:]

for p in plugins:
res = subprocess.check_output([sys.executable, p] + args).decode().strip()
Expand Down
1 change: 0 additions & 1 deletion build/ymake.core.conf
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,6 @@ module _BASE_UNIT: _BARE_UNIT {

when ($MUSL == "yes") {
CFLAGS += -D_musl_
LINK_DYN_LIB_FLAGS += --musl
PEERDIR+=contrib/libs/musl/include
}

Expand Down

0 comments on commit 8cad053

Please sign in to comment.