otavepto / gbe_fork

Fork of https://gitlab.com/Mr_Goldberg/goldberg_emulator
https://gitlab.com/Mr_Goldberg/goldberg_emulator
GNU Lesser General Public License v3.0
185 stars 54 forks source link

Premake #184

Closed Detanup01 closed 1 month ago

Detanup01 commented 1 month ago

Yes it would make an every single one so yeah.

178 #149

(Using C++latest when building) (using Premake for this)

premake5.exe --os=windows --file="PATHTO\premake5.lua" vs2022 premake5.exe --os=linux --file="PATHTO\premake5.lua" gmake or replace gmake to gmake2

Today I had enough for this, will be checking and trying to understand it.

Sometimes I think would be easier to just write a C# app for building these :D

for vs: G:/VisualStudio/VS_2022/MSBuild/Current/Bin/amd64/MSBuild.exe SteamClient.vcxproj /p:Configuration=Release /p:Platform=Win32 -v:n

G:/VisualStudio/VS_2022/MSBuild/Current/Bin/amd64/MSBuild.exe GBE.sln /p:Configuration=ExperimentalRelease /p:Platform=x64 -v:n

otavepto commented 1 month ago

apparently you've triggered some bug in Github, the workflow was finished but Github still thinks it's pending for 4hr 😄

Detanup01 commented 1 month ago

:D bugs everywhere.

Detanup01 commented 1 month ago

If you could search for "gmake" under gcc or clang (whichever we want to use) and build with it I will try on my laptop VM

otavepto commented 1 month ago

I'll definitely try everything once I'm home, excited for this actually.

Detanup01 commented 1 month ago

now only need to be in the dir. current "ubuntu for windows" is fucking with me in this perspective :P

Detanup01 commented 1 month ago

oh btw because i predefining optimize "On" symbols "Off" my building on windows and linux is soo much smaller. even in debug mode, lol.

23MB from github action 5MB when building with this. and probably I even include things that I dont need :D

Detanup01 commented 1 month ago

check the newest script so you could do it easily. to build another script top of it and it will build all :DD or use these separate github actions for it

Detanup01 commented 1 month ago

You can test Linux and Windows with these dll's/so's: https://pixeldrain.com/u/REud2FDh

otavepto commented 1 month ago

I think I have to apologize for the agony of reading bash/batch scripts 😄
It works very well on Windows and Linux. One thing I don't know how to solve for Linux is bundling all archives statically inside the output .so, similar to static linking against .lib files on Windows The relevant switch is supposed to look like this

-Wl,--whole-archive -Wl,-Bstatic -lz -lcurl -lprotobuf ... -Wl,-Bdynamic -Wl,--no-whole-archive

This ensures that the output .so won't require these libraries at runtime. Unfortunately the order of these args is important

  1. -Wl,--whole-archive -Wl,-Bstatic (turn on static linking + whole archive bundling)
  2. List of libs (they will linked statically now and bundled entirely inside the output .so)
  3. -Wl,-Bdynamic -Wl,--no-whole-archive (turn off static linking + whole archive bundling)

But the generated GBE_Build\SteamEmu\Makefile looks like this (no static linking or whole archiving)

LIBS += -lpthread -ldl -lssq -lz -lcurl -lprotobuf-lite -lmbedcrypto -lingame_overlay -lsystem -lmini_detour

And later the args are just appended together without the -lmylib in between like this

ALL_LDFLAGS += $(LDFLAGS) -L../../build/deps/linux/libssq/build64 -L../../build/deps/linux/curl/install64/lib -L../../build/deps/linux/protobuf/install64/lib -L../../build/deps/linux/zlib/install64/lib -L../../build/deps/linux/mbedtls/install64/lib -L../../build/deps/linux/ingame_overlay/install64/lib -L../../build/deps/linux/ingame_overlay/deps/System/install64/lib -L../../build/deps/linux/ingame_overlay/deps/mini_detour/install64/lib -L/usr/lib64 -m64 -shared -Wl,-soname=libsteam_api64.so -s -Wl,--whole-archive -Wl,-Bstatic -Wl,-Bdynamic -Wl,--no-whole-archive -Wl,--exclude-libs,ALL

You can use this on Windows to check the import table of the .so (similar to CFF explorer and works on Windows): https://github.com/horsicq/XELFViewer The libraries should preferably contain only these 4 image

I don't know how to do that in premake

Detanup01 commented 1 month ago

If you build with vs22 some flags already applied and probably some for Linux too

Detanup01 commented 1 month ago

DYNAMICBASE for example in vs22 already runs with it. If you run the script you can see it (that's why the -v:n thing so you can see the thing that it will run)

Detanup01 commented 1 month ago

Lol found out how you doing static links.

links { "SDL2:static", "SDL2_image:static" }

otavepto commented 1 month ago

for linux static linking I'm passing -Bstatic to the linker: https://linux.die.net/man/1/ld I've reverted the duplicate flags you mentioned

Detanup01 commented 1 month ago

I testing if :static will works in local machine , will check and if it do I push it for linux (does it need for windows too?)

Detanup01 commented 1 month ago

nearly works but crying for lpthread being linked staticly and that dlopen is being a bitch too

Detanup01 commented 1 month ago

everything works except pthread and ld. do we really need to link those into it?

otavepto commented 1 month ago

yeah this is what I was saying above, we have to turn off this option after specifying the ones we need only, we can't keep it turned on forever

-Wl,-Bstatic -lmylib_1 -lmylib_2 -Wl,-Bdynamic

notice how it must be turned off at the end via -Wl,-Bdynamic it isn't necessary, but without it, it would introduce another painful runtime linking problem for people who do not have these libraries installed, we all know how smooth that would turn out at the end. this is a more prominent problem on linux than windows since there are many distros with different libraries installed by default

Edit: I just realized, I never said thank you 😄 thank you so much of course

Detanup01 commented 1 month ago

aint those libraries auto installed? or by steam itself ? i bet something like libc++ and some of those already get downloaded

otavepto commented 1 month ago

zlib for example was in the import table, I'm sure that would be lacking on some distros. The assumption that a library might be installed by default defies the purpose of deps in the first place. It would be honestly just easier for us to list them in a text/md file and tell everyone "install and link them from directory build/deps/, lol have fun" 😄 But I personally had the worst time building this thing 2 years ago because of that and created a local fork for that reason alone, building ungoogled-chromium was much easier!

Everything looks good to me, feel free to merge any time 👍

Detanup01 commented 1 month ago

merging would require change in the build script. also ye, you was right it was zlib imported but no longer! I plan to include all things into the main premake5.lua because pre_make_more.lua is just a cut from the main one and didnt have most of the things. I wanted to successfully make it and it was good. Next would be implementing all those that I cutted out. If you could make a workflow for it I be glad since I have little knowladge about that and seems you have more in that field :D I probably continue it with next week and if I have time this weekend too.

Detanup01 commented 1 month ago

quick question. because it errors out so many time do you want me to fix those errors or nah. example: all strcpy to strcpy_s and when doing x.size() i do (type we want)x.size();

otavepto commented 1 month ago

Nah forget about the errors for now they're too much, we can do them later on, _CRT_SECURE_NO_WARNINGS is fine for now. I just discovered that premake appends stuff which is a huge potential to reduce duplicates, I'll refactor it and see if it works. example:


    -- defines
    ---------
    filter {} -- reset the filter and remove all active keywords
    defines { -- added to all filters, later defines will be appended
        "UTF_CPP_CPLUSPLUS=201703L", "CURL_STATICLIB", "CONTROLLER_SUPPORT", "EMU_BUILD_STRING=".._OPTIONS["emubuild"]
    }
    -- release mode defines
    filter { "configurations:Release or ExperimentalRelease" }
        defines {
            "NDEBUG", "EMU_RELEASE_BUILD",
        }
    -- debug mode defines
    filter { "configurations:Debug or ExperimentalDebug" }
        defines {
            "DEBUG",
        }

    -- Windows defines
    filter "options:os=windows"
        defines {
            "_CRT_SECURE_NO_WARNINGS",
        }

    -- Linux defines
    filter { "options:os=linux" }
        defines {
            "GNUC",
        }

The above code produced proper defines, they are appended, not overwritten 🎉

Detanup01 commented 1 month ago

OHH thank you. and okay :D

otavepto commented 1 month ago

damn I never realized how confusing the different builds look on linux:

on windows:

even reading that makes me confused as hell. wow

Detanup01 commented 1 month ago

Yeah a little confusing that's why i want to finish the windows first then Linux

otavepto commented 1 month ago

Let me know any time/day/week/month you feel like it's looking good and almost complete, and I'll create/edit the workflows for you. Edit: Made a quick matrix-based one, too wasteful since it builds all possible combinations, will optimize it later.

Detanup01 commented 1 month ago

I probably port over your thing and edit a little if you can please don't delete your branch in this week

Detanup01 commented 1 month ago

I think it is okay now. we might need to add more stuff but currently its okay. Will check back in some other day but this is good now

otavepto commented 1 month ago

Tons of thanks for this, thank you so much. I've merged it as it's indeed a very good base to continue on. Feel free to change/enhance/modify it any time, either via PR or directly pushing to dev.