%global branch 23.08
%global version 23.08.25
%global llvm_major 18
%global llvm_version 18.1.8
%global rust_version 1.81.0

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

%ifarch aarch64
%global platform_commit 40e758c058b2db4d6d2a59bb20d67d92dfd203bd81abe5f119fb4d9e7a7489ab
%global sdk_commit 5af29d047f2c84e61a51a37515f9d0e374a914bad6d8c5b0258150e54b897030
%global llvm_commit 72da52d1f552e891f087005dd79ef864811a5a06df566d6cd0e59947abf01651
%global rust_commit ab0633847188bbd94c500c7240194ea22c47cde1f5e1b88d7833eb463e8e8936
%endif

%ifarch x86_64
%global platform_commit 0a3508e2e09c748e207965e0c0e25a52e6ae77716230be986cbbfb4b29295eb5
%global sdk_commit afab9552793880cc9b2adc9019ee89031d7c7c2dca87c7e0e94923e6fe3e1339
%global llvm_commit 5311e43c5398b2ce50a935c761693faf80d0079afb2232b9fbc00a1138215a38
%global rust_commit 81caf9b122cf28c012ba390c40c68b5f89568951aab748383f92c86000e5d2a4
%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> - 23.08.25-1
- Add rust-stable extension
- Bump to fdo-sdk 23.08.25

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