Git Product home page Git Product logo

Comments (8)

MichalStrehovsky avatar MichalStrehovsky commented on July 29, 2024 1

The way bflat is structured is really no different from how clang, gcc, or other native compilers are structured. They scale to the extent of Linux kernel, Chromium browser, etc. with thousands of files.

bflat build foo.cs bar.cs produces an executable you can run (same way gcc foo.c produces an executable). This is for quick consumption with small things.

But you can also do:

bflat build-il foo.cs bar.cs -o:MyAssembly.dll
bflat build program.cs -r:MyAssembly.dll

The first invocation produces an equivalent of a library csproj. The second invocation uses the library to create an executable (equivalent of Exe csproj).

Depending on what you want to achieve, you can also do:

bflat build -c program.cs

This is the same as the -c argument to clang: it says compile to object file, but don't run the linker. You can then run the linker manually. (You can use bflat build -x program.cs to have bflat tell you how it invokes the linker so that you know the correct invocation as a starting point.)

from bflat.

MichalStrehovsky avatar MichalStrehovsky commented on July 29, 2024

bflat build without specifying the input files will look for any *.cs files in the current directory. If you need more control, you would specify the file names explicitly.

Bflat is just a compiler, not a build system. If the build is more complex, one would drive this from a build system. Makefiles, or even MSBuild targets.

from bflat.

AudriusButkevicius avatar AudriusButkevicius commented on July 29, 2024

Sure, but if you have anything more than a few files this somewhat becomes unfeasible. Its also not clear how linking etc would work.

One example that I have in mind is for example game modding.

Currently I have to a solution with a project that declares base types for modding, and then a project per mod that uses the types from the base project.

I then compile the mod project, have a small C++ dll that injects the CLR into the game and loads the mods via dynamic assembly loading.

Ideally I'd like to avoid having to load the CLR and compile the mods (including project and nuget deps) to native code and inject them directly. Is that possible with this compiler or is this only usable for 2-3 file projects?

from bflat.

voronoipotato avatar voronoipotato commented on July 29, 2024

You'd have to change the way you write and structure code but there's genuinely no reason you couldn't do this with 150+ file projects. This is less of a problem for F# since we (culturally) don't rely on that kind of polymorphism as much but there's no actual strict need to write your C# that way.

from bflat.

AudriusButkevicius avatar AudriusButkevicius commented on July 29, 2024

Can you elaborate how the code should be structured?

Also how to deal with nuget dependency graph?

from bflat.

voronoipotato avatar voronoipotato commented on July 29, 2024

For your own code you should be able to essentially treat folders as projects using namespaces etc as you do in C# normally. For nuget you'll have to be more careful with what packages/versions you choose. If it becomes intractable there are tools like paket which are allow for more fine grained control and flexibility with package resolution. If my current understanding is correct, you probably won't be able to write your project with the kind of runtime modular approach that you're used to, so you should design with that in mind.

from bflat.

AudriusButkevicius avatar AudriusButkevicius commented on July 29, 2024

Thanks.

Can library outputs have a dll entrypoint (DllMain)? Not obvious how to declare that from c# or how that gets exposed? Also, not obvious how to export symbols from your dlls as C ABI (I assume thats the usecase for supporting compiling to libraries)

I guess it's a lot of manual work to do that for the whole solution but I'll give it a go see how far I get.

from bflat.

MichalStrehovsky avatar MichalStrehovsky commented on July 29, 2024

If you have existing project files, you can just drive bflat from MSBuild.

Bflat builds with bflat, but the bflat command line is constructed by MSBuild:

<ItemGroup>
<BflatArg Include="@(Compile->'&quot;%(Identity)&quot;')" />
<BflatArg Include="--os:%(SupportedHost.OS)" />
<BflatArg Include="--arch:%(SupportedHost.Arch)" />
<BflatArg Include="--no-globalization" />
<BflatArg Include="--no-exception-messages" />
<BflatArg Include="--no-pie" />
<BflatArg Include="-o:&quot;$(LayoutsDirectory)%(SupportedHost.Identity)\$(BflatName)&quot;" />
<BflatArg Include="@(RuntimeCopyLocalItems->'-r:&quot;%(Identity)&quot;')" />
</ItemGroup>
<WriteLinesToFile File="$(IntermediateLayoutOutputPath)\runbflat.rsp"
Lines="@(BflatArg)"
Overwrite="true"
WriteOnlyWhenDifferent="true" />
<Exec Command="&quot;$(RunCommand)&quot; build @&quot;$(IntermediateLayoutOutputPath)\runbflat.rsp&quot;" />

(Or you can just use the built-in PublishAot option and skip bflat completely. The main advantage of bflat is in the seamless crosscompilation and ability to use without MSBuild. If you don't need that, just go with the built-in thing).

Can library outputs have a dll entrypoint (DllMain)

DllMain is not directly exposed because running managed code under loader lock would be asking for trouble. You can use [ModuleInitializer] to sort of get similar semantics.

Also, not obvious how to export symbols from your dlls as C ABI

Did you see the sample?

from bflat.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.