AArnott / CodeGeneration.Roslyn

Assists in performing Roslyn-based code generation during a build.
Microsoft Public License
408 stars 59 forks source link

Access CompilationGenerator properties from ICodeGenerator #49

Closed amerkoleci closed 5 years ago

amerkoleci commented 7 years ago

Hi, I would like to know if is possible t access to properties like IntermediateOutputDirectory?

I'm creating different file from cs using the ICodeGenerator logic.

AArnott commented 7 years ago

Not currently. I think if we wanted to support generating additional files we'd want to expose proper support for that rather than just expose the intermediate output directory, since this would feed into incremental build checks. Do you need to control the name of the file being generated?

amerkoleci commented 7 years ago

I would like to parse the cs file and generate a shader hlsl file in the obj, intermediate dir, is this possible?

amerkoleci commented 7 years ago

I have something like this:

[ShaderProgram("HelloWorld")]
public class TestHelloWorldShaderProgram 
{
                [ShaderModule(ShaderStage.Vertex)]
        public PSInput VertexShader(VSInput input)
        {
                      ......
                }
}

I already generate with syntax walker the hlsl logic but at the moment I save the hlsl file to pass to fxc compiler under temp path.

AArnott commented 7 years ago

How do you influence the rest of the build to pick up your generated file?

amerkoleci commented 7 years ago

After ending the fxc compilation logic i read the compiled hlsl bytecode and generate class with roslyn with the bytecode as property

AArnott commented 7 years ago

So are you reading files from the intermediate output directory, or writing to it, or both?

amerkoleci commented 7 years ago

From the original cs file i generate hlsl under temp path, the invoke fxc compiler with generated hlsl then i use the roslyn method to generate new cs class with the bytecode embedded as field

AArnott commented 7 years ago

Why not use an embedded resource for storing the binary data?

AArnott commented 7 years ago

I know nothing about the Shader domain in case that wasn't obvious. So please forgive my ignorance.

amerkoleci commented 7 years ago

How can i generate embedded resource during ICodeGenerator logic?

AArnott commented 7 years ago

You can't. ICodeGenerator only lets you add compilation units (source files). But my question was more around trying to understand why your transform does C#->HSLS->fxc->C# and what value that adds to the developer. It seems odd to embed compiled binary code into C# source. When I add a binary file to an assembly, it's via embedded resources instead of as a byte[] usually.

amerkoleci commented 7 years ago

The value is that I can use C# as input language with all the power of c# and have compilation errors the transpile to hlsl or even different languages like GLSL or Metal

AArnott commented 7 years ago

Can you delete the intermediate files when you're done? Is there any value to leaving them around? Perhaps for incremental builds?

amis92 commented 5 years ago

Supporting additional files in one or another form is not currently on this project's roadmap, and isn't expected in foreseeable future.