%global branch 24.08
%global version 24.08.6
%global llvm_major 18
%global llvm_version 18.1.8
%global rust_version 1.82.0

# Check for updates with:
#  flatpak remote-info --arch=x86_64 flathub org.freedesktop.Platform//24.08
#  flatpak remote-info --arch=x86_64 flathub org.freedesktop.Sdk//24.08
#  flatpak remote-info --arch=x86_64 flathub org.freedesktop.Sdk.Extension.llvm18//24.08
#  flatpak remote-info --arch=x86_64 flathub org.freedesktop.Sdk.Extension.rust-stable//24.08

%ifarch aarch64
%global platform_commit 60eb612ea76ec9c849643df295cdc353e8aae3d6aee799d834484eb3234cd140
%global sdk_commit fa70dcf88893d9b3644a10ade464f1f91ca99189a81e107aab93327f614954ed
%global llvm_commit 397caa18dc7859e935316eadd8116cb6b541e30e37e7165925021432d8c850a4
%global rust_commit 1a2c9eb81860e8efadd6f01d0da090f1fff3cbbdd9da87cc93f54313ea17f813
%endif

%ifarch x86_64
%global platform_commit 4032cef5b0b698b46df684fc68527252cb7350f39bd90b25bb0c79766911de23
%global sdk_commit c452562271263c5cf32cec693f20a99f77c0771d9a13f607991984e927f0a602
%global llvm_commit b4df7e54e59a4121693c0b2bbdf01f1baff078eaa4f53410124f6fdad69596f7
%global rust_commit 90814be2396ce8bec31982cf0ce8bf9bd9901e02ae6630be602ae80005a8caea
%endif

Name:           fdo-sdk-%{branch}-flatpak
Summary:        Flatpak Freedesktop SDK
Version:        %{version}
Release:        1
License:        MIT AND Apache-2.0 WITH LLVM-exception
URL:            https://freedesktop-sdk.gitlab.io/

BuildRequires:  flatpak

BuildArch:      aarch64 x86_64 %{ix86}

%description
%{summary}.

%package -n fdo-runtime-%{branch}-flatpak
Summary:        Flatpak Freedesktop Runtime

%description -n fdo-runtime-%{branch}-flatpak
%{summary}.

%package -n fdo-sdk-extension-llvm%{llvm_major}-%{branch}-flatpak
Version:        %{llvm_version}
Summary:        Flatpak Freedesktop SDK llvm%{llvm_major} extension

%description -n fdo-sdk-extension-llvm%{llvm_major}-%{branch}-flatpak
%{summary}.

%package -n fdo-sdk-extension-rust-stable-%{branch}-flatpak
Version:        %{rust_version}
Summary:        Flatpak Freedesktop SDK rust-stable extension

%description -n fdo-sdk-extension-rust-stable-%{branch}-flatpak
%{summary}.

%prep
flatpak remote-add --user flathub https://dl.flathub.org/repo/flathub.flatpakrepo
flatpak remote-modify --user --collection-id=org.flathub.Stable flathub

%build
flatpak install --assumeyes --no-deps --no-related --user flathub org.freedesktop.Platform//%{branch}
flatpak update --assumeyes --no-deps --no-related --user --commit=%{platform_commit} org.freedesktop.Platform//%{branch}
flatpak install --assumeyes --no-deps --no-related --user flathub org.freedesktop.Sdk//%{branch}
flatpak update --assumeyes --no-deps --no-related --user --commit=%{sdk_commit} org.freedesktop.Sdk//%{branch}
flatpak install --assumeyes --no-deps --no-related --user flathub org.freedesktop.Sdk.Extension.llvm%{llvm_major}//%{branch}
flatpak update --assumeyes --no-deps --no-related --user --commit=%{llvm_commit} org.freedesktop.Sdk.Extension.llvm%{llvm_major}//%{branch}
flatpak install --assumeyes --no-deps --no-related --user flathub org.freedesktop.Sdk.Extension.rust-stable//%{branch}
flatpak update --assumeyes --no-deps --no-related --user --commit=%{rust_commit} org.freedesktop.Sdk.Extension.rust-stable//%{branch}

%install
mkdir -p %{buildroot}%{_datadir}/flatpak-sideload/{fdo-sdk,fdo-runtime,fdo-sdk-extension-llvm%{llvm_major},fdo-sdk-extension-rust-stable}-%{branch}
flatpak create-usb --user %{buildroot}%{_datadir}/flatpak-sideload/fdo-sdk-%{branch} org.freedesktop.Sdk//%{branch}
flatpak create-usb --user %{buildroot}%{_datadir}/flatpak-sideload/fdo-runtime-%{branch} org.freedesktop.Platform//%{branch}
flatpak create-usb --user %{buildroot}%{_datadir}/flatpak-sideload/fdo-sdk-extension-llvm%{llvm_major}-%{branch} org.freedesktop.Sdk.Extension.llvm%{llvm_major}//%{branch}
flatpak create-usb --user %{buildroot}%{_datadir}/flatpak-sideload/fdo-sdk-extension-rust-stable-%{branch} org.freedesktop.Sdk.Extension.rust-stable//%{branch}

%files
%{_datadir}/flatpak-sideload/fdo-sdk-%branch

%files -n fdo-runtime-%{branch}-flatpak
%{_datadir}/flatpak-sideload/fdo-runtime-%branch

%files -n fdo-sdk-extension-llvm%{llvm_major}-%{branch}-flatpak
%{_datadir}/flatpak-sideload/fdo-sdk-extension-llvm%{llvm_major}-%branch

%files -n fdo-sdk-extension-rust-stable-%{branch}-flatpak
%{_datadir}/flatpak-sideload/fdo-sdk-extension-rust-stable-%branch

%changelog
* Fri Dec 06 2024 Asahi Lina <lina@asahilina.net> - 24.08.6-1
- Add rust-stable extension
- Bump to fdo-sdk 24.08.6

* Wed Sep 25 2024 Janne Grunau <j@jannau.net> - 24.08.2-1
- Update to fdo-sdk 24.08.02

* Mon Jul 15 2024 Hector Martin <marcan@fedoraproject.org> - 23.08.20-1
- Initial release