Skip to content

[WIP] Contrib ports system #13002

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 29 additions & 13 deletions tools/ports/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,42 @@
ports_dir = os.path.dirname(os.path.abspath(__file__))


def read_ports():
def load_port(port):
expected_attrs = ['get', 'clear', 'process_args', 'show', 'needed']
ports.append(port)
ports_by_name[port.name] = port
for a in expected_attrs:
assert hasattr(port, a), 'port %s is missing %s' % (port, a)
if not hasattr(port, 'process_dependencies'):
port.process_dependencies = lambda x: 0
if not hasattr(port, 'deps'):
port.deps = []

def read_ports():
for filename in os.listdir(ports_dir):
if not filename.endswith('.py') or filename == '__init__.py':
continue
filename = os.path.splitext(filename)[0]
port = __import__(filename, globals(), level=1)
ports.append(port)
port.name = filename
ports_by_name[port.name] = port
for a in expected_attrs:
assert hasattr(port, a), 'port %s is missing %s' % (port, a)
if not hasattr(port, 'process_dependencies'):
port.process_dependencies = lambda x: 0
if not hasattr(port, 'deps'):
port.deps = []

for dep in port.deps:
if dep not in ports_by_name:
exit_with_error('unknown dependency in port: %s' % dep)
load_port(port)

contrib_dir = os.path.join(ports_dir, 'contrib')
for filename in os.listdir(contrib_dir):
if not filename.endswith('.py') or filename == '__init__.py':
continue
filename = os.path.splitext(filename)[0]
print(filename)
port = __import__('contrib.' + filename, globals(), level=1, fromlist=[None])
print(port)
port.name = filename
load_port(port)

for port in ports:
for dep in port.deps:
if dep not in ports_by_name:
exit_with_error('unknown dependency in port: %s' % dep)



read_ports()
11 changes: 11 additions & 0 deletions tools/ports/contrib/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Emscripten "Contib" Ports
=========================

Ports in this directory are contributed by the wider community and are
supported on the "best effort" basis. Since they are not run as part of
emscripten CI they are not always guaranteed to build or function.

To using the ports in this directory you must build them using the `embuilder`
command. e.g.:

./embuilder build foo
Empty file added tools/ports/contrib/__init__.py
Empty file.
59 changes: 59 additions & 0 deletions tools/ports/contrib/libarchive.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Copyright 2014 The Emscripten Authors. All rights reserved.
# Emscripten is available under two separate licenses, the MIT license and the
# University of Illinois/NCSA Open Source License. Both these licenses can be
# found in the LICENSE file.

import os
import shutil

TAG = 'version_1'
HASH = '77f7d8f18fe11bb66a57e358325b7422d721f7b506bd63293cfde74079f958864db66ead5a36c311a76dd8c2b089b7659641a5522de650de0f9e6865782a60dd'


def needed(settings):
return True


def get(ports, settings, shared):
ports.fetch_project('libarchive', 'https://github.com/libarchive/libarchive/releases/download/v' + TAG + '/libarchive-' + TAG + '.tar.gz', 'libarchive-' + TAG, sha512hash=HASH)

def create():
ports.clear_project_build('libarchive')

source_path = os.path.join(ports.get_dir(), 'libarchive', 'libarchive-' + TAG)
dest_path = os.path.join(shared.Cache.get_path('ports-builds'), 'libarchive')
shared.try_delete(dest_path)
os.makedirs(dest_path)
shutil.rmtree(dest_path, ignore_errors=True)
shutil.copytree(source_path, dest_path)
ports.install_headers(dest_path)

# build
srcs = 'adler32.c compress.c crc32.c deflate.c gzclose.c gzlib.c gzread.c gzwrite.c infback.c'
'inffast.c inflate.c inftrees.c trees.c uncompr.c zutil.c'.split()
commands = []
o_s = []
for src in srcs:
o = os.path.join(ports.get_build_dir(), 'libarchive', src + '.o')
shared.safe_ensure_dirs(os.path.dirname(o))
commands.append([shared.EMCC, os.path.join(dest_path, src), '-O2', '-o', o, '-I' + dest_path, '-w', '-c'])
o_s.append(o)
ports.run_commands(commands)

final = os.path.join(ports.get_build_dir(), 'libarchive', 'libarchive.a')
ports.create_lib(final, o_s)
return final

return [shared.Cache.get('libarchive.a', create, what='port')]


def clear(ports, settings, shared):
shared.Cache.erase_file('libarchive.a')


def process_args(ports):
return []


def show():
return 'libarchive'