Skip to content

Commit 564bd1c

Browse files
committed
build: make extensions an array and advertise variants
This will allow distributions to contain multiple implementations of the same extension. This will be useful for distributing e.g. readline versus libedit, static versus dynamic linking, etc.
1 parent 392bc59 commit 564bd1c

File tree

4 files changed

+29
-13
lines changed

4 files changed

+29
-13
lines changed

README.rst

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,14 +319,20 @@ core
319319
An array of linking requirement maps. (See below for data format.)
320320

321321
extensions
322-
A map of extension names to a map describing the extension.
322+
A map of extension names to an array of maps describing candidate extensions.
323323

324324
Extensions are non-core/non-essential parts of the Python distribution that
325325
are frequently built as standalone entities.
326326

327327
Names in this map denote the name of the extension module.
328328

329-
Values are maps with the following keys:
329+
Values are arrays of maps. Each map represents a potential candidate
330+
providing the extension. There is frequently only a single extension
331+
candidate. Multiple candidates can occur if there are e.g. varying
332+
libraries an extension can be linked against to supply underlying
333+
functionality.
334+
335+
Each map has the following keys:
330336

331337
in_core
332338
Boolean indicating if this extension is defined by the core distribution.
@@ -359,6 +365,11 @@ extensions
359365
The path to a static library defining this extension module. May not
360366
be defined.
361367

368+
variant
369+
String describing this extension variant. Downstream consumers can key off
370+
this value to choose an appropriate extension variant when there are
371+
multiple options.
372+
362373
Each entry in a ``links`` array is a map with the following keys:
363374

364375
name

cpython-linux/build.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -481,12 +481,13 @@ def process_setup_line(line):
481481
'system': True,
482482
})
483483

484-
bi['extensions'][extension] = {
484+
bi['extensions'][extension] = [{
485485
'in_core': False,
486486
'init_fn': 'PyInit_%s' % extension,
487487
'links': links,
488488
'objs': objs,
489-
}
489+
'variant': 'default',
490+
}]
490491

491492

492493
found_start = False
@@ -516,12 +517,13 @@ def process_setup_line(line):
516517
# can register their PyInit_ functions.
517518
for name, init_fn in sorted(config_c_in.items()):
518519
log('adding in-core extension %s' % name)
519-
bi['extensions'][name] = {
520+
bi['extensions'][name] = [{
520521
'in_core': True,
521522
'init_fn': init_fn,
522523
'links': [],
523524
'objs': [],
524-
}
525+
'variant': 'default',
526+
}]
525527

526528
# Any paths left in modules_objs are not part of any extension and are
527529
# instead part of the core distribution.

cpython-macos/build.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -237,12 +237,13 @@ def process_setup_line(line):
237237
'system': True,
238238
})
239239

240-
bi['extensions'][extension] = {
240+
bi['extensions'][extension] = [{
241241
'in_core': False,
242242
'init_fn': 'PyInit_%s' % extension,
243243
'links': links,
244244
'objs': objs,
245-
}
245+
'variant': 'default',
246+
}]
246247

247248
found_start = False
248249

@@ -267,12 +268,13 @@ def process_setup_line(line):
267268

268269
for name, init_fn in sorted(config_c_in.items()):
269270
log('adding in-core extension %s' % name)
270-
bi['extensions'][name] = {
271+
bi['extensions'][name] = [{
271272
'in_core': True,
272273
'init_fn': init_fn,
273274
'links': [],
274275
'objs': [],
275-
}
276+
'variant': 'default',
277+
}]
276278

277279
# Any paths left in modules_objs are not part of any extensions and
278280
# are instead part of the core distribution.

cpython-windows/build.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,13 +1170,14 @@ def find_additional_dependencies(project: pathlib.Path):
11701170
additional_depends = find_additional_dependencies(ext)
11711171
additional_depends -= CONVERT_TO_BUILTIN_EXTENSIONS.get(ext, {}).get('ignore_additional_depends', set())
11721172

1173-
res['extensions'][ext] = {
1173+
res['extensions'][ext] = [{
11741174
'in_core': False,
11751175
'objs': [],
11761176
'init_fn': 'PyInit_%s' % ext,
11771177
'static_lib': None,
11781178
'links': [{'name': n[:-4], 'system': True} for n in sorted(additional_depends)],
1179-
}
1179+
'variant': 'default',
1180+
}]
11801181

11811182
for obj in process_project(ext, dest_dir):
11821183
res['extensions'][ext]['objs'].append('build/extensions/%s/%s' % (ext, obj))
@@ -1196,7 +1197,7 @@ def find_additional_dependencies(project: pathlib.Path):
11961197
# Copy the extension static library.
11971198
ext_static = outputs_path / ('%s.lib' % ext)
11981199
dest = dest_dir / ('%s.lib' % ext)
1199-
res['extensions'][ext]['static_lib'] = 'build/extensions/%s/%s.lib' % (ext, ext)
1200+
res['extensions'][ext][0]['static_lib'] = 'build/extensions/%s/%s.lib' % (ext, ext)
12001201
log('copying static extension %s' % ext_static)
12011202
shutil.copyfile(ext_static, dest)
12021203

0 commit comments

Comments
 (0)