jamescourtney / FlatSharp

Fast, idiomatic C# implementation of Flatbuffers
Apache License 2.0
497 stars 50 forks source link

Shared fbs between multiple projects #388

Closed duckdoom4 closed 1 year ago

duckdoom4 commented 1 year ago

I'd like to be able to share some code between multiple projects. For example:

We have Project A, Project B, Shared Project and Main Project.

Project A and Project B produce a dll consumed by Main Project. Shared Project contains common fbs files that are shared between A and B.

Project A contains fbs files that need to include Shared project's fbs files.

Currently this doesn't seem to work. I get errors telling me that The type 'SharedType' in 'path\to\ProjectA\FlatSharp.generated.cs' conflicts with the imported type 'SharedType' in 'SharedProject, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. Using the type defined in 'path\to\ProjectA\FlatSharp.generated.cs'.

To paint a better picture of our use case here are the details:

I have an fbs for vec3f, this is used in A and B.

namespace pkNX.Structures.FlatBuffers;

table Vec3f {
    X:float;
    Y:float;
    Z:float;
}

Then I implement the code (something like this):

namespace pkNX.Structures.FlatBuffers;

[TypeConverter(typeof(ExpandableObjectConverter))]
public partial class Vec3f
{
    public static readonly Vec3f Zero = new();
    public static readonly Vec3f One = new(1, 1, 1);

    public Vec3f(float x = 0, float y = 0, float z = 0)
    {
        X = x;
        Y = y;
        Z = z;
    }

    public bool IsOne => X is 1 && Y is 1 && Z is 1;
    public bool IsZero => X is 0 && Y is 0 && Z is 0;

    public float Magnitude => MathF.Sqrt(MagnitudeSqr);
    public float MagnitudeSqr => Dot(this);
    public Vec3f Normalized() => this * (1 / Magnitude);

    public float Dot(Vec3f other) => X * other.X + Y * other.Y + Z * other.Z;
    public Vec3f Cross(Vec3f other) => new(Y * other.Z - Z * other.Y, Z * other.X - X * other.Z, X * other.Y - Y * other.X);
    public float DistanceTo(Vec3f other) => (this - other).Magnitude;
    public float DistanceToSqr(Vec3f other) => (this - other).MagnitudeSqr;
    public Vec3f Lerp(Vec3f other, float t) => this + (other - this) * t;
    public static Vec3f operator -(Vec3f v) => new(-v.X, -v.Y, -v.Z);

    public static Vec3f operator +(Vec3f l, Vec3f r) => new(l.X + r.X, l.Y + r.Y, l.Z + r.Z);
    public static Vec3f operator -(Vec3f l, Vec3f r) => new(l.X - r.X, l.Y - r.Y, l.Z - r.Z);
    public static Vec3f operator *(Vec3f l, Vec3f r) => new(l.X * r.X, l.Y * r.Y, l.Z * r.Z);
    public static Vec3f operator /(Vec3f l, Vec3f r) => new(l.X / r.X, l.Y / r.Y, l.Z / r.Z);

    public static Vec3f operator +(Vec3f l, float r) => new(l.X + r, l.Y + r, l.Z + r);
    public static Vec3f operator -(Vec3f l, float r) => new(l.X - r, l.Y - r, l.Z - r);
    public static Vec3f operator *(Vec3f l, float r) => new(l.X * r, l.Y * r, l.Z * r);
    public static Vec3f operator /(Vec3f l, float r) => new(l.X / r, l.Y / r, l.Z / r);

    public static bool operator ==(Vec3f? left, Vec3f? right) => Equals(left, right);
    public static bool operator !=(Vec3f? left, Vec3f? right) => !Equals(left, right);
}

Now project A and B will use the above mentioned code/fbs include from the shared project.

As of right now, this wouldn't work. Due to the errors mentioned earlier. I hope this paints a better picture, if not I can make a sample project.

duckdoom4 commented 1 year ago

On a related note. In an attempt to work around this, I placed all files inside one project. Unfortunately this also doesn't work.

1>dotnet C:\Users\Admin\.nuget\packages\flatsharp.compiler\7.1.1\tools\net6.0\FlatSharp.Compiler.dll --nullable-warnings true --normalize-field-names true --gen-poolable false --input "..\Reflection\Schemas\reflection.fbs;..\Arceus\Schemas\Config\AppConfigList.fbs;..\Arceus\Schemas\Config\ConfigureTable.fbs;..\Arceus\Schemas\DressUp\DressUpTable.fbs;..\Arceus\Schemas\Event\Trigger.fbs;..\Arceus\Schemas\Field\LandmarkItemSpawnTable.fbs;..\Arceus\Schemas\Field\LandmarkItemTable.fbs;..\Arceus\Schemas\Field\MassOutbreakTable.fbs;..\Arceus\Schemas\Field\NewHuge\NewHugeOutbreakGroup.fbs;..\Arceus\Schemas\Field\NewHuge\NewHugeOutbreakGroupLottery.fbs;..\Arceus\Schemas\Field\NewHuge\NewHugeOutbreakLottery.fbs;..\Arceus\Schemas\Field\NewHuge\NewHugeOutbreakTimeLimit.fbs;..\Arceus\Schemas\Field\Resident\AreaBGMTable.fbs;..\Arceus\Schemas\Field\Resident\AreaSettingsTable.fbs;..\Arceus\Schemas\Field\Resident\AreaWeatherTable.fbs;..\Arceus\Schemas\Field\Slots\EncounterDataArchive.fbs;..\Arceus\Schemas\Field\Slots\EncounterMultiplerArchive.fbs;..\Arceus\Schemas\Field\Static\EventEncountArchive.fbs;..\Arceus\Schemas\Geometry\AABB.fbs;..\Arceus\Schemas\Geometry\Sphere.fbs;..\Arceus\Schemas\HaShopTable.fbs;..\Arceus\Schemas\Math\math.fbs;..\Arceus\Schemas\Math\Matrix4x3f.fbs;..\Arceus\Schemas\Math\PackedVec2f.fbs;..\Arceus\Schemas\Math\PackedVec3f.fbs;..\Arceus\Schemas\Math\PackedVec4f.fbs;..\Arceus\Schemas\Math\PackedVec4i.fbs;..\Arceus\Schemas\Math\Quat4f.fbs;..\Arceus\Schemas\Math\Transform.fbs;..\Arceus\Schemas\Math\Vec2f.fbs;..\Arceus\Schemas\Math\Vec3f.fbs;..\Arceus\Schemas\Math\Vec4f.fbs;..\Arceus\Schemas\Misc\ArchiveContents.fbs;..\Arceus\Schemas\Misc\KeyAssignmentTable.fbs;..\Arceus\Schemas\Misc\LbPointsTable.fbs;..\Arceus\Schemas\Misc\MoveShopTable.fbs;..\Arceus\Schemas\Misc\PlayReportTable.fbs;..\Arceus\Schemas\Misc\ScriptIDRecordRelease.fbs;..\Arceus\Schemas\NPC\NPCModelSet.fbs;..\Arceus\Schemas\Placement\OybnSettingTable.fbs;..\Arceus\Schemas\Placement\PlacementItemArchive.fbs;..\Arceus\Schemas\Placement\PlacementLocationArchive.fbs;..\Arceus\Schemas\Placement\PlacementMkrgTable.fbs;..\Arceus\Schemas\Placement\PlacementParameters.fbs;..\Arceus\Schemas\Placement\PlacementSearchItemTable.fbs;..\Arceus\Schemas\Placement\PlacementSpawnerData.fbs;..\Arceus\Schemas\Placement\PlacementUnnnTable.fbs;..\Arceus\Schemas\Pokedex\PokedexDistributionTable.fbs;..\Arceus\Schemas\Pokedex\PokedexRankTable.fbs;..\Arceus\Schemas\Pokedex\PokedexResearchTable.fbs;..\Arceus\Schemas\Poke\EvolutionTable.fbs;..\Arceus\Schemas\Poke\Model Set\PokeModelSet.fbs;..\Arceus\Schemas\Poke\Model\BoneScalarMesh.fbs;..\Arceus\Schemas\Poke\Model\Material.fbs;..\Arceus\Schemas\Poke\Model\Mesh.fbs;..\Arceus\Schemas\Poke\Model\MeshBuffer.fbs;..\Arceus\Schemas\Poke\Model\Model.fbs;..\Arceus\Schemas\Poke\Model\MultiMaterialTable.fbs;..\Arceus\Schemas\Poke\Model\PokeConfig.fbs;..\Arceus\Schemas\Poke\Model\Shader.fbs;..\Arceus\Schemas\Poke\Model\Skeleton.fbs;..\Arceus\Schemas\Poke\Moves\Learnset.fbs;..\Arceus\Schemas\Poke\Moves\PokeFieldObstructionWaza.fbs;..\Arceus\Schemas\Poke\Moves\PokeFieldObstructionWazaNsLegendArchive.fbs;..\Arceus\Schemas\Poke\Moves\PokeFieldObstructionWazaNsLegendEffectArchive.fbs;..\Arceus\Schemas\Poke\Moves\PokeFieldObstructionWazaSeArchive.fbs;..\Arceus\Schemas\Poke\Moves\PokeFieldObstructionWazaWildArchive.fbs;..\Arceus\Schemas\Poke\Moves\PokeFieldObstructionWazaWildEffectArchive.fbs;..\Arceus\Schemas\Poke\Moves\PokeFieldObstructionWazaWildWaterArchive.fbs;..\Arceus\Schemas\Poke\Moves\PokeFieldObstructionWazaWildWaterEffectArchive.fbs;..\Arceus\Schemas\Poke\Moves\Waza.fbs;..\Arceus\Schemas\Poke\PersonalInfoLAfb.fbs;..\Arceus\Schemas\Poke\PokeAdd.fbs;..\Arceus\Schemas\Poke\PokeAIArchive.fbs;..\Arceus\Schemas\Poke\PokeBattleSpawnArchive.fbs;..\Arceus\Schemas\Poke\PokeBodyParticleArchive.fbs;..\Arceus\Schemas\Poke\PokeCaptureCollisionArchive.fbs;..\Arceus\Schemas\Poke\PokeDefaultLocatorArchive.fbs;..\Arceus\Schemas\Poke\PokeDropItem.fbs;..\Arceus\Schemas\Poke\PokeDropItemArchive.fbs;..\Arceus\Schemas\Poke\PokeDropItemBattleArchive.fbs;..\Arceus\Schemas\Poke\PokeEatingHabitsArchive.fbs;..\Arceus\Schemas\Poke\PokeMiscTable.fbs;..\Arceus\Schemas\Poke\PokeResource\PokeInfoList.fbs;..\Arceus\Schemas\Poke\PokeResource\PokeResourceTable.fbs;..\Arceus\Schemas\Shared\AbilityType.fbs;..\Arceus\Schemas\Shared\FlatDummyObject.fbs;..\Arceus\Schemas\Shared\NatureType.fbs;..\Arceus\Schemas\Shared\ShinyType.fbs;..\Arceus\Schemas\Throw\CommonCaptureConfigTable.fbs;..\Arceus\Schemas\Throw\ThrowableBaitParamDictionary.fbs;..\Arceus\Schemas\Throw\ThrowableParamTable.fbs;..\Arceus\Schemas\Throw\ThrowableResourceDictionary.fbs;..\Arceus\Schemas\Throw\ThrowableResourceSetDictionary.fbs;..\Arceus\Schemas\Throw\ThrowParamTable.fbs;..\Arceus\Schemas\Throw\ThrowPermissionSet.fbs;..\Arceus\Schemas\TrainerData.fbs;..\Arceus\Schemas\Util\Color3f.fbs;..\Arceus\Schemas\Util\Color4f.fbs;..\LGPE\Schemas\shop.fbs;..\LGPE\Schemas\wild.fbs;..\SV\Schemas\Audio\BGMEventArray.fbs;..\SV\Schemas\Audio\BGMEventType.fbs;..\SV\Schemas\Audio\EnvPokeVoiceLotterySetting.fbs;..\SV\Schemas\Battle\BattleConfig.fbs;..\SV\Schemas\Battle\BattleEffectTableArray.fbs;..\SV\Schemas\Battle\ItemTableArray.fbs;..\SV\Schemas\Battle\PokeExceptionTableArray.fbs;..\SV\Schemas\Cooking\CookingCommonData.fbs;..\SV\Schemas\Cooking\Enums\FoodSkillType.fbs;..\SV\Schemas\Cooking\Enums\IngredientType.fbs;..\SV\Schemas\Cooking\Enums\RecipeType.fbs;..\SV\Schemas\Cooking\Enums\SeasoningType.fbs;..\SV\Schemas\Cooking\FoodPowerComboArray.fbs;..\SV\Schemas\Cooking\IngredientDataArray.fbs;..\SV\Schemas\Cooking\IngredientDishDataArray.fbs;..\SV\Schemas\Cooking\Param\FoodPokeTypeParam.fbs;..\SV\Schemas\Cooking\Param\FoodPowerComboParam.fbs;..\SV\Schemas\Cooking\Param\FoodPowerParam.fbs;..\SV\Schemas\Cooking\Param\IngredientParam.fbs;..\SV\Schemas\Cooking\RecipeDataArray.fbs;..\SV\Schemas\Cooking\SeasoningDataArray.fbs;..\SV\Schemas\Cooking\TakaraSpicePowerTableArray.fbs;..\SV\Schemas\Entity\CollisionShape.fbs;..\SV\Schemas\Entity\ComparisonOperatorType.fbs;..\SV\Schemas\Entity\ConditionSimpleAutoBattleHecklerAreaArray.fbs;..\SV\Schemas\Entity\OwnerInfo.fbs;..\SV\Schemas\Entity\ParamSet.fbs;..\SV\Schemas\Entity\PokemonTriggerID.fbs;..\SV\Schemas\Entity\PokemonUniquePathData.fbs;..\SV\Schemas\Entity\PokeObjArray.fbs;..\SV\Schemas\Event\EventAddPokemonArray.fbs;..\SV\Schemas\Event\EventSub012.RewardTableArray.fbs;..\SV\Schemas\Event\EventTradeListArray.fbs;..\SV\Schemas\Event\EventTradePokemonArray.fbs;..\SV\Schemas\Event\Motion\FieldNpcFaceType.fbs;..\SV\Schemas\Event\Motion\FieldNpcMotion.fbs;..\SV\Schemas\Event\Motion\FieldNpcMotionType.fbs;..\SV\Schemas\Event\Motion\FieldNpcPokemonDefaultMotion.fbs;..\SV\Schemas\Event\Motion\FieldNpcPokemonMotion.fbs;..\SV\Schemas\Event\Motion\NpcTrafficFormation.fbs;..\SV\Schemas\Event\Motion\NpcTrafficPartnerType.fbs;..\SV\Schemas\Event\NpcTrafficGenerateTableArray.fbs;..\SV\Schemas\Event\PopupWindowTableArray.fbs;..\SV\Schemas\Event\TreeShakePokemonArray.fbs;..\SV\Schemas\Geometry\PackedVec2f.fbs;..\SV\Schemas\Geometry\PackedVec3f.fbs;..\SV\Schemas\Geometry\PackedVec4f.fbs;..\SV\Schemas\Geometry\Transform.fbs;..\SV\Schemas\Geometry\Vec3f.fbs;..\SV\Schemas\Gym\ExerciseRewardData.fbs;..\SV\Schemas\Gym\ExerciseSetting.fbs;..\SV\Schemas\Gym\gym.denki.PopupPosTableArray.fbs;..\SV\Schemas\Gym\gym.esper.ENDLESS_BORDERArray.fbs;..\SV\Schemas\Gym\gym.esper.EXERCISE_COURSESArray.fbs;..\SV\Schemas\Gym\gym.kusa.PokeTableArray.fbs;..\SV\Schemas\Gym\gym.kusa.RewardTableArray.fbs;..\SV\Schemas\Gym\gym.mizu.FixTableArray.fbs;..\SV\Schemas\Gym\gym.mizu.SeriItemTableArray.fbs;..\SV\Schemas\Gym\gym.mizu.SeriNpcTableArray.fbs;..\SV\Schemas\Gym\gym.mizu.SeriVenueTableArray.fbs;..\SV\Schemas\Gym\gym.mushi.GymMushiData.fbs;..\SV\Schemas\Gym\gym.mushi.GymMushiRewardArray.fbs;..\SV\Schemas\Gym\GymKooriCoursePokemonTable.fbs;..\SV\Schemas\Gym\GymKooriCourseTableArray.fbs;..\SV\Schemas\Gym\gym_denki.PopupFixTableArray.fbs;..\SV\Schemas\Item\DLCItemGroupArray.fbs;..\SV\Schemas\Item\DropItemDataArray.fbs;..\SV\Schemas\Item\Enums\BattleFunctionType.fbs;..\SV\Schemas\Item\Enums\EquipEffect.fbs;..\SV\Schemas\Item\Enums\FieldFunctionType.fbs;..\SV\Schemas\Item\Enums\FieldPocket.fbs;..\SV\Schemas\Item\Enums\ItemGroup.fbs;..\SV\Schemas\Item\Enums\ItemType.fbs;..\SV\Schemas\Item\Enums\PluckEffect.fbs;..\SV\Schemas\Item\Enums\WorkPpSelTgt.fbs;..\SV\Schemas\Item\Enums\WorkType.fbs;..\SV\Schemas\Item\HiddenItemBiomeTableArray.fbs;..\SV\Schemas\Item\HiddenItemDataTableArray.fbs;..\SV\Schemas\Item\ItemDataArray.fbs;..\SV\Schemas\Item\ItemPointTypeBiomeTableArray.fbs;..\SV\Schemas\Item\MonohiroiItemArray.fbs;..\SV\Schemas\Item\RummagingItemDataTableArray.fbs;..\SV\Schemas\Misc\Ajito\AjitoCommonLevelArray.fbs;..\SV\Schemas\Misc\Ajito\AjitoDifficultEnum.fbs;..\SV\Schemas\Misc\Ajito\AjitoPokemonArray.fbs;..\SV\Schemas\Misc\Ajito\AjitoTypeEnum.fbs;..\SV\Schemas\Misc\Ajito\AjitoUnitArray.fbs;..\SV\Schemas\Misc\GemSettingRootTableArray.fbs;..\SV\Schemas\Misc\RibbonDataArray.fbs;..\SV\Schemas\NetBattle\NetBattleRuleDataArray.fbs;..\SV\Schemas\NetBattle\NetBattleRuleParamArray.fbs;..\SV\Schemas\Personal\PersonalInfoDetail.fbs;..\SV\Schemas\Personal\PersonalInfoDex.fbs;..\SV\Schemas\Personal\PersonalInfoEvolution.fbs;..\SV\Schemas\Personal\PersonalInfoGender.fbs;..\SV\Schemas\Personal\PersonalInfoHatch.fbs;..\SV\Schemas\Personal\PersonalInfoMove.fbs;..\SV\Schemas\Personal\PersonalInfoStats.fbs;..\SV\Schemas\Personal\PersonalTable.fbs;..\SV\Schemas\Picnic\PicnicPokemon.fbs;..\SV\Schemas\Picnic\PicnicSystemData.fbs;..\SV\Schemas\Picnic\PicnicTablesetData.fbs;..\SV\Schemas\Picnic\PicnicWagonData.fbs;..\SV\Schemas\PokeData\PokeDataBattle.fbs;..\SV\Schemas\PokeData\PokeDataEventBattle.fbs;..\SV\Schemas\PokeData\PokeDataFull.fbs;..\SV\Schemas\PokeData\PokeDataSymbol.fbs;..\SV\Schemas\PokeData\PokeDataTrade.fbs;..\SV\Schemas\PokeData\WazaSet.fbs;..\SV\Schemas\Raid\DeliveryRaidEnemyTableArray.fbs;..\SV\Schemas\Raid\DeliveryRaidFixedRewardItemArray.fbs;..\SV\Schemas\Raid\DeliveryRaidLotteryRewardItemArray.fbs;..\SV\Schemas\Raid\DeliveryRaidPriorityArray.fbs;..\SV\Schemas\Raid\Enums\RaidBossExtraActType.fbs;..\SV\Schemas\Raid\Enums\RaidBossExtraTimingType.fbs;..\SV\Schemas\Raid\Enums\RaidRewardItemCategoryType.fbs;..\SV\Schemas\Raid\Enums\RaidRewardItemSubjectType.fbs;..\SV\Schemas\Raid\Enums\RaidRomType.fbs;..\SV\Schemas\Raid\RaidDifficultyLotteryTableArray.fbs;..\SV\Schemas\Raid\RaidEnemyInfo.fbs;..\SV\Schemas\Raid\RaidEnemyTableArray.fbs;..\SV\Schemas\Raid\RaidFixedRewardItemArray.fbs;..\SV\Schemas\Raid\RaidFixedRewardItemInfo.fbs;..\SV\Schemas\Raid\RaidGemSetting.fbs;..\SV\Schemas\Raid\RaidLotteryRewardItemArray.fbs;..\SV\Schemas\Raid\RaidLotteryRewardItemInfo.fbs;..\SV\Schemas\Raid\RaidPokeScaleDataArray.fbs;..\SV\Schemas\Raid\RaidRewardSlotArray.fbs;..\SV\Schemas\Raid\RaidTrainerArray.fbs;..\SV\Schemas\Shared\BallType.fbs;..\SV\Schemas\Shared\BattleType.fbs;..\SV\Schemas\Shared\DataType.fbs;..\SV\Schemas\Shared\DevID.fbs;..\SV\Schemas\Shared\GemType.fbs;..\SV\Schemas\Shared\ItemID.fbs;..\SV\Schemas\Shared\LangType.fbs;..\SV\Schemas\Shared\MoveType.fbs;..\SV\Schemas\Shared\PokeMemoType.fbs;..\SV\Schemas\Shared\RareType.fbs;..\SV\Schemas\Shared\RibbonType.fbs;..\SV\Schemas\Shared\SeikakuType.fbs;..\SV\Schemas\Shared\Sex.fbs;..\SV\Schemas\Shared\SexType.fbs;..\SV\Schemas\Shared\SizeType.fbs;..\SV\Schemas\Shared\TalentType.fbs;..\SV\Schemas\Shared\TokuseiType.fbs;..\SV\Schemas\System\ObjectGenerationRangeArray.fbs;..\SV\Schemas\Trainers\Talk\CheckCategory.fbs;..\SV\Schemas\Trainers\Talk\TalkData.fbs;..\SV\Schemas\Trainers\Talk\TalkRankEffect.fbs;..\SV\Schemas\Trainers\TrainerBodySize.fbs;..\SV\Schemas\Trainers\TrainerCategory.fbs;..\SV\Schemas\Trainers\TrainerDataArray.fbs;..\SV\Schemas\Trainers\TrainerEnvArray.fbs;..\SV\Schemas\Trainers\TrainerTypeArray.fbs;..\SV\Schemas\Trinity\TrinityComponent.fbs;..\SV\Schemas\Trinity\TrinityFileDescriptors.fbs;..\SV\Schemas\Trinity\TrinityFileSystemMetadata.fbs;..\SV\Schemas\Trinity\TrinityPak.fbs;..\SV\Schemas\Trinity\TrinityPropertySheet.fbs;..\SV\Schemas\Trinity\TrinitySceneObject.fbs;..\SV\Schemas\Trinity\TrinitySceneObjectTemplate.fbs;..\SV\Schemas\Trinity\TrinityScenePoint.fbs;..\SV\Schemas\UI\BattleBgmSelectTableArray.fbs;..\SV\Schemas\UI\BufDataArray.fbs;..\SV\Schemas\UI\Dressup\DressupCategoryDataArray.fbs;..\SV\Schemas\UI\Dressup\DressupItemDataArray.fbs;..\SV\Schemas\UI\Dressup\DressupShopDataArray.fbs;..\SV\Schemas\UI\Dressup\DressupStyleDataArray.fbs;..\SV\Schemas\UI\Dressup\DressupStylePresetDataArray.fbs;..\SV\Schemas\UI\Enums\ClerkType.fbs;..\SV\Schemas\UI\Enums\CondEnum.fbs;..\SV\Schemas\UI\Enums\PayType.fbs;..\SV\Schemas\UI\Enums\SellType.fbs;..\SV\Schemas\UI\Enums\ShopKind.fbs;..\SV\Schemas\UI\Quest\DanQuestClearArray.fbs;..\SV\Schemas\UI\Quest\EventSkyFlyArray.fbs;..\SV\Schemas\UI\Quest\GymQuestClearArray.fbs;..\SV\Schemas\UI\Quest\NushiQuestClearArray.fbs;..\SV\Schemas\UI\Restaurant\RestaurantMenuDataArray.fbs;..\SV\Schemas\UI\Restaurant\RestaurantShopDataArray.fbs;..\SV\Schemas\UI\SchoolMapDataArray.fbs;..\SV\Schemas\UI\Shop\FriendlyShopDataArray.fbs;..\SV\Schemas\UI\Shop\LineupDataArray.fbs;..\SV\Schemas\UI\Shop\ShopDataArray.fbs;..\SV\Schemas\UI\Shop\ShopWazamachineDataArray.fbs;..\SV\Schemas\UI\SystemBgArray.fbs;..\SV\Schemas\UI\TipsDataArray.fbs;..\SV\Schemas\UI\ymap\DestinationDataTableArray.fbs;..\SV\Schemas\UI\ymap\NpcDestinationDataTableArray.fbs;..\SV\Schemas\UI\ymap\PlaceNameDataTableArray.fbs;..\SV\Schemas\Waza\Waza.fbs;..\SV\Schemas\Waza\WazaAffinity.fbs;..\SV\Schemas\Waza\WazaEntityStat.fbs;..\SV\Schemas\Waza\WazaID.fbs;..\SV\Schemas\Waza\WazaInflict.fbs;..\SV\Schemas\Waza\WazaType.fbs;..\SV\Schemas\World\Area\AreaInfo.fbs;..\SV\Schemas\World\Area\AreaTag.fbs;..\SV\Schemas\World\Area\AreaType.fbs;..\SV\Schemas\World\Area\BandType.fbs;..\SV\Schemas\World\Area\Biome.fbs;..\SV\Schemas\World\Area\BringItem.fbs;..\SV\Schemas\World\Area\EnableTable.fbs;..\SV\Schemas\World\Area\EncAttr.fbs;..\SV\Schemas\World\Area\EncBiome.fbs;..\SV\Schemas\World\Area\FieldAttrKey.fbs;..\SV\Schemas\World\Area\FieldDungeonAreaArray.fbs;..\SV\Schemas\World\Area\FieldInsideAreaArray.fbs;..\SV\Schemas\World\Area\FieldLocationArray.fbs;..\SV\Schemas\World\Area\FieldMainAreaArray.fbs;..\SV\Schemas\World\Area\FieldSubAreaArray.fbs;..\SV\Schemas\World\Area\OverrideBiome.fbs;..\SV\Schemas\World\EncountPokeDataArray.fbs;..\SV\Schemas\World\EventBattlePokemonArray.fbs;..\SV\Schemas\World\Field\AreaFlyFlagArray.fbs;..\SV\Schemas\World\Field\CoinSymbolManager.fbs;..\SV\Schemas\World\Field\ExclusionGroupArray.fbs;..\SV\Schemas\World\Field\FieldAutomaticReturnTableArray.fbs;..\SV\Schemas\World\Field\FieldAutoReturnPosTableArray.fbs;..\SV\Schemas\World\Field\FieldCamera.fbs;..\SV\Schemas\World\Field\FieldInteriorCamera.fbs;..\SV\Schemas\World\Field\FieldOutOfRangeTableArray.fbs;..\SV\Schemas\World\Field\FieldPlayer.fbs;..\SV\Schemas\World\Field\FieldRide.fbs;..\SV\Schemas\World\Field\GemSymbolLotteryTableArray.fbs;..\SV\Schemas\World\Field\GemSymbolSetting.fbs;..\SV\Schemas\World\Field\MapChangeParametersArray.fbs;..\SV\Schemas\World\FixedSymbol\BehaviorFrequency.fbs;..\SV\Schemas\World\FixedSymbol\FixedSymbolAI.fbs;..\SV\Schemas\World\FixedSymbol\FixedSymbolArray.fbs;..\SV\Schemas\World\FixedSymbol\FixedSymbolGeneration.fbs;..\SV\Schemas\World\FixedSymbol\FixedSymbolManager.fbs;..\SV\Schemas\World\FixedSymbol\GenerationPattern.fbs;..\SV\Schemas\World\FixedSymbol\PokemonActionID.fbs;..\SV\Schemas\World\PointDataArray.fbs;..\SV\Schemas\World\SettingData.fbs;..\SV\Schemas\World\TimeTable.fbs;..\SV\Schemas\World\VersionTable.fbs;..\SV\Schemas\Zukan\BlacklistArray.fbs;..\SV\Schemas\Zukan\DistributionRootArray.fbs;..\SV\Schemas\Zukan\MemoPokeTableArray.fbs;..\SV\Schemas\Zukan\RewardDataArray.fbs;..\SWSH\Schemas\ArchiveContent.fbs;..\SWSH\Schemas\BattleTowerPoke.fbs;..\SWSH\Schemas\BattleTowerTrainer.fbs;..\SWSH\Schemas\CellTable.fbs;..\SWSH\Schemas\EncounterArchive.fbs;..\SWSH\Schemas\EncounterNestArchive.fbs;..\SWSH\Schemas\EncounterStaticArchive.fbs;..\SWSH\Schemas\EncounterTradeArchive.fbs;..\SWSH\Schemas\Geometry\AABB.fbs;..\SWSH\Schemas\Geometry\Sphere.fbs;..\SWSH\Schemas\GiftArchive.fbs;..\SWSH\Schemas\Math\math.fbs;..\SWSH\Schemas\Math\PackedVec3f.fbs;..\SWSH\Schemas\Model\GFBModel.fbs;..\SWSH\Schemas\Model\GFBPokeConfig.fbs;..\SWSH\Schemas\NestHoleCrystalEncounterArchive.fbs;..\SWSH\Schemas\NestHoleDistributionEncounterArchive.fbs;..\SWSH\Schemas\NestHoleDistributionRewardArchive.fbs;..\SWSH\Schemas\NestHoleLevelArchive.fbs;..\SWSH\Schemas\NestHoleRewardArchive.fbs;..\SWSH\Schemas\NestHoleUndergroundArchive.fbs;..\SWSH\Schemas\Placement\Placement.fbs;..\SWSH\Schemas\Placement\PlacementShared.fbs;..\SWSH\Schemas\Placement\PlacementZone.fbs;..\SWSH\Schemas\Placement\PlacementZoneAdvancedTipHolder.fbs;..\SWSH\Schemas\Placement\PlacementZoneBerryTreeHolder.fbs;..\SWSH\Schemas\Placement\PlacementZoneEnvironmentHolder.fbs;..\SWSH\Schemas\Placement\PlacementZoneFieldItemHolder.fbs;..\SWSH\Schemas\Placement\PlacementZoneFishingPointHolder.fbs;..\SWSH\Schemas\Placement\PlacementZoneFlightAnchorHolder.fbs;..\SWSH\Schemas\Placement\PlacementZoneHiddenItemHolder.fbs;..\SWSH\Schemas\Placement\PlacementZoneIKStepHolder.fbs;..\SWSH\Schemas\Placement\PlacementZoneLadderHolder.fbs;..\SWSH\Schemas\Placement\PlacementZoneMovementPathHolder.fbs;..\SWSH\Schemas\Placement\PlacementZoneNestHoleHolder.fbs;..\SWSH\Schemas\Placement\PlacementZoneNPCHolder.fbs;..\SWSH\Schemas\Placement\PlacementZoneOtherNPCHolder.fbs;..\SWSH\Schemas\Placement\PlacementZoneParticleHolder.fbs;..\SWSH\Schemas\Placement\PlacementZonePokeCenterSpawnAnchorHolder.fbs;..\SWSH\Schemas\Placement\PlacementZonePopupHolder.fbs;..\SWSH\Schemas\Placement\PlacementZoneQuadrantHolder.fbs;..\SWSH\Schemas\Placement\PlacementZoneRotomRallyEntry.fbs;..\SWSH\Schemas\Placement\PlacementZoneSpeciesHolder.fbs;..\SWSH\Schemas\Placement\PlacementZoneStaticObjectsHolder.fbs;..\SWSH\Schemas\Placement\PlacementZoneStepJumpHolder.fbs;..\SWSH\Schemas\Placement\PlacementZoneSymbolSpawnHolder.fbs;..\SWSH\Schemas\Placement\PlacementZoneTrainerHolder.fbs;..\SWSH\Schemas\Placement\PlacementZoneTrainerTipHolder.fbs;..\SWSH\Schemas\Placement\PlacementZoneTriggerHolder.fbs;..\SWSH\Schemas\Placement\PlacementZoneUnitObjectHolder.fbs;..\SWSH\Schemas\Placement\PlacementZoneWarpHolder.fbs;..\SWSH\Schemas\PokeResourceTable.fbs;..\SWSH\Schemas\RentalArchive.fbs;..\SWSH\Schemas\ScriptMeta.fbs;..\SWSH\Schemas\shop.fbs;..\SWSH\Schemas\SymbolBehavior.fbs;..\SWSH\Schemas\Util\Color3f.fbs;..\SWSH\Schemas\Util\Color4f.fbs;..\SWSH\Schemas\Waza.fbs;..\SWSH\Schemas\WeatherEntry.fbs" --includes "" --output obj\Debug\net7.0\

1>C:\Users\Admin\.nuget\packages\flatsharp.compiler\7.1.1\build\FlatSharp.Compiler.targets(123,9): error : System.ComponentModel.Win32Exception (206): An error occurred trying to start process 'C:\Users\Admin\.nuget\packages\flatsharp.compiler\7.1.1\tools\net6.0\flatc\windows\flatc.exe' with working directory 'C:\Users\Admin\Documents\Projects\Pokemon Projects\pkNX\pkNX.Structures.FlatBuffers\pkNX.Structures.FlatBuffers'. The filename or extension is too long.
1>C:\Users\Admin\.nuget\packages\flatsharp.compiler\7.1.1\build\FlatSharp.Compiler.targets(123,9): error :    at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)
1>C:\Users\Admin\.nuget\packages\flatsharp.compiler\7.1.1\build\FlatSharp.Compiler.targets(123,9): error :    at System.Diagnostics.Process.Start()
1>C:\Users\Admin\.nuget\packages\flatsharp.compiler\7.1.1\build\FlatSharp.Compiler.targets(123,9): error :    at FlatSharp.Compiler.FlatSharpCompiler.GetBfbs(CompilerOptions options) in D:\a\FlatSharp\FlatSharp\src\FlatSharp.Compiler\FlatSharpCompiler.cs:line 437
1>C:\Users\Admin\.nuget\packages\flatsharp.compiler\7.1.1\build\FlatSharp.Compiler.targets(123,9): error :    at FlatSharp.Compiler.FlatSharpCompiler.RunCompiler(CompilerOptions options) in D:\a\FlatSharp\FlatSharp\src\FlatSharp.Compiler\FlatSharpCompiler.cs:line 105
1>C:\Users\Admin\.nuget\packages\flatsharp.compiler\7.1.1\build\FlatSharp.Compiler.targets(123,9): error :    at FlatSharp.Compiler.FlatSharpCompiler.<>c__DisplayClass7_0.<Main>b__0(CompilerOptions x) in D:\a\FlatSharp\FlatSharp\src\FlatSharp.Compiler\FlatSharpCompiler.cs:line 51
1>C:\Users\Admin\.nuget\packages\flatsharp.compiler\7.1.1\build\FlatSharp.Compiler.targets(123,9): error :    at CommandLine.ParserResultExtensions.WithParsed[T](ParserResult`1 result, Action`1 action)
1>C:\Users\Admin\.nuget\packages\flatsharp.compiler\7.1.1\build\FlatSharp.Compiler.targets(123,9): error :    at FlatSharp.Compiler.FlatSharpCompiler.Main(String[] args) in D:\a\FlatSharp\FlatSharp\src\FlatSharp.Compiler\FlatSharpCompiler.cs:line 47

Maybe we could separate the schemas based on namespaces? We have separate namespaces for most fbs files. namespace pkNX.Structures.FlatBuffers.Arceus; And we could then have namespace pkNX.Structures.FlatBuffers for the shared fbs files.

Any files not it that namespace should have no overlap so it'd be safe to treat them as separate compile units. Files that are part of a namespace would still be part of the high level namespace compile units, but be 'shared'

jamescourtney commented 1 year ago

Congrats! You've broken FlatSharp in a way I never anticipated or even really considered :) Looks like you're running afoul of this. FlatSharp internally invokes flatc to do the IDL parsing.

One thing you can do as a short term workaround is to have one "index" FBS file:

include "A.fbs";
include "B.fbs";
...
include "Z.fbs";

It seems I should probably switch from command-line switches to using a configuration file to avoid the path-length limitations.

Regarding the original topic of this thread, I've created this issue in the FlatBuffers repository to see if I can get some guidance. The short version is that flatc doesn't do a great job of telling me which files were explicitly passed in and which were included.

duckdoom4 commented 1 year ago

Awesome stuff. Thanks for taking the time to help me with this.

The index file is a great idea, that might actually do the trick for now. Will try it tomorrow.

In regards to the include thing. I think you might not need to know what files are included.

Can't we do something like:

var namespace = GetNamespaceFromFile()
var typeName = GetTypeNameFromFile(); // name of class or struct or enum etc.

string fullyQualifiedName = namespace + "." + typeName;

And then

Map<string, FBSCodeInfo> typesMap;

If not typesMap contains fullyQualifiedName {
    Add to map
}
Else
{
  Type is already defined. Might want to produce an error if the source file doesn't match. (Since that would mean it's actually defined twice in a single compilation unit)
}

Then you'd be able to serialize typesMap and import it from the derived projects

duckdoom4 commented 1 year ago

And maybe we could even give the end user some control over the compilation units by allowing multiple tags and adding an additional output file option.

For something along the lines of:

We have one large project, but we want to generate one set of flat buffers as ProjectA and another set as ProjectB. You might want this if you have conditional compilation. And right now, it would solve part of my problem by compiling into multiple units allowing shorter commands to be used.

But tbh, if the issue here is solved, I don't think we'd need this option anymore.

jamescourtney commented 1 year ago

I have a fix for this pending a bunch of test breaks.

There are two new MSBuild properties you can leverage:

<PropertyGroup>
    <!-- this goes in your shared library. This emits the class definitions, but no serializers -->
   <FlatSharpClassDefinitionsOnly>true</FlatSharpClassDefinitionsOnly>

    <!-- this goes in the consuming library. This triggers only processing 
            explicitly-passed input files. Serializers will be generated for included files, but no class definitions -->
   <FlatSharpInputFilesOnly>true</FlatSharpInputFilesOnly>
</PropertyGroup>

One big limitation is that I can't resolve different drive letters on Windows. Flatc doesn't tell me the drive letter, so I'm kind of up a creek in that regard.

duckdoom4 commented 1 year ago

I think it's safe-ish to assume the drive letter is the same as the input file. No one in their right mind would put in absolute paths to a different drive letter to includes in their .fbs

Unless.. it might be added to the aditional includes directory. But that one you'd be able to iterate through yourself so you can manually link the file paths to included files

jamescourtney commented 1 year ago

Fixed in 7.2.0 -- let me know how it works for you!

duckdoom4 commented 1 year ago

Awesome! Thanks for all the effort you put into helping us integrate it into our project!

I'll be testing everything first chance I get :)

jamescourtney commented 1 year ago

@duckdoom4 -- Please LMK if this is working as you expect. You should probably use FlatSharp 7.2.1 as it resolves the drive-letter issue.

duckdoom4 commented 1 year ago

Sorry, didn't have much time yet. I tried to get things to work but didn't complete the update yet. So far everything seems to work with one exception, but that might be my mistake. I'll let you know when I can be certain

duckdoom4 commented 1 year ago

@jamescourtney Hi there, I finally got time to test everything out properly. I am running into a small issue still though, but I think that's easy to solve. How did you intend the projects to be structured?

I now have: ClassLibrary called pkNX.Structures.FlatBuffers.Shared With the following properties:

<PropertyGroup>
  <FlatSharpClassDefinitionsOnly>true</FlatSharpClassDefinitionsOnly>
</PropertyGroup>

<ItemGroup>
  <FlatSharpSchema Include="Schemas\**\*.fbs">
    <IncludePath>Schemas\</IncludePath>
  </FlatSharpSchema>
</ItemGroup>

ClassLibrary called pkNX.Structures.FlatBuffers.Main With the following properties:

<ItemGroup>
  <ProjectReference Include="..\pkNX.Structures.FlatBuffers.Shared\pkNX.Structures.FlatBuffers.Shared.csproj" />
</ItemGroup>

<PropertyGroup>
  <FlatSharpDeserializers>GreedyMutable</FlatSharpDeserializers>
  <FlatSharpInputFilesOnly>true</FlatSharpInputFilesOnly>
</PropertyGroup>

<ItemGroup>
  <FlatSharpSchema Include="Schemas\**\*.fbs">
    <IncludePath>Schemas\</IncludePath>
    <IncludePath>..\pkNX.Structures.FlatBuffers.Shared\Schemas\</IncludePath>
  </FlatSharpSchema>
</ItemGroup>

This generates the following warning: .\pkNX.Structures.FlatBuffers.SWSH\..\FlatSharp.generated.cs(171497,21,171497,25): warning CS0436: The type 'AABB' in '.\pkNX.Structures.FlatBuffers.SWSH\..\FlatSharp.generated.cs' conflicts with the imported type 'AABB' in 'pkNX.Structures.FlatBuffers.Shared, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. Using the type defined in '.\pkNX.Structures.FlatBuffers.SWSH\..\FlatSharp.generated.cs'.

I can see that in both files it still generates the partial class for both projects in their FlatSharp.generated.cs. I'm guessing I just need to edit the project setup?

(Everything else is working wonderfully btw. Very happy with the new features :D)