1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-08 03:28:20 +02:00

Removed "Dynamic Library" target type, replaced by Build Kind

This commit is contained in:
Brian Fiete 2021-06-28 09:44:47 -07:00
parent 1c1cb1ac49
commit 7ae8599916
8 changed files with 163 additions and 98 deletions

View file

@ -296,7 +296,7 @@ namespace IDE
bool isTest = options.mBuildOptions.mBuildKind == .Test;
bool isExe = ((project.mGeneralOptions.mTargetType != Project.TargetType.BeefLib) && (project.mGeneralOptions.mTargetType != Project.TargetType.BeefTest)) || (isTest);
bool isDynLib = project.mGeneralOptions.mTargetType == Project.TargetType.BeefDynLib;
bool isDynLib = (project.mGeneralOptions.mTargetType == Project.TargetType.BeefLib) && (options.mBuildOptions.mBuildKind == .DynamicLib);
if (options.mBuildOptions.mBuildKind == .StaticLib)
isExe = false;
@ -525,7 +525,7 @@ namespace IDE
bool isTest = options.mBuildOptions.mBuildKind == .Test;
bool isExe = ((project.mGeneralOptions.mTargetType != Project.TargetType.BeefLib) && (project.mGeneralOptions.mTargetType != Project.TargetType.BeefTest)) || (isTest);
bool isDynLib = project.mGeneralOptions.mTargetType == Project.TargetType.BeefDynLib;
bool isDynLib = (project.mGeneralOptions.mTargetType == Project.TargetType.BeefLib) && (options.mBuildOptions.mBuildKind == .DynamicLib);
if (isExe || isDynLib)
{
@ -761,7 +761,8 @@ namespace IDE
}
}
if (depProject.mGeneralOptions.mTargetType == .BeefDynLib)
bool depIsDynLib = (depProject.mGeneralOptions.mTargetType == Project.TargetType.BeefLib) && (depOptions.mBuildOptions.mBuildKind == .DynamicLib);
if (depIsDynLib)
{
if (mImpLibMap.TryGetValue(depProject, var libPath))
{
@ -797,9 +798,9 @@ namespace IDE
bool isTest = options.mBuildOptions.mBuildKind == .Test;
bool isExe = ((project.mGeneralOptions.mTargetType != Project.TargetType.BeefLib) && (project.mGeneralOptions.mTargetType != Project.TargetType.BeefTest)) || (isTest);
if (options.mBuildOptions.mBuildKind == .StaticLib)
isExe = false;
if (options.mBuildOptions.mBuildKind == .DynamicLib)
isExe = true;
if (isExe)
{
String linkLine = scope String();
@ -814,7 +815,7 @@ namespace IDE
linkLine.Append("-subsystem:windows ");
else if (project.mGeneralOptions.mTargetType == .C_GUIApplication)
linkLine.Append("-subsystem:console ");
else if (project.mGeneralOptions.mTargetType == .BeefDynLib)
else if (project.mGeneralOptions.mTargetType == .BeefLib)
{
linkLine.Append("-dll ");
@ -885,7 +886,7 @@ namespace IDE
linkLine.Append("-nologo ");
if ((project.mGeneralOptions.mTargetType == .BeefDynLib) && (workspaceOptions.mAllowHotSwapping) && (is64Bit))
if ((project.mGeneralOptions.mTargetType == .BeefLib) && (workspaceOptions.mAllowHotSwapping) && (is64Bit))
{
// This helps to ensure that DLLs have enough hot swapping space after them
int nameHash = targetPath.GetHashCode();
@ -1204,7 +1205,7 @@ namespace IDE
Directory.CreateDirectory(targetDir).IgnoreError();
}
if (project.mGeneralOptions.mTargetType == .BeefDynLib)
if (project.mGeneralOptions.mTargetType == .BeefLib)
{
if (targetPath.EndsWith(".dll", .InvariantCultureIgnoreCase))
{

View file

@ -8884,11 +8884,15 @@ namespace IDE
{
if (project.mGeneralOptions.mTargetType.IsBeefApplication)
targetType = .BeefApplication_StaticLib;
else if (project.mGeneralOptions.mTargetType == .BeefLib)
targetType = .BeefLib_Static;
}
else if (options.mBuildOptions.mBuildKind == .DynamicLib)
{
if (project.mGeneralOptions.mTargetType.IsBeefApplication)
targetType = .BeefApplication_DynamicLib;
else if (project.mGeneralOptions.mTargetType == .BeefLib)
targetType = .BeefLib_Dynamic;
}
}
@ -9418,48 +9422,28 @@ namespace IDE
let platformType = Workspace.PlatformType.GetFromName(platformName);
if (options.mBuildOptions.mBuildKind.IsApplicationLib)
switch (platformType)
{
switch (platformType)
{
case .Windows:
case .Windows:
if (options.mBuildOptions.mBuildKind == .DynamicLib)
newString.Append(".dll");
else if ((options.mBuildOptions.mBuildKind == .StaticLib) || (project.mGeneralOptions.mTargetType == .BeefLib))
newString.Append(".lib");
case .iOS:
if (options.mBuildOptions.mBuildKind == .DynamicLib)
newString.Append(".dylib");
else
newString.Append(".a");
case .Wasm:
if (!newString.Contains('.'))
newString.Append(".html");
default:
if (options.mBuildOptions.mBuildKind == .DynamicLib)
newString.Append(".so");
else
newString.Append(".a");
}
}
else
{
switch (platformType)
{
case .Windows:
if (project.mGeneralOptions.mTargetType == .BeefLib)
newString.Append(".lib");
else if (project.mGeneralOptions.mTargetType == .BeefDynLib)
newString.Append(".dll");
else if (project.mGeneralOptions.mTargetType != .CustomBuild)
newString.Append(".exe");
case .macOS:
if (project.mGeneralOptions.mTargetType == .BeefDynLib)
newString.Append(".dylib");
case .Wasm:
if (!newString.Contains('.'))
newString.Append(".html");
default:
if (project.mGeneralOptions.mTargetType == .BeefDynLib)
newString.Append(".so");
}
else if (project.mGeneralOptions.mTargetType != .CustomBuild)
newString.Append(".exe");
case .macOS:
if (options.mBuildOptions.mBuildKind == .DynamicLib)
newString.Append(".dylib");
else if (options.mBuildOptions.mBuildKind == .StaticLib)
newString.Append(".a");
case .Wasm:
if (!newString.Contains('.'))
newString.Append(".html");
default:
if (options.mBuildOptions.mBuildKind == .DynamicLib)
newString.Append(".so");
else if (options.mBuildOptions.mBuildKind == .StaticLib)
newString.Append(".a");
}
}
IDEUtils.FixFilePath(newString);
@ -9480,9 +9464,11 @@ namespace IDE
case "LinkFlags":
newString = scope:ReplaceBlock String();
bool isBeefDynLib = (project.mGeneralOptions.mTargetType == .BeefLib) && (options.mBuildOptions.mBuildKind == .DynamicLib);
if ((project.mGeneralOptions.mTargetType == .BeefConsoleApplication) ||
(project.mGeneralOptions.mTargetType == .BeefGUIApplication) ||
(project.mGeneralOptions.mTargetType == .BeefDynLib) ||
(isBeefDynLib) ||
(options.mBuildOptions.mBuildKind == .Test))
{
let platformType = Workspace.PlatformType.GetFromName(platformName);

View file

@ -866,14 +866,6 @@ namespace IDE
case StaticLib;
case DynamicLib;
case NotSupported;
public bool IsApplicationLib
{
get
{
return (this == .StaticLib) || (this == .DynamicLib);
}
}
}
public enum COptimizationLevel
@ -916,13 +908,14 @@ namespace IDE
case BeefConsoleApplication,
BeefGUIApplication,
BeefLib,
BeefDynLib,
CustomBuild,
BeefTest,
C_ConsoleApplication,
C_GUIApplication,
BeefApplication_StaticLib,
BeefApplication_DynamicLib;
BeefApplication_DynamicLib,
BeefLib_Static,
BeefLib_Dynamic;
public bool IsBeef
{
@ -933,7 +926,6 @@ namespace IDE
case BeefConsoleApplication,
BeefGUIApplication,
BeefLib,
BeefDynLib,
BeefTest:
return true;
default:
@ -956,6 +948,22 @@ namespace IDE
}
}
}
public bool IsBeefApplicationOrLib
{
get
{
switch (this)
{
case BeefConsoleApplication,
BeefGUIApplication,
BeefLib:
return true;
default:
return false;
}
}
}
}
public class WindowsOptions
@ -1863,7 +1871,8 @@ namespace IDE
strs.Add(cmd);
}
}
bool isBeefDynLib = false;
using (data.Open("Project"))
{
if (!IsSingleFile)
@ -1889,6 +1898,9 @@ namespace IDE
mGeneralOptions.mTargetType = .BeefGUIApplication;
case "C_WindowsApplication":
mGeneralOptions.mTargetType = .C_GUIApplication;
case "BeefDynLib":
mGeneralOptions.mTargetType = .BeefLib;
isBeefDynLib = true;
default:
mGeneralOptions.mTargetType = data.GetEnum<TargetType>("TargetType", GetDefaultTargetType());
}
@ -1962,6 +1974,8 @@ namespace IDE
// Build
options.mBuildOptions.mBuildKind = data.GetEnum<BuildKind>("BuildKind", isTest ? .Test : .Normal);
if ((isBeefDynLib) && (options.mBuildOptions.mBuildKind == .Normal))
options.mBuildOptions.mBuildKind = .DynamicLib;
data.GetString("TargetDirectory", options.mBuildOptions.mTargetDirectory, "$(BuildDir)");
data.GetString("TargetName", options.mBuildOptions.mTargetName, "$(ProjectName)");
data.GetString("OtherLinkFlags", options.mBuildOptions.mOtherLinkFlags, "$(LinkFlags)");

View file

@ -16,11 +16,10 @@ namespace IDE.ui
public PathEditWidget mDirectoryEdit;
public EditWidget mNameEdit;
public DarkComboBox mTargetComboBox;
static String[6] sApplicationTypeNames =
static String[5] sApplicationTypeNames =
.("Console Application",
"GUI Application",
"Library",
"Dynamic Library",
"Custom Build",
"Test");
public bool mNameChanged;

View file

@ -622,7 +622,6 @@ namespace IDE.ui
"Console Application",
"GUI Application",
"Library",
"Dynamic Library",
"Custom Build",
"Test"
));

View file

@ -521,11 +521,12 @@ bool BfCompiler::IsTypeUsed(BfType* checkType, BfProject* curProject)
BfTypeInstance* typeInst = checkType->ToTypeInstance();
if (typeInst != NULL)
{
if ((typeInst->mTypeDef->mProject != NULL) && (typeInst->mTypeDef->mProject != curProject))
{
if (typeInst->mTypeDef->mProject->mTargetType == BfTargetType_BeefDynLib)
return false;
}
//TODO: Why was this here?
// if ((typeInst->mTypeDef->mProject != NULL) && (typeInst->mTypeDef->mProject != curProject))
// {
// if (typeInst->mTypeDef->mProject->mTargetType == BfTargetType_BeefDynLib)
// return false;
// }
if (checkType->IsInterface())
return typeInst->mIsReified;
@ -1217,11 +1218,12 @@ void BfCompiler::CreateVData(BfVDataModule* bfModule)
baseType = baseType->mBaseType;
}
if (module->mProject != bfModule->mProject)
{
if ((module->mProject != NULL) && (module->mProject->mTargetType == BfTargetType_BeefDynLib))
continue;
}
//TODO: What was this for?
// if (module->mProject != bfModule->mProject)
// {
// if ((module->mProject != NULL) && (module->mProject->mTargetType == BfTargetType_BeefDynLib))
// continue;
// }
if (typeInst->mHasStaticInitMethod)
sortedStaticInitMap.insert(std::make_pair(bfModule->TypeToString(type), typeInst));
@ -1662,8 +1664,18 @@ void BfCompiler::CreateVData(BfVDataModule* bfModule)
if ((targetType == BfTargetType_BeefWindowsApplication) && (mOptions.mPlatformType != BfPlatformType_Windows))
targetType = BfTargetType_BeefConsoleApplication;
bool isPosixDynLib = (targetType == BfTargetType_BeefDynLib) && (mOptions.mPlatformType != BfPlatformType_Windows);
bool isConsoleApplication = (targetType == BfTargetType_BeefConsoleApplication) || (targetType == BfTargetType_BeefTest);
if ((targetType == BfTargetType_BeefWindowsApplication) && (mOptions.mPlatformType != BfPlatformType_Windows))
isConsoleApplication = true;
bool isDllMain = (targetType == BfTargetType_BeefLib_DynamicLib) && (mOptions.mPlatformType == BfPlatformType_Windows);
bool isPosixDynLib = ((targetType == BfTargetType_BeefLib_DynamicLib) || (targetType == BfTargetType_BeefLib_StaticLib)) &&
(mOptions.mPlatformType != BfPlatformType_Windows);
bool mainHasArgs = (targetType != BfTargetType_BeefLib_DynamicLib) && (targetType != BfTargetType_BeefLib_StaticLib) &&
(mOptions.mPlatformType != BfPlatformType_Wasm);
bool mainHasRet = (targetType != BfTargetType_BeefLib_DynamicLib) && (targetType != BfTargetType_BeefLib_StaticLib);
// Generate "main"
if (!IsHotCompile())
{
@ -1671,7 +1683,9 @@ void BfCompiler::CreateVData(BfVDataModule* bfModule)
BfIRFunctionType mainFuncType;
BfIRFunction mainFunc;
if ((targetType == BfTargetType_BeefConsoleApplication) || (targetType == BfTargetType_BeefTest))
BfIRFunctionType shutdownFuncType;
BfIRFunction shutdownFunc;
if (isConsoleApplication)
{
SmallVector<BfIRType, 2> paramTypes;
paramTypes.push_back(int32Type);
@ -1680,7 +1694,7 @@ void BfCompiler::CreateVData(BfVDataModule* bfModule)
mainFunc = bfModule->mBfIRBuilder->CreateFunction(mainFuncType, BfIRLinkageType_External, "main");
bfModule->SetupIRMethod(NULL, mainFunc, false);
}
else if (targetType == BfTargetType_BeefDynLib)
else if (isDllMain)
{
SmallVector<BfIRType, 4> paramTypes;
paramTypes.push_back(nullPtrType); // hinstDLL
@ -1708,15 +1722,43 @@ void BfCompiler::CreateVData(BfVDataModule* bfModule)
}
else
{
SmallVector<BfIRType, 2> paramTypes;
if (mOptions.mPlatformType != BfPlatformType_Wasm)
BfIRFunction combinedFunc;
SmallVector<BfIRType, 2> paramTypes;
if (mainHasArgs)
{
paramTypes.push_back(int32Type);
paramTypes.push_back(nullPtrType);
}
mainFuncType = bfModule->mBfIRBuilder->CreateFunctionType(int32Type, paramTypes, false);
mainFunc = bfModule->mBfIRBuilder->CreateFunction(mainFuncType, BfIRLinkageType_External, "BeefMain");
mainFuncType = bfModule->mBfIRBuilder->CreateFunctionType(mainHasRet ? int32Type : voidType, paramTypes, false);
mainFunc = bfModule->mBfIRBuilder->CreateFunction(mainFuncType, BfIRLinkageType_External, "BeefStart");
bfModule->SetupIRMethod(NULL, mainFunc, false);
combinedFunc = bfModule->mBfIRBuilder->CreateFunction(mainFuncType, BfIRLinkageType_External, "BeefMain");
bfModule->SetupIRMethod(NULL, combinedFunc, false);
paramTypes.clear();
shutdownFuncType = bfModule->mBfIRBuilder->CreateFunctionType(voidType, paramTypes, false);
shutdownFunc = bfModule->mBfIRBuilder->CreateFunction(shutdownFuncType, BfIRLinkageType_External, "BeefStop");
bfModule->SetupIRMethod(NULL, shutdownFunc, false);
bfModule->mBfIRBuilder->SetActiveFunction(combinedFunc);
auto entryBlock = bfModule->mBfIRBuilder->CreateBlock("entry", true);
bfModule->mBfIRBuilder->SetInsertPoint(entryBlock);
SmallVector<BfIRValue, 1> args;
if (mainHasArgs)
{
args.push_back(bfModule->mBfIRBuilder->GetArgument(0));
args.push_back(bfModule->mBfIRBuilder->GetArgument(1));
}
auto res = bfModule->mBfIRBuilder->CreateCall(mainFunc, args);
args.clear();
bfModule->mBfIRBuilder->CreateCall(shutdownFunc, args);
if (mainHasArgs)
bfModule->mBfIRBuilder->CreateRet(res);
else
bfModule->mBfIRBuilder->CreateRetVoid();
}
bfModule->mBfIRBuilder->SetActiveFunction(mainFunc);
@ -1746,13 +1788,16 @@ void BfCompiler::CreateVData(BfVDataModule* bfModule)
bfModule->SetupIRMethod(NULL, setCmdLineFunc, false);
SmallVector<BfIRValue, 2> args;
args.push_back(bfModule->mBfIRBuilder->GetArgument(0));
args.push_back(bfModule->mBfIRBuilder->GetArgument(1));
if (mainHasArgs)
{
args.push_back(bfModule->mBfIRBuilder->GetArgument(0));
args.push_back(bfModule->mBfIRBuilder->GetArgument(1));
}
bfModule->mBfIRBuilder->CreateCall(setCmdLineFunc, args);
}
BfIRBlock initSkipBlock;
if (targetType == BfTargetType_BeefDynLib)
if (isDllMain)
{
auto initBlock = bfModule->mBfIRBuilder->CreateBlock("doInit", false);
initSkipBlock = bfModule->mBfIRBuilder->CreateBlock("skipInit", false);
@ -1960,18 +2005,19 @@ void BfCompiler::CreateVData(BfVDataModule* bfModule)
if (!hadRet)
retValue = bfModule->GetConstValue32(0);
}
else if (targetType == BfTargetType_BeefDynLib)
}
else
{
retValue = bfModule->GetConstValue32(1);
if (mainHasRet)
retValue = bfModule->GetConstValue32(1);
}
if (targetType == BfTargetType_BeefTest)
EmitTestMethod(bfModule, testMethods, retValue);
BfIRBlock deinitSkipBlock;
if (targetType == BfTargetType_BeefDynLib)
{
if (isDllMain)
{
auto deinitBlock = bfModule->mBfIRBuilder->CreateBlock("doDeinit", false);
deinitSkipBlock = bfModule->mBfIRBuilder->CreateBlock("skipDeinit", false);
auto cmpResult = bfModule->mBfIRBuilder->CreateCmpEQ(bfModule->mBfIRBuilder->GetArgument(1), bfModule->mBfIRBuilder->CreateConst(BfTypeCode_Int32, 0));
@ -1982,6 +2028,14 @@ void BfCompiler::CreateVData(BfVDataModule* bfModule)
if (mOptions.mPlatformType != BfPlatformType_Wasm)
{
auto prevBlock = bfModule->mBfIRBuilder->GetInsertBlock();
if (shutdownFunc)
{
bfModule->mBfIRBuilder->SetActiveFunction(shutdownFunc);
auto entryBlock = bfModule->mBfIRBuilder->CreateBlock("entry", true);
bfModule->mBfIRBuilder->SetInsertPoint(entryBlock);
}
bfModule->mBfIRBuilder->CreateCall(dtorFunc, SizedArray<BfIRValue, 0>());
BfModuleMethodInstance shutdownMethod = bfModule->GetInternalMethod("Shutdown");
@ -1989,6 +2043,13 @@ void BfCompiler::CreateVData(BfVDataModule* bfModule)
{
bfModule->mBfIRBuilder->CreateCall(shutdownMethod.mFunc, SizedArray<BfIRValue, 0>());
}
if (shutdownFunc)
{
bfModule->mBfIRBuilder->CreateRetVoid();
bfModule->mBfIRBuilder->SetActiveFunction(mainFunc);
bfModule->mBfIRBuilder->SetInsertPoint(prevBlock);
}
}
if (deinitSkipBlock)
@ -6772,7 +6833,7 @@ bool BfCompiler::DoCompile(const StringImpl& outputDirectory)
}
if ((bfProject->mTargetType != BfTargetType_BeefConsoleApplication) && (bfProject->mTargetType != BfTargetType_BeefWindowsApplication) &&
(bfProject->mTargetType != BfTargetType_BeefDynLib) &&
(bfProject->mTargetType != BfTargetType_BeefLib_DynamicLib) && (bfProject->mTargetType != BfTargetType_BeefLib_StaticLib) &&
(bfProject->mTargetType != BfTargetType_C_ConsoleApplication) && (bfProject->mTargetType != BfTargetType_C_WindowsApplication) &&
(bfProject->mTargetType != BfTargetType_BeefTest) &&
(bfProject->mTargetType != BfTargetType_BeefApplication_StaticLib) && (bfProject->mTargetType != BfTargetType_BeefApplication_DynamicLib))
@ -9072,8 +9133,9 @@ BF_EXPORT const char* BF_CALLTYPE BfCompiler_GetUsedOutputFileNames(BfCompiler*
canReference = false;
if (bfProject != project)
{
if (project->mTargetType == BfTargetType_BeefDynLib)
canReference = false;
//TODO: What was this for?
// if (project->mTargetType == BfTargetType_BeefDynLib)
// canReference = false;
}
}
if (!canReference)

View file

@ -16121,7 +16121,10 @@ void BfModule::SetupIRMethod(BfMethodInstance* methodInstance, BfIRFunction func
if (methodInstance->mReturnType->IsVar())
mBfIRBuilder->Func_AddAttribute(func, -1, BfIRAttribute_VarRet);
if (methodDef->mImportKind == BfImportKind_Export)
mBfIRBuilder->Func_AddAttribute(func, -1, BFIRAttribute_DllExport);
{
if (methodDef->mDeclaringType->mProject->mTargetType != BfTargetType_BeefLib_StaticLib)
mBfIRBuilder->Func_AddAttribute(func, -1, BFIRAttribute_DllExport);
}
if (methodDef->mIsNoReturn)
mBfIRBuilder->Func_AddAttribute(func, -1, BfIRAttribute_NoReturn);
auto callingConv = GetIRCallingConvention(methodInstance);

View file

@ -1123,14 +1123,15 @@ enum BfTargetType
{
BfTargetType_BeefConsoleApplication,
BfTargetType_BeefWindowsApplication,
BfTargetType_BeefLib,
BfTargetType_BeefDynLib,
BfTargetType_BeefLib,
BfTargetType_CustomBuild,
BfTargetType_BeefTest,
BfTargetType_C_ConsoleApplication,
BfTargetType_C_WindowsApplication,
BfTargetType_BeefApplication_StaticLib,
BfTargetType_BeefApplication_DynamicLib
BfTargetType_BeefApplication_DynamicLib,
BfTargetType_BeefLib_StaticLib,
BfTargetType_BeefLib_DynamicLib,
};
enum BfProjectFlags