<Project Sdk="Microsoft.NET.Sdk">

    <PropertyGroup>
        <OutputType>Library</OutputType>
        <PackageId>Microsoft.Regorus</PackageId>
        <RootNamespace>Microsoft.Regorus</RootNamespace>
        <TargetFrameworks>netstandard2.0;netstandard2.1</TargetFrameworks>
        <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
       <LangVersion>10.0</LangVersion>

        <!-- See https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-pack -->
        <VersionPrefix>$(RegorusPackageVersion)</VersionPrefix>
        <VersionSuffix>$(VersionSuffix)</VersionSuffix>
        <PackageReadmeFile>README.md</PackageReadmeFile>
        <PackageLicenseExpression>MIT AND Apache-2.0 AND BSD-3-Clause</PackageLicenseExpression>
        <PackageProjectUrl>https://github.com/microsoft/regorus</PackageProjectUrl>
        <RepositoryUrl>https://github.com/microsoft/regorus</RepositoryUrl>
        <RepositoryType>git</RepositoryType>
        <Authors>Microsoft</Authors>
        <Company>Microsoft</Company>
        <PackageTags>rego;policy;engine;authorization;opa;rust</PackageTags>
        <Description>Fast, lightweight Rego interpreter and policy engine for .NET, powered by Rust.</Description>
        <Copyright>Copyright (c) Microsoft Corporation.</Copyright>
    </PropertyGroup>

    <PropertyGroup>
        <RegorusFFIArtifactsProfile Condition="'$(RegorusFFIArtifactsProfile)' == ''">release</RegorusFFIArtifactsProfile>
    </PropertyGroup>

    <ItemGroup>
        <PackageReference Include="System.Text.Json" />
    </ItemGroup>

    <PropertyGroup Condition="'$(EnableRegorusTestHooks)' == 'true'">
        <DefineConstants>$(DefineConstants);REGORUS_FFI_TEST_HOOKS</DefineConstants>
    </PropertyGroup>

    <!--
        $(RegorusFFIArtifactsDir) is the location where regorus shared libraries have been
        built for various platforms and copied to. RegorusFFIArtifactsDir is passed in
        by the publishing pipeline.

        For each target triple, `Pack` expects the regorus ffi shared library
        to be found in $(RegorusFFIArtifactsDir)/<target-triple>/$(RegorusFFIArtifactsProfile).

        If $(IgnoreMissingArtifacts) is not set, ensure that the binaries for officially supported platforms exists.
    -->
    <Target Name="ChecksRegorusFFIArtifactsDir" BeforeTargets="Pack" Condition="'$(IgnoreMissingArtifacts)' == ''">
        <Error Text="RegorusFFIArtifactsDir must be supplied." Condition="$(RegorusFFIArtifactsDir) == ''" />

        <!-- Ensure that the binaries for officially supported platforms exists. -->
         <Error Text="$(RegorusFFIArtifactsDir)/x86_64-pc-windows-msvc/$(RegorusFFIArtifactsProfile)/regorus_ffi.dll missing."
             Condition="!Exists('$(RegorusFFIArtifactsDir)/x86_64-pc-windows-msvc/$(RegorusFFIArtifactsProfile)/regorus_ffi.dll')" />
         <Error Text="$(RegorusFFIArtifactsDir)/x86_64-pc-windows-msvc/$(RegorusFFIArtifactsProfile)/regorus_ffi.pdb missing."
             Condition="!Exists('$(RegorusFFIArtifactsDir)/x86_64-pc-windows-msvc/$(RegorusFFIArtifactsProfile)/regorus_ffi.pdb')" />

         <Error Text="$(RegorusFFIArtifactsDir)/x86_64-unknown-linux-gnu/$(RegorusFFIArtifactsProfile)/libregorus_ffi.so missing."
             Condition="!Exists('$(RegorusFFIArtifactsDir)/x86_64-unknown-linux-gnu/$(RegorusFFIArtifactsProfile)/libregorus_ffi.so')" />

         <Error Text="$(RegorusFFIArtifactsDir)/aarch64-apple-darwin/$(RegorusFFIArtifactsProfile)/libregorus_ffi.dylib missing."
             Condition="!Exists('$(RegorusFFIArtifactsDir)/aarch64-apple-darwin/$(RegorusFFIArtifactsProfile)/libregorus_ffi.dylib')" />
    </Target>

    <ItemGroup>
        <None Include="docs/README.md" Pack="true"  PackagePath="/" />
        <None Include="../../../LICENSE" Pack="true" PackagePath="/" />

        <!-- Copy each binary to expected location within the package -->
        <None Include="$(RegorusFFIArtifactsDir)/x86_64-pc-windows-msvc/$(RegorusFFIArtifactsProfile)/*.dll" Pack="true" PackagePath="runtimes/win-x64/native/" />
        <None Include="$(RegorusFFIArtifactsDir)/x86_64-pc-windows-msvc/$(RegorusFFIArtifactsProfile)/*.pdb" Pack="true" PackagePath="runtimes/win-x64/native/" />

        <None Include="$(RegorusFFIArtifactsDir)/aarch64-pc-windows-msvc/$(RegorusFFIArtifactsProfile)/*.dll" Pack="true" PackagePath="runtimes/win-arm64/native/" />
        <None Include="$(RegorusFFIArtifactsDir)/aarch64-pc-windows-msvc/$(RegorusFFIArtifactsProfile)/*.pdb" Pack="true" PackagePath="runtimes/win-arm64/native/" />

        <None Include="$(RegorusFFIArtifactsDir)/x86_64-unknown-linux-gnu/$(RegorusFFIArtifactsProfile)/lib*.so" Pack="true" PackagePath="runtimes/linux-x64/native/" />

        <None Include="$(RegorusFFIArtifactsDir)/aarch64-apple-darwin/$(RegorusFFIArtifactsProfile)/lib*.dylib" Pack="true" PackagePath="runtimes/osx-arm64/native/" />
    </ItemGroup>
</Project>
