[vlc-commits] [Git][videolan/vlc][master] 11 commits: apple: build.sh: export the fact we're building for a simulator

Steve Lhomme (@robUx4) gitlab at videolan.org
Tue Jul 23 06:50:58 UTC 2024



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
ac46208b by Steve Lhomme at 2024-07-23T06:12:29+00:00
apple: build.sh: export the fact we're building for a simulator

- - - - -
1919b8c7 by Steve Lhomme at 2024-07-23T06:12:29+00:00
contrib: recognize the Darwin simualator platforms

- - - - -
b045e846 by Denis Charmet at 2024-07-23T06:12:29+00:00
contrib: add a shell script to turn compilation triplet into Rust target

Co-authored-by: Steve Lhomme <robux4 at ycbcr.xyz>

- - - - -
46dd97a6 by Steve Lhomme at 2024-07-23T06:12:29+00:00
contrib: rust: use the shell script to get the Rust target

- - - - -
40a52d9b by Steve Lhomme at 2024-07-23T06:12:29+00:00
contrib: rust: get the Rust target for native compiler

If for some reason we don't have a proper value, we don't have a usable value,
we cannot compile native rust code nor install the cross-compiler.

- - - - -
ab494f2c by Steve Lhomme at 2024-07-23T06:12:29+00:00
contrib: rustc: use the RUST_HOST target to check for native compilation

It may be configured to default to another target.

We need to check the RUST_HOST is supported because rustc returns a version
even if the --target doesn't match a known target. Maybe in the future it will.

- - - - -
176813db by Steve Lhomme at 2024-07-23T06:12:29+00:00
contrib: rustc: detect a system Rust cross compiler with the proper RUST_TARGET

- - - - -
1b8a1f9c by Steve Lhomme at 2024-07-23T06:12:29+00:00
contrib: rust: add CARGO call to build native tools

The C compiler and native tools should be the BUILDxxx ones.
The RUSTFLAGS are not needed, especially the target platform specific ones.

- - - - -
ac5a8d72 by Steve Lhomme at 2024-07-23T06:12:29+00:00
contrib: cargo-c: build with the cargo targetting the native target

cargo-capi is a native tool.

- - - - -
2f29e7e8 by Steve Lhomme at 2024-07-23T06:12:29+00:00
contrib: cargo-c: build as a regular contrib

PKGS_TOOLS are native tools that are used by VLC so they are rebuilt
when using prebuilt contribs.

cargo capi is only used to build rav1e, it's not needed when using prebuilt contribs.

This may be reverted if we ever want to use cargo capi in VLC.

- - - - -
aeb91ea4 by Steve Lhomme at 2024-07-23T06:12:29+00:00
contrib: rav1e: always use the native cargo/Rust compiler for vendoring

There should be no difference:

- the vendor system is meant to pick the source needed to rebuild the package
  for all targets, it doesn't require a target, in fact there is no "--target" option.
- someone even made a tool to do vendoring for a specific target:
  https://users.rust-lang.org/t/is-it-possible-to-vendor-dependencies-only-for-a-given-target/90261/2
- before and after the patch the rav1e-vendor-build folder is the same
- using CARGO_NATIVE on Linux I still get a ton of windows packages in the
  rav1e-vendor folder

It may start a little faster while the cross compiler is being downloaded.

- - - - -


7 changed files:

- contrib/bootstrap
- contrib/src/cargo-c/rules.mak
- + contrib/src/get-rust-target.sh
- contrib/src/main-rust.mak
- contrib/src/rav1e/rules.mak
- contrib/src/rustc/rules.mak
- extras/package/apple/build.sh


Changes:

=====================================
contrib/bootstrap
=====================================
@@ -296,6 +296,10 @@ case "${OS}" in
 		then
 			add_make_enabled "HAVE_BITCODE_ENABLED"
 		fi
+		if test "$BUILDFORSIMULATOR"
+		then
+			add_make_enabled "HAVE_SIMULATOR"
+		fi
 		;;
 	*bsd*)
 		MAKE=gmake


=====================================
contrib/src/cargo-c/rules.mak
=====================================
@@ -3,7 +3,7 @@
 CARGOC_VERSION := 0.9.29
 
 ifdef BUILD_RUST
-PKGS_TOOLS += cargo-c
+# PKGS_TOOLS += cargo-c
 
 ifneq ($(call system_tool_majmin, cargo-capi --version),)
 PKGS_FOUND += cargo-c
@@ -11,11 +11,7 @@ endif
 
 endif
 
-ifdef HAVE_CROSS_COMPILE
-DEPS_cargo-c = rustc-cross $(DEPS_rustc-cross)
-else
 DEPS_cargo-c = rustc $(DEPS_rustc)
-endif
 
 .sum-cargo-c:
 	touch $@
@@ -32,5 +28,5 @@ endif
 
 .cargo-c:
 	+unset PKG_CONFIG_LIBDIR PKG_CONFIG_PATH CFLAGS CPPFLAGS LDFLAGS; \
-		$(CARGO) install --locked $(CARGOC_FEATURES) cargo-c --version $(CARGOC_VERSION)
+		$(CARGO_NATIVE) install --target=$(RUST_HOST) --locked $(CARGOC_FEATURES) cargo-c --version $(CARGOC_VERSION)
 	touch $@


=====================================
contrib/src/get-rust-target.sh
=====================================
@@ -0,0 +1,215 @@
+#!/bin/sh
+# SPDX-License-Identifier: ISC
+# Copyright (C) 2024 VideoLabs, VLC authors and VideoLAN
+#
+# Authors: Denis Charmet <typx at dinauz.org>
+#          Steve Lhomme <robux4 at videolabs.io>
+#
+# Transform a compilation triplet into a Rust Tier 1 and Tier 2 target
+# based on https://doc.rust-lang.org/rustc/platform-support.html
+
+DARWIN=
+ARCH=
+OS=
+UWP=
+UCRT=
+SIMULATOR=
+TRIPLET=
+
+abort_err()
+{
+    echo "ERROR: $1" >&2
+    exit 1
+}
+
+return_triplet()
+{
+  echo "$1"
+  exit 0
+}
+
+validate_darwin()
+{
+  D=$(echo $1 | cut -f2 -d"=")
+  case $D in
+    macos)
+      DARWIN=macos
+      ;;
+    ios)
+      DARWIN=ios
+      ;;
+    tvos)
+      DARWIN=tvos
+      ;;
+    watchos)
+      DARWIN=watchos
+      ;;
+    xros)
+      DARWIN=xros
+      ;;
+    *)
+      abort_err "Unsupported Darwin variant '$D'"
+      ;;
+  esac
+}
+
+validate_triplet()
+{
+  TRIPLET=$1
+  ARCH=$(echo $1 | cut -f 1 -d '-')
+  UNUSED=$(echo $1 | cut -f 2 -d '-')
+  OS=$(echo $1 | cut -f 3 -d '-')
+  REST=$(echo $1 | cut -f 4 -d '-')
+
+  if test ! -z "$REST"; then
+    OS=$REST
+  fi
+  if test -z "$ARCH" || test -z "$UNUSED" || test -z "$OS"; then
+    abort_err "Unsupported triplet '$1'"
+  fi
+}
+
+print_usage()
+{
+    echo "Usage: $0 [--ucrt] [--uwp] [--darwin {macos,ios,tvos,watchos,xros}] [--simulator] triplet"
+}
+
+
+for ARG in "$@"; do
+  case $ARG in
+    --uwp)
+      UWP=1
+      ;;
+    --ucrt)
+      UCRT=1
+      ;;
+    --simulator)
+      SIMULATOR=1
+      ;;
+    --darwin=*)
+      validate_darwin $ARG
+      ;;
+    *-*-*)
+      validate_triplet $ARG
+      break
+      ;;
+    *)
+      print_usage
+      abort_err "Unknown parameter $ARG"
+      ;;
+  esac
+done
+
+case $OS in
+  mingw32|mingw32ucrt|mingw32uwp)
+    if test ! -z "$UWP"; then
+      abort_err "UWP Windows is Tier 3"
+    fi
+    if test ! -z "$UCRT"; then
+      return_triplet $ARCH-pc-windows-gnullvm
+    else
+      return_triplet $ARCH-pc-windows-gnu
+    fi
+    ;;
+
+  android)
+    case $ARCH in
+      aarch64|i686|x86_64)
+        return_triplet $TRIPLET
+        ;;
+    esac
+    ;;
+
+  androideabi)
+    case $ARCH in
+      arm|armv7|thumbv7neon)
+        return_triplet $TRIPLET
+        ;;
+    esac
+    ;;
+
+  darwin*)
+    case $DARWIN in
+      macos)
+        case $ARCH in
+          aarch64|arm64)
+            return_triplet aarch64-apple-darwin
+            ;;
+          x86_64)
+            return_triplet x86_64-apple-darwin
+            ;;
+        esac
+        ;;
+
+      ios)
+        if test ! -z "$SIMULATOR"; then
+          case $ARCH in
+            aarch64|arm64)
+              return_triplet aarch64-apple-ios-sim
+              ;;
+          esac
+        else
+          case $ARCH in
+            aarch64|arm64)
+              return_triplet aarch64-apple-ios
+              ;;
+            x86_64)
+              return_triplet x86_64-apple-ios
+              ;;
+          esac
+        fi
+        ;;
+
+    esac
+    abort_err "Unsupported Darwin triplet '$TRIPLET' for '$DARWIN'"
+    ;;
+
+  gnueabihf)
+    case $ARCH in
+      arm|armv7|thumbv7neon)
+        return_triplet $ARCH-unknown-linux-gnueabihf
+        ;;
+    esac
+    ;;
+
+  gnu)
+    case $ARCH in
+      riscv64)
+        return_triplet riscv64gc-unknown-linux-gnu
+        ;;
+      x86_64|aarch64|i686|loongarch64|powerpc|powerpc64|powerpcle|s390x|i586|sparc64)
+        return_triplet $ARCH-unknown-linux-gnu
+        ;;
+    esac
+    ;;
+
+  netbsd)
+    case $ARCH in
+      x86_64)
+        return_triplet x86_64-unknown-netbsd
+        ;;
+    esac
+    ;;
+
+  freebsd)
+    case $ARCH in
+      x86_64)
+        return_triplet x86_64-unknown-freebsd
+        ;;
+    esac
+    ;;
+
+  emscripten)
+    case $ARCH in
+      wasm32)
+        return_triplet wasm32-unknown-emscripten
+        ;;
+    esac
+    ;;
+
+  *)
+    abort_err "Unknown OS '$OS'"
+    ;;
+esac
+
+abort_err "Unsupported triplet '$TRIPLET'"


=====================================
contrib/src/main-rust.mak
=====================================
@@ -7,64 +7,46 @@
 RUST_VERSION_MIN=1.63.0
 
 ifdef HAVE_WIN32
+ifdef HAVE_WINSTORE
+RUST_TARGET_FLAGS += --uwp
+endif
 ifdef HAVE_UCRT
 # does not work as Tier 2 before that
 RUST_VERSION_MIN=1.79.0
-
-ifndef HAVE_WINSTORE # UWP is available as Tier 3
-ifeq ($(HOST),i686-w64-mingw32)
-RUST_TARGET = i686-pc-windows-gnullvm # ARCH is i386
-else ifneq ($(HOST),armv7-w64-mingw32)
-# Not supported on armv7
-RUST_TARGET = $(ARCH)-pc-windows-gnullvm
-endif # archs
-endif # WINSTORE
-else # MSVCRT
-ifeq ($(HOST),i686-w64-mingw32)
-RUST_TARGET = i686-pc-windows-gnu # ARCH is i386
-else ifeq ($(HOST),x86_64-w64-mingw32)
-RUST_TARGET = $(ARCH)-pc-windows-gnu
-else
-# Not supported on armv7/aarch64 yet
-endif # archs
-endif # MSVCRT
-else ifdef HAVE_ANDROID
-RUST_TARGET = $(HOST)
-else ifdef HAVE_IOS
-ifneq ($(ARCH),arm) # iOS 32bit is Tier 3
-ifneq ($(ARCH),i386) # iOS 32bit is Tier 3
-ifndef HAVE_TVOS # tvOS is Tier 3
-RUST_TARGET = $(ARCH)-apple-ios
-endif
+RUST_TARGET_FLAGS += --ucrt
 endif
 endif
-else ifdef HAVE_MACOSX
-RUST_TARGET = $(ARCH)-apple-darwin
-# else ifdef HAVE_SOLARIS
-# Solaris x86_64 is Tier 3
-# RUST_TARGET = x86_64-sun-solaris
-else ifdef HAVE_LINUX
-ifeq ($(HOST),arm-linux-gnueabihf)
-RUST_TARGET = arm-unknown-linux-gnueabihf #add eabihf
-else
-ifeq ($(HOST),riscv64-linux-gnu)
-RUST_TARGET = riscv64gc-unknown-linux-gnu
+
+ifdef HAVE_DARWIN_OS
+ifdef HAVE_TVOS
+RUST_TARGET_FLAGS += --darwin=tvos
+else ifdef HAVE_WATCHOS
+RUST_TARGET_FLAGS += --darwin=watchos
+else ifdef HAVE_IOS
+RUST_TARGET_FLAGS += --darwin=ios
 else
-RUST_TARGET = $(ARCH)-unknown-linux-gnu
+RUST_TARGET_FLAGS += --darwin=macos
+endif
+ifdef HAVE_SIMULATOR
+RUST_TARGET_FLAGS += --simulator
 endif
 endif
-else ifdef HAVE_BSD
-RUST_TARGET = $(HOST)
-else ifdef HAVE_EMSCRIPTEN
-RUST_TARGET = $(HOST)
+
+ifneq ($(findstring darwin,$(BUILD)),)
+RUST_BUILD_FLAGS += --darwin=macos
 endif
 
+RUST_TARGET := $(shell $(SRC)/get-rust-target.sh $(RUST_TARGET_FLAGS) $(HOST) 2>/dev/null || echo FAIL)
+RUST_HOST :=  $(shell $(SRC)/get-rust-target.sh $(RUST_BUILD_FLAGS) $(BUILD) 2>/dev/null || echo FAIL)
+
+ifneq ($(RUST_HOST),FAIL)
 # For now, VLC don't support Tier 3 platforms (ios 32bit, tvOS).
 # Supporting a Tier 3 platform means building an untested rust toolchain.
 # TODO Let's hope tvOS move from Tier 3 to Tier 2 before the VLC 4.0 release.
-ifneq ($(RUST_TARGET),)
+ifneq ($(RUST_TARGET),FAIL)
 BUILD_RUST="1"
 endif
+endif
 
 RUSTUP_HOME= $(BUILDBINDIR)/.rustup
 CARGO_HOME = $(BUILDBINDIR)/.cargo
@@ -84,12 +66,17 @@ endif
 
 CARGO_ENV = TARGET_CC="$(CC)" TARGET_AR="$(AR)" TARGET_RANLIB="$(RANLIB)" \
 	TARGET_CFLAGS="$(CFLAGS)" RUSTFLAGS="$(RUSTFLAGS)"
+CARGO_ENV_NATIVE = TARGET_CC="$(BUILDCC)" TARGET_AR="$(BUILDAR)" TARGET_RANLIB="$(BUILDRANLIB)" \
+	TARGET_CFLAGS="$(BUILDCFLAGS)"
 
 ifneq ($(call system_tool_majmin, cargo --version),)
 CARGO = RUSTUP_HOME=$(RUSTUP_HOME) CARGO_HOME=$(CARGO_HOME) $(CARGO_ENV) cargo
+CARGO_NATIVE = RUSTUP_HOME=$(RUSTUP_HOME) CARGO_HOME=$(CARGO_HOME) $(CARGO_ENV_NATIVE) cargo
 else
 CARGO = . $(CARGO_HOME)/env && \
         RUSTUP_HOME=$(RUSTUP_HOME) CARGO_HOME=$(CARGO_HOME) $(CARGO_ENV) cargo
+CARGO_NATIVE = . $(CARGO_HOME)/env && \
+        RUSTUP_HOME=$(RUSTUP_HOME) CARGO_HOME=$(CARGO_HOME) $(CARGO_ENV_NATIVE) cargo
 endif
 
 CARGO_INSTALL_ARGS = --target=$(RUST_TARGET) --prefix=$(PREFIX) \


=====================================
contrib/src/rav1e/rules.mak
=====================================
@@ -23,12 +23,11 @@ RAV1E_FEATURES=--features=asm
 
 # we may not need cargo if the tarball is downloaded, but it will be needed by rav1e anyway
 ifdef HAVE_CROSS_COMPILE
-DEPS_rav1e-vendor = rustc-cross $(DEPS_rustc-cross)
 DEPS_rav1e = rustc-cross $(DEPS_rustc-cross)
 else
-DEPS_rav1e-vendor = rustc $(DEPS_rustc)
 DEPS_rav1e = rustc $(DEPS_rustc)
 endif
+DEPS_rav1e-vendor = rustc $(DEPS_rustc)
 DEPS_rav1e += rav1e-vendor $(DEPS_rav1e-vendor) cargo-c $(DEPS_cargo-c)
 
 # rav1e-vendor
@@ -37,7 +36,7 @@ rav1e-vendor-build:
 	$(RM) -R $@
 	mkdir -p $@
 	tar xzfo $(TARBALLS)/rav1e-$(RAV1E_VERSION).tar.gz -C $@ --strip-components=1
-	cd $@ && $(CARGO) vendor --locked rav1e-$(RAV1E_VERSION)-vendor
+	cd $@ && $(CARGO_NATIVE) vendor --locked rav1e-$(RAV1E_VERSION)-vendor
 	cd $@ && tar -jcf rav1e-$(RAV1E_VERSION)-vendor.tar.bz2 rav1e-$(RAV1E_VERSION)-vendor
 	install $@/rav1e-$(RAV1E_VERSION)-vendor.tar.bz2 "$(TARBALLS)"
 	# cd $@ && sha512sum rav1e-$(RAV1E_VERSION)-vendor.tar.bz2 > SHA512SUMS


=====================================
contrib/src/rustc/rules.mak
=====================================
@@ -17,13 +17,14 @@ RUSTUP = . $(CARGO_HOME)/env && \
          RUSTUP_HOME=$(RUSTUP_HOME) CARGO_HOME=$(CARGO_HOME) rustup
 endif
 
-ifeq ($(call system_tool_matches_min, cargo --version,$(RUST_VERSION_MIN)),)
+ifeq ($(call system_tool_matches_min, echo 'fn main() {}' | rustc --target=$(RUST_HOST) --emit=dep-info - -o /dev/null 2>/dev/null && rustc --target=$(RUST_HOST) --version,$(RUST_VERSION_MIN)),)
 PKGS_FOUND += rustc
-# TODO detect if the target is available
-# PKGS_FOUND += rustc-cross
 else
 DEPS_rustc = rustup $(DEPS_rustup)
 endif
+ifeq ($(call system_tool_matches_min, echo 'fn main() {}' | rustc --target=$(RUST_TARGET) --emit=dep-info - -o /dev/null 2>/dev/null && rustc --target=$(RUST_TARGET) --version,$(RUST_VERSION_MIN)),)
+PKGS_FOUND += rustc-cross
+endif
 
 endif
 


=====================================
extras/package/apple/build.sh
=====================================
@@ -637,6 +637,9 @@ elif [ "$VLC_HOST_OS" = "watchos" ]; then
     export BUILDFORIOS="yes"
     export BUILDFORWATCHOS="yes"
 fi
+if [ "$VLC_HOST_PLATFORM_SIMULATOR" = "yes" ]; then
+    export BUILDFORSIMULATOR="yes"
+fi
 
 # Default to "make" if there is no MAKE env variable
 MAKE=${MAKE:-make}



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/47da1c719b071e9bdf9ba2c8180ab1c471d653b2...aeb91ea481edf4fd7bd7252bee8aff6b963959e0

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/47da1c719b071e9bdf9ba2c8180ab1c471d653b2...aeb91ea481edf4fd7bd7252bee8aff6b963959e0
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list