summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorL. E. Segovia <amy@centricular.com>2024-07-09 21:19:37 -0300
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>2024-10-22 18:33:54 +0000
commit39a7a0184c1f4b47c97ffe70e9d7d5e9db6c5da9 (patch)
tree949a9ad18c98c8dde880d2794ac0f713c005b177
parent924cca6ffebf60d4ae1175e2a5eedcc7a9832a0c (diff)
rust: Enable MinGW ABI
Part-of: <https://gitlab.freedesktop.org/gstreamer/cerbero/-/merge_requests/1583>
-rw-r--r--cerbero/bootstrap/rust.py25
-rw-r--r--cerbero/build/build.py13
-rw-r--r--config/windows.config13
-rw-r--r--recipes/gst-plugins-rs.recipe12
-rw-r--r--recipes/librsvg.recipe8
5 files changed, 58 insertions, 13 deletions
diff --git a/cerbero/bootstrap/rust.py b/cerbero/bootstrap/rust.py
index 58b5d365..dfe598cc 100644
--- a/cerbero/bootstrap/rust.py
+++ b/cerbero/bootstrap/rust.py
@@ -81,18 +81,21 @@ class RustBootstrapper(BootstrapperBase):
self.build_triple = self.config.rust_build_triple
self.target_triples = self.config.rust_target_triples
if self.config.platform == Platform.WINDOWS:
- # On Windows, build-tools always use MSVC so we need to always
- # bootstrap $arch-windows-msvc
- bs_triple = self.config.rust_triple(self.config.arch, self.config.platform, True)
- if bs_triple not in self.target_triples:
- self.target_triples.append(bs_triple)
+ tgt = set(self.target_triples)
+ # On Windows, build tools must be built using MSVC. However,
+ # the current variant determines the default target.
+ # So we need to always bootstrap $arch-windows-msvc,
+ # and override the build triple accordingly
+ self.build_triple = self.config.rust_triple(self.config.arch, self.config.platform, True)
+ tgt.add(self.build_triple)
# rustup-init wants to always install both 64-bit and 32-bit
# toolchains, so ensure that we fetch and install both
archs = {Architecture.X86_64, Architecture.X86}
other_arch = (archs - {self.config.arch}).pop()
- arch_triple = self.config.rust_triple(other_arch, self.config.platform, self.config.variants.visualstudio)
- if arch_triple not in self.target_triples:
- self.target_triples.append(arch_triple)
+ # in both MSVC and MinGW ABIs
+ tgt.add(self.config.rust_triple(other_arch, self.config.platform, True))
+ tgt.add(self.config.rust_triple(other_arch, self.config.platform, False))
+ self.target_triples = list(tgt)
self.fetch_urls = self.get_fetch_urls()
self.fetch_urls_func = self.get_more_fetch_urls
self.extract_steps = []
@@ -179,11 +182,15 @@ class RustBootstrapper(BootstrapperBase):
entry = channel_data['pkg'][c]['target'][self.build_triple]
urls += list(get_entry_urls(entry))
- # And then maybe also rust-std for the target machine
+ # Then maybe also rust-std for the target machine
for triple in self.target_triples:
if triple != self.build_triple:
entry = channel_data['pkg']['rust-std']['target'][triple]
urls += list(get_entry_urls(entry))
+ # And rust-mingw for any MinGW targets
+ if 'windows-gnu' in triple:
+ entry = channel_data['pkg']['rust-mingw']['target'][triple]
+ urls += list(get_entry_urls(entry))
return (urls, self.install_toolchain_for_cargoc_fetch)
diff --git a/cerbero/build/build.py b/cerbero/build/build.py
index 1c7dd742..8c0513db 100644
--- a/cerbero/build/build.py
+++ b/cerbero/build/build.py
@@ -1369,6 +1369,19 @@ class CargoC(Cargo):
def __init__(self):
Cargo.__init__(self)
+ # cargo-c ignores config.toml's rustflags, which are necessary for i386
+ # cross-build
+ self.target_triple = self.config.rust_triple(
+ self.config.target_arch, self.config.target_platform, self.using_msvc()
+ )
+ if self.target_triple == 'i686-pc-windows-gnu':
+ tgt = self.target_triple.upper().replace('-', '_')
+ self.set_env(f'CARGO_TARGET_{tgt}_LINKER', self.get_env('RUSTC_LINKER'))
+ link_args = []
+ for arg in shlex.split(self.get_env('RUSTC_LDFLAGS')):
+ link_args += ['-C', f'link-arg={arg}']
+ self.set_env('RUSTFLAGS', ' '.join(link_args))
+
def get_cargoc_args(self):
cargoc_args = [
'--release',
diff --git a/config/windows.config b/config/windows.config
index f15d5f2c..ad68b146 100644
--- a/config/windows.config
+++ b/config/windows.config
@@ -6,9 +6,12 @@
from cerbero.config import Architecture, Platform, Distro, FatalError
from cerbero.utils import EnvValue, EnvValueArg, EnvValueCmd, EnvValuePath
-# Enable rust support by default only when building with MSVC
-# https://gitlab.freedesktop.org/gstreamer/cerbero/-/issues/381
-if not variants.mingw and not variants.uwp:
+# MinGW x86 requires changing GCC's exception model to DWARF2
+# See https://fedoraproject.org/wiki/Changes/Mingw32GccDwarf2
+mingw_incompatible_sjlj = variants.mingw and target_arch == Architecture.X86
+
+# Tracking bug: https://gitlab.freedesktop.org/gstreamer/cerbero/-/issues/381
+if not variants.uwp and not mingw_incompatible_sjlj:
variants.override('rust', False)
# We don't want anything from mingw or msys detected in configure and
@@ -146,6 +149,10 @@ msvc_env_for_build_system['CC'] = EnvValueCmd('cl')
msvc_env_for_build_system['CXX'] = EnvValueCmd('cl')
msvc_env_for_build_system['AR'] = EnvValueCmd('lib')
+# Rust
+mingw_env_for_toolchain['RUSTC_LDFLAGS'] = EnvValueArg(arch_flags + [f'-Wl,-m,i386pe'])
+mingw_env_for_toolchain['RUSTC_LINKER'] = cmd('gcc')
+
# MinGW toolchain config env
mingw_env_for_toolchain['LIBRARY_PATH'] = EnvValuePath([lib_dir])
diff --git a/recipes/gst-plugins-rs.recipe b/recipes/gst-plugins-rs.recipe
index 91f7f385..2ecc0150 100644
--- a/recipes/gst-plugins-rs.recipe
+++ b/recipes/gst-plugins-rs.recipe
@@ -5,6 +5,7 @@ from cerbero.utils import messages as m
from cerbero.utils import shell, determine_num_cargo_jobs, determine_total_ram
from pathlib import Path
import re
+import shlex
import shutil
import tempfile
@@ -137,6 +138,17 @@ class Recipe(recipe.Recipe):
self.cargo_features.append(f'gst{each}/v1_22')
self.cargo_features.append('gst-plugin-webrtc/v1_22')
+ # The LIBRARY_PATH setting affects all invocations of GCC underneath
+ # Cargo, in particular those that link build scripts (that are meant to
+ # run on the host machine, not through wine).
+ # When creating these, a value for LIBRARY_PATH present will cause
+ # cross-mingw GCC to prefer libpthread.a for MinGW-w64 over the system
+ # libpthread, and hell breaks loose.
+ if self.config.target_platform == Platform.WINDOWS and \
+ self.config.platform != self.config.target_platform:
+ self.set_env('LDFLAGS')
+ self.set_env('LIBRARY_PATH')
+
async def configure(self):
# Check that the Cargo.toml version matches the recipe version
toml_version = self.get_cargo_toml_version()
diff --git a/recipes/librsvg.recipe b/recipes/librsvg.recipe
index 7b450d63..6ac9cc11 100644
--- a/recipes/librsvg.recipe
+++ b/recipes/librsvg.recipe
@@ -70,6 +70,10 @@ class Recipe(recipe.Recipe):
# Cargo tries to look up an import lib when LibraryType.BOTH
# librsvg only generates the shared library
self.library_type = LibraryType.SHARED
+ # GCC willfully obeys LIBRARY_PATH
+ if self.config.platform != self.config.target_platform:
+ self.set_env('LDFLAGS')
+ self.set_env('LIBRARY_PATH')
self.target_triple = self.config.rust_triple(self.config.target_arch,
self.config.target_platform, self.using_msvc())
self.meson_options['triplet'] = self.target_triple
@@ -88,6 +92,7 @@ class Recipe(recipe.Recipe):
s = '[build]\n' \
f'target = "{self.target_triple}"\n'
self.append_config_toml(s)
+
if self.config.target_platform == Platform.ANDROID:
# Use the compiler's forwarding
# See https://android.googlesource.com/platform/ndk/+/master/docs/BuildSystemMaintainers.md#linkers
@@ -95,7 +100,7 @@ class Recipe(recipe.Recipe):
link_args = []
# We need to extract necessary linker flags from LDFLAGS which is
# passed to the compiler
- for arg in shlex.split(self.get_env('LDFLAGS', '')):
+ for arg in shlex.split(self.get_env('RUSTC_LDFLAGS', self.get_env('LDFLAGS'))):
link_args += ['-C', f"link-arg={arg}"]
s = f'[target.{self.target_triple}]\n' \
f'linker = "{linker}"\n' \
@@ -111,6 +116,7 @@ class Recipe(recipe.Recipe):
for p in path:
if msys2_prefix in p:
self.remove_env('PATH', p, sep=os.pathsep)
+
await super().configure()
async def compile(self):