microsoft / qsharp

Azure Quantum Development Kit, including the Q# programming language, resource estimator, and Quantum Katas
https://microsoft.github.io/qsharp/
MIT License
367 stars 73 forks source link

Issue building from source on ARM Mac #1642

Closed spencerdearman closed 1 week ago

spencerdearman commented 1 week ago

Describe the bug

The primary issue that I am having is that the qsharp package is failing to build on the last step due to a MacOS platform issue.

To Reproduce

Run ./build.py in the root directory as if you were just going to build the package and the error should present itself.

Expected behavior

The package should complete building, but instead I receive this error.

98 files are correctly formatted. build.py: Finished in 12.408s. build.py: Building the command line compiler Compiling qsharp v0.0.0 (/Users/spencerdearman/qsharp/pip) error: linking withcc` failed: exit status: 1 ... ld: symbol(s) not found for architecture arm64 clang: error: linker command failed with exit code 1 (use -v to see invocation)

error: could not compile qsharp (lib) due to 1 previous error Traceback (most recent call last): File "/Users/spencerdearman/qsharp/./build.py", line 221, in subprocess.run(cargo_build_args, check=True, text=True, cwd=root_dir) File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/subprocess.py", line 571, in run raise CalledProcessError(retcode, process.args, subprocess.CalledProcessError: Command '['cargo', 'build', '--release']' returned non-zero exit status 101. `

System information

Operating System: ARM64 Chip: M3 Max MacOS: Sonoma 14.4.1 Python Version: python 3.11.9 Package Version: The default when the repo is downloaded

nirajvenkat commented 1 week ago

I was able to make some kludgy fixes to get this working in the short term: 50a20bc38eac7d6dddc182f06dbbff6b6d414fac

idavis commented 1 week ago

@nirajvenkat Do you have both the aarch64 and x86_64 rust toolchains installed? Can you try running:

rustup target add x86_64-apple-darwin
rustup target add aarch64-apple-darwin

And then run the build again?

spencerdearman commented 1 week ago

I had to run rustup target add x86_64-apple-darwin to get it to work on my device but it was able to build after doing so.

billti commented 1 week ago

Interesting that the error was 'ld: symbol(s) not found for architecture arm64' but adding the x64 target fixed it :-/

I'm guessing as we build universal wheels on the mac by default (see https://github.com/microsoft/qsharp/blob/main/build.py#L240), if you build that on Mac (which build.py does by default) then you need both x64 and arm64 targets installed in your Rust toolchain. Maybe our README should include that tidbit.

idavis commented 1 week ago

I created #1649 to address this and guide users to a working build.

nirajvenkat commented 1 week ago

@idavis Thanks this helps with the full ./build.py. These changes (https://github.com/microsoft/qsharp/commit/50a20bc38eac7d6dddc182f06dbbff6b6d414) are still required though. My rustup target list --installed now shows:

aarch64-apple-darwin
wasm32-unknown-unknown
x86_64-apple-darwin

Earlier I was only doing ./build.py --wasm --npm --vscode so the lack of x86_64 toolchain was not affecting me.

idavis commented 1 week ago

@nirajvenkat What version of rust are you using? This build works fine for me without any source changes with 1.78.

nirajvenkat commented 1 week ago

@idavis rustc 1.79.0 (129f3b996 2024-06-10)

idavis commented 1 week ago

@nirajvenkat #1649 should have fixed your issues. Please reopen if you have any more problems. Thank you!