Skip to content
Open
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
3 changes: 2 additions & 1 deletion cerbero/bootstrap/bootstrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,11 @@ def __new__(klass, config, system, toolchains, build_tools, offline, assume_yes)
return bs


from cerbero.bootstrap import linux, windows, android, osx, ios # noqa: E402
from cerbero.bootstrap import linux, windows, android, osx, ios, emscripten # noqa: E402

linux.register_all()
windows.register_all()
android.register_all()
osx.register_all()
ios.register_all()
emscripten.register_all()
65 changes: 65 additions & 0 deletions cerbero/bootstrap/emscripten.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# cerbero - a multi-platform build system for Open Source software
# Copyright (C) 2024 Fluendo S.A <support@fluendo.com>
# Authors: Maxim Dementyev <mdementyev@fluendo.com>
# Andoni Morales <amorales@fluendo.com>
# Jorge Zapata <jzapata@fluendo.com>
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Library General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Library General Public License for more details.
#
# You should have received a copy of the GNU Library General Public
# License along with this library; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.

from cerbero.bootstrap import BootstrapperBase
from cerbero.bootstrap.bootstrapper import register_toolchain_bootstrapper
from cerbero.enums import Distro
from cerbero.utils import messages as m
from cerbero.utils import shell
import os.path
import shutil


EMSDK_VERSION = '3.1.58'
EMSDK_BUNDLE_EXT = '.tar.gz'
EMSDK_BASE_URL = 'https://github.com/emscripten-core/emsdk/archive/refs/tags/%s' + EMSDK_BUNDLE_EXT
EMSDK_CHECKSUMS = {'3.1.58' + EMSDK_BUNDLE_EXT: '6d860f7ae4bd16bfc18f732200e6608cb2aa739f2ddf9c522755cb0d4037f025'}


class EmscriptenToolchainBootstrapper(BootstrapperBase):
"""
Bootstrapper for Emscripten builds.
Installs the Emscripten SDK
"""

def __init__(self, config, offline, assume_yes):
super().__init__(config, offline)
url = EMSDK_BASE_URL % (EMSDK_VERSION)
bundle_name = 'emsdk-' + EMSDK_VERSION + EMSDK_BUNDLE_EXT
urls = (url, bundle_name, EMSDK_CHECKSUMS[os.path.basename(url)])
self.fetch_urls.append(urls)
self.extract_steps.append((url, True, self.config.home_dir))

async def start(self, jobs=0):
sdk_path_after_extract = os.path.join(self.config.home_dir, 'emsdk-' + EMSDK_VERSION)
shutil.rmtree(self.config.toolchain_prefix) # to be sure it's rename and not a move
shutil.move(sdk_path_after_extract, self.config.toolchain_prefix)
m.message('Install Emscripten SDK...')
await shell.async_call_output(
['./emsdk', 'install', EMSDK_VERSION], cmd_dir=self.config.toolchain_prefix, cpu_bound=False
)
m.message('Activate Emscripten SDK...')
await shell.async_call_output(
['./emsdk', 'activate', EMSDK_VERSION], cmd_dir=self.config.toolchain_prefix, cpu_bound=False
)


def register_all():
register_toolchain_bootstrapper(Distro.EMSCRIPTEN, EmscriptenToolchainBootstrapper)
4 changes: 3 additions & 1 deletion cerbero/build/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,8 @@ class Build(object):

def __init__(self):
self._properties_keys = []
if self.config.target_platform == Platform.WEB:
self.library_type = LibraryType.STATIC

@modify_environment
def get_env(self, var, default=None):
Expand Down Expand Up @@ -948,7 +950,7 @@ def merge_env(old_env, new_env):
binaries['qmake6'] = [self.config.qt6_qmake_path]

# Point meson to rustc with correct arguments to ensure it's detected when cross-compiling
if self.config.cargo_home:
if self.config.variants.rust and self.config.cargo_home:
target_triple = self.config.rust_triple(self.config.target_arch,
self.config.target_platform, self.using_msvc())
binaries['rust'] = [self.config.cargo_home + '/bin/rustc', '--target', target_triple]
Expand Down
5 changes: 4 additions & 1 deletion cerbero/build/filesprovider.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,10 @@ class FilesProvider(object):
Platform.DARWIN: {'bext': '', 'sregex': _DYLIB_REGEX,
'mext': '.so', 'smext': '.a', 'pext': '.so', 'srext': '.dylib'},
Platform.IOS: {'bext': '', 'sregex': _DYLIB_REGEX,
'mext': '.so', 'smext': '.a', 'pext': '.so', 'srext': '.dylib'}}
'mext': '.so', 'smext': '.a', 'pext': '.so', 'srext': '.dylib'},
Platform.WEB: {'bext': '.js', 'sregex': _DYLIB_REGEX,
'mext': '.so', 'smext': '.a', 'pext': '.so', 'srext': '.dylib'},
}

# Match static gstreamer plugins, GIO modules, etc.
_FILES_STATIC_PLUGIN_REGEX = re.compile(r'lib/.+/lib(gst|)([^/.]+)\.a')
Expand Down
5 changes: 5 additions & 0 deletions cerbero/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class Platform:
DARWIN = 'darwin'
ANDROID = 'android'
IOS = 'ios'
WEB = 'web'


class Architecture:
Expand All @@ -43,6 +44,9 @@ class Architecture:
ARMv7 = 'armv7'
ARMv7S = 'armv7s'
ARM64 = 'arm64'
WASM = 'wasm'
WASM32 = 'wasm32'
WASM64 = 'wasm64'

@staticmethod
def is_arm(arch):
Expand Down Expand Up @@ -72,6 +76,7 @@ class Distro:
ANDROID = 'android'
GENTOO = 'gentoo'
NONE = 'none'
EMSCRIPTEN = 'emscripten'


class DistroVersion:
Expand Down
10 changes: 10 additions & 0 deletions config/cross-emscripten-wasm.cbc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# FLUENDO S.A.
# Copyright (C) <2024> <support@fluendo.com>
# Cross-compilation config file for Emscripten WASM.

from cerbero.config import Platform, Architecture, Distro

target_platform = Platform.EMSCRIPTEN
target_distro = Distro.EMSCRIPTEN
target_distro_version = None
target_arch = Architecture.WASM
10 changes: 10 additions & 0 deletions config/cross-web-emscripten-wasm32.cbc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# FLUENDO S.A.
# Copyright (C) <2024> <support@fluendo.com>
# Cross-compilation config file for Emscripten WASM 32 bits.

from cerbero.config import Platform, Architecture, Distro

target_platform = Platform.WEB
target_distro = Distro.EMSCRIPTEN
target_distro_version = None
target_arch = Architecture.WASM32
10 changes: 10 additions & 0 deletions config/cross-web-emscripten-wasm64.cbc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# FLUENDO S.A.
# Copyright (C) <2024> <support@fluendo.com>
# Cross-compilation config file for Emscripten WASM 64 bits.

from cerbero.config import Platform, Architecture, Distro

target_platform = Platform.WEB
target_distro = Distro.EMSCRIPTEN
target_distro_version = None
target_arch = Architecture.WASM64
43 changes: 43 additions & 0 deletions config/emscripten.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# FLUENDO S.A.
# Copyright (C) <2024> <support@fluendo.com>
# Platform config file for Emscripten.

import os
import os.path

# These variants are enabled by default, but not available on our platform
variants.rust = False
variants.mingw = False

# unfortunately, variants.rust = False is not enough, there is no check to use cargo
# in "cerbero/build/build.py", _get_meson_target_file_contents()
#cargo_home = None

if not toolchain_prefix:
# the bundle contains 'emsdk-X.Y.Z' as a root folder
# we need to unify it, because have no that info on config level
toolchain_prefix = os.path.join(home_dir, "emsdk")

# after emsdk activate, we've got .emscripten config file
dot_emscripten_config = os.path.join(toolchain_prefix, '.emscripten')
if os.path.exists(dot_emscripten_config):
# after execution, this config file defines:
# BINARYEN_ROOT, EMSCRIPTEN_ROOT, LLVM_ROOT, NODE_JS
os.environ['EM_CONFIG'] = dot_emscripten_config
exec(open(dot_emscripten_config).read(), globals())

# emconfigure and emmake prepare the environment for build,
# see get_building_env() from emsdk/upstream/emscripten/tools/building.py
# that is used in those wrappers.
var_path_execs = (
('CC', EMSCRIPTEN_ROOT, 'emcc'),
('CXX', EMSCRIPTEN_ROOT, 'em++'),
('AR', EMSCRIPTEN_ROOT, 'emar'),
('LD', EMSCRIPTEN_ROOT, 'emcc'),
('NM', LLVM_ROOT, 'llvm-nm'),
('LDSHARED', EMSCRIPTEN_ROOT, 'emcc'),
('RANLIB', EMSCRIPTEN_ROOT, 'emranlib'),
)

for var,path,exe in var_path_execs:
env[var] = path + '/' + exe
41 changes: 41 additions & 0 deletions config/web.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# FLUENDO S.A.
# Copyright (C) <2024> <support@fluendo.com>
# Platform config file for the Web platform.
# It contains sensitive enviroment configuration that
# shouldn't be modified unless you know what you are doing.
# PLEASE, DO NOT EDIT THIS FILE

import os
import os.path
from cerbero.config import Distro, FatalError
from cerbero.utils import EnvValueCmd

if target_distro != Distro.EMSCRIPTEN:
raise FatalError('EMSCRIPTEN is the only Distro supported for the WEB platform')

# These variants are enabled by default, but not available on our platform
variants.rust = False

if not toolchain_prefix:
toolchain_prefix = os.path.join(home_dir, "emsdk")

dot_emscripten_config = os.path.join(toolchain_prefix, '.emscripten')
# This file might be missing if we are bootstrapping
if os.path.exists(dot_emscripten_config):
# Parse the .emscripten config file to fetch the installed
# sdk enviroment.
# after execution, this config file defines:
# BINARYEN_ROOT, EMSCRIPTEN_ROOT, LLVM_ROOT, NODE_JS
os.environ['EM_CONFIG'] = dot_emscripten_config
exec(open(dot_emscripten_config).read(), globals())

def add_cmd(var, prefix, command):
env[var] = os.path.join(prefix, command)

add_cmd('CC', EMSCRIPTEN_ROOT, 'emcc')
add_cmd('CXX', EMSCRIPTEN_ROOT, 'em++')
add_cmd('AR', EMSCRIPTEN_ROOT, 'emar')
add_cmd('LD', EMSCRIPTEN_ROOT, 'emcc')
add_cmd('NM', LLVM_ROOT, 'llvm-nm')
add_cmd('LDSHARED', EMSCRIPTEN_ROOT, 'emcc'),
add_cmd('RANLIB', EMSCRIPTEN_ROOT, 'emranlib')