mesonbuild / mesonbuild/meson

C# compiler 'csc.exe' can't resolve the provided path

Open
#7,375 0 comments 0 reactions 0 assignees View on GitHub
bug language:C#
Dominant language
Python
Stars
6.6k
Forks
1.9k
Avg merge
2d 6h
Merged PRs (30d)
33

Description

### Bug description:
The paths provided to C# compiler 'csc.exe' can't be resolved correctly by 'csc' and as a fallback it is trying to access the sources from the build directory ( the directory where 'csc' is executed ).
Didn't work with both 'relative' and 'absolute' paths.

### To reproduce:
**Project location:** C:\Project\c_sharp_test
**Files:** _main.cs_, _meson.build_
**Contents of 'main.cs':**
```
using System;

public class Base {
static public void Main() {
Console.WriteLine("Hello c# world!");
}
}
```
**Contents of 'meson.build' (relative path version):**
```
project('c_sharp_test', 'cs')

executable('c_sharp_test',
sources: 'main.cs'
)
```
**Contents of 'meson.build' (absolute path version):**
```
project('c_sharp_test', 'cs')

executable('c_sharp_test',
sources: meson.current_source_dir() + '\main.cs'
)
```
**Open the terminal in the project dir and run the following commands:**
_meson build/debug --buildtype=debug_
_meson compile -C build/debug_
**Terminal output:**
C:\Project\c_sharp_test>meson compile -C build/debug
Found runner: ninja
ninja: Entering directory `build/debug'
[1/1] Compiling C Sharp target c_sharp_test.exe
FAILED: c_sharp_test.exe
csc @c_sharp_test.exe.rsp
Microsoft (R) Visual C# Compiler version 4.7.3062.0
for C# 5
Copyright (C) Microsoft Corporation. All rights reserved.

This compiler is provided as part of the Microsoft (R) .NET Framework, but only supports language versions up to C# 5, which is no longer the latest version. For compilers that support newer versions of the C# programming language, see http://go.microsoft.com/fwlink/?LinkID=533240

error CS1504: Source file 'c:\Project\c_sharp_test\build\debug\main.cs' could not be opened ('The system cannot find the file specified. ')
ninja: build stopped: subcommand failed.

### Expected behavior
The executable must be generated.

### Possible solution
The paths must be absolute and with backslash as directory separator in order for 'csc' to get them right.
Managed to get the executable compiled with the following steps:
* Build the project with the 'meson.build' (absolute path version) then compile it with the error
* Go to build/debug directory and open in a text editor the file 'c_sharp_test.exe.rsp'
* Replace the forward slash with a backslash in the path and save the file:
```
"-debug" "-target:exe" "-out:c_sharp_test.exe" C:/Project/c_sharp_test/main.cs
to
"-debug" "-target:exe" "-out:c_sharp_test.exe" C:\Project\c_sharp_test\main.cs
```
* Run the command from the same directory:
_csc @c_sharp_test.exe.rsp_
* The executable is generated

### System parameters
* Build platform: Windows native
* Operating system: Windows 8.1
* Python version: 3.8.3_32bit
* Meson version: 0.54.3
* Ninja version: 1.10.0
* Microsoft (R) Visual C# Compiler version: 4.7.3062.0

### P.S.
A big thanks in advance for all your efforts

Contributor guide

Open the contributing guide

Research direction

Reproduce the issue with the shown meson.build files and inspect c_sharp_test.exe.rsp in the build/debug directory. Trace how Meson generates the csc response-file source path and compare the forward-slash and backslash forms; done means the unmodified response file lets csc compile successfully on Windows.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, python
Domain
build-system, compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.