Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bazel run/bazel test only work in specific circumstances #9

Open
j3parker opened this issue Sep 6, 2019 · 1 comment
Open

bazel run/bazel test only work in specific circumstances #9

j3parker opened this issue Sep 6, 2019 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@j3parker
Copy link
Member

j3parker commented Sep 6, 2019

Normally in C# you put all of your DLLs in one folder, and they are loaded based on filename (the full details are more complex).

In Bazel, when you have a target with dependencies in a different folder it will fail to run because the DLL can't be found.

Solutions that probably won't work:

  • Copying DLLs: in a large project like D2L this would become a performance/disk space issue.
  • app.config: you can use <probing> to add subdirectories for the loader to consider. The problem is you can't use .. so this won't handle all cases.

What I think will work:

Have an extra action that produces a shim exe, and also write the real exe path and the list of transitive dependencies to a txt file. The shim exe's Main function:

  1. Reads the txt file into a read only dictionary from Path.GetFilenameWithoutExtension to the path to the DLL
  2. hooks into the AssemblyLoad event and uses the list from (1) to resolve DLLs
  3. Loads the real exe assembly
  4. Calls the real Main( args ) (caution: Main() vs Main( string[] args ).. the runner would need to do the right thing).

In our DefaultInfo for executable rules we point at that shim, with the txt file as a runfile.

This probably makes sense to do after #8 because we should only need to make this exe once (probably for the latest .NET Core version?) but we could also do it for just .NET Framework first too.

@j3parker j3parker added this to the Generally usable milestone Sep 8, 2019
j3parker added a commit that referenced this issue Sep 11, 2019
This goes towards #9, but doesn't fix it. We still need to deal with how
these files aren't all collected into a single directory.
@j3parker j3parker self-assigned this Sep 11, 2019
j3parker added a commit that referenced this issue Sep 11, 2019
This goes towards #9, but doesn't fix it. We still need to deal with how
these files aren't all collected into a single directory.
j3parker added a commit that referenced this issue Sep 11, 2019
This goes towards #9, but doesn't fix it. We still need to deal with how
these files aren't all collected into a single directory.
@j3parker
Copy link
Member Author

I've got this broadly working but it doesn't make sense to check in until we support net48 + netcoreapp2.1 (the newest target frameworks that can produce exes).

I'm still investigating how runfiles work under the hood to see what stuff we have to DIY.

@j3parker j3parker added the bug Something isn't working label Sep 21, 2019
j3parker added a commit to j3parker/rules_csharp that referenced this issue Mar 7, 2020
csharp_binary needs to become a rule which emits a cc_binary that
invokes "dotnet <foo>", where "<foo>" is the actual *.dll that we
compile, to solve Brightspace#71. Eventually <foo> will become a wrapper C# exe
that tweaks assembly loading to solve Brightspace#9. So all of this requires the
wrapper to provide a default argv[1].

For stuff like dotnet vstest (Brightspace#51) we will have argv[1] = vstest, so we
also need support for baking in argv[2].
j3parker added a commit to j3parker/rules_csharp that referenced this issue Mar 7, 2020
csharp_binary needs to become a rule which emits a cc_binary that
invokes "dotnet <foo>", where "<foo>" is the actual *.dll that we
compile, to solve Brightspace#71. Eventually <foo> will become a wrapper C# exe
that tweaks assembly loading to solve Brightspace#9. So all of this requires the
wrapper to provide a default argv[1].

For stuff like dotnet vstest (Brightspace#51) we will have argv[1] = vstest, so we
also need support for baking in argv[2].
j3parker added a commit to j3parker/rules_csharp that referenced this issue Mar 7, 2020
csharp_binary needs to become a rule which emits a cc_binary that
invokes "dotnet <foo>", where "<foo>" is the actual *.dll that we
compile, to solve Brightspace#71. Eventually <foo> will become a wrapper C# exe
that tweaks assembly loading to solve Brightspace#9. So all of this requires the
wrapper to provide a default argv[1].

For stuff like dotnet vstest (Brightspace#51) we will have argv[1] = vstest, so we
also need support for baking in argv[2].
j3parker added a commit to j3parker/rules_csharp that referenced this issue Mar 7, 2020
csharp_binary needs to become a rule which emits a cc_binary that
invokes "dotnet <foo>", where "<foo>" is the actual *.dll that we
compile, to solve Brightspace#71. Eventually <foo> will become a wrapper C# exe
that tweaks assembly loading to solve Brightspace#9. So all of this requires the
wrapper to provide a default argv[1].

For stuff like dotnet vstest (Brightspace#51) we will have argv[1] = vstest, so we
also need support for baking in argv[2].
j3parker added a commit to j3parker/rules_csharp that referenced this issue Mar 7, 2020
csharp_binary needs to become a rule which emits a cc_binary that
invokes "dotnet <foo>", where "<foo>" is the actual *.dll that we
compile, to solve Brightspace#71. Eventually <foo> will become a wrapper C# exe
that tweaks assembly loading to solve Brightspace#9. So all of this requires the
wrapper to provide a default argv[1].

For stuff like dotnet vstest (Brightspace#51) we will have argv[1] = vstest, so we
also need support for baking in argv[2].
j3parker added a commit to j3parker/rules_csharp that referenced this issue Mar 7, 2020
csharp_binary needs to become a rule which emits a cc_binary that
invokes "dotnet <foo>", where "<foo>" is the actual *.dll that we
compile, to solve Brightspace#71. Eventually <foo> will become a wrapper C# exe
that tweaks assembly loading to solve Brightspace#9. So all of this requires the
wrapper to provide a default argv[1].

For stuff like dotnet vstest (Brightspace#51) we will have argv[1] = vstest, so we
also need support for baking in argv[2].
j3parker added a commit to j3parker/rules_csharp that referenced this issue Mar 7, 2020
csharp_binary needs to become a rule which emits a cc_binary that
invokes "dotnet <foo>", where "<foo>" is the actual *.dll that we
compile, to solve Brightspace#71. Eventually <foo> will become a wrapper C# exe
that tweaks assembly loading to solve Brightspace#9. So all of this requires the
wrapper to provide a default argv[1].

For stuff like dotnet vstest (Brightspace#51) we will have argv[1] = vstest, so we
also need support for baking in argv[2].
j3parker added a commit that referenced this issue Mar 7, 2020
csharp_binary needs to become a rule which emits a cc_binary that
invokes "dotnet <foo>", where "<foo>" is the actual *.dll that we
compile, to solve #71. Eventually <foo> will become a wrapper C# exe
that tweaks assembly loading to solve #9. So all of this requires the
wrapper to provide a default argv[1].

For stuff like dotnet vstest (#51) we will have argv[1] = vstest, so we
also need support for baking in argv[2].
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant