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

Native Windows build #38872

Open
wants to merge 82 commits into
base: develop
Choose a base branch
from
Open

Native Windows build #38872

wants to merge 82 commits into from

Conversation

tobiasdiez
Copy link
Contributor

@tobiasdiez tobiasdiez commented Oct 28, 2024

The goal of this PR is to provide a native Windows build of Sage using MSVC (using the new Meson build system).

Instructions on how to test are under the Windows tab at https://doc-pr-38872--sagemath.netlify.app/html/en/installation/meson.
Afterwards, you should be able to import some sage modules in a normal python install (but most modules actually don't properly import due to various errors that will be fixed peu a peu in follow-up PRs)

State of Windows support of dependencies

Conda Issues:

Upstream issues

Singular

Flint:

Cysignals:

📝 Checklist

  • The title is concise and informative.
  • The description explains in detail what this PR is about.
  • I have linked a relevant issue or discussion.
  • I have created tests covering the changes.
  • I have updated the documentation and checked the documentation preview.

⌛ Dependencies

Copy link

github-actions bot commented Oct 28, 2024

Documentation preview for this PR (built with commit 0445ffb; changes) is ready! 🎉
This preview will update shortly after each push to this PR.

../src/sage/symbolic/ginac/upoly-ginac.cpp(219): error C2440: '<function-style-cast>': cannot convert from 'size_t' to 'GiNaC::numeric'
../src/sage/symbolic/ginac/upoly-ginac.cpp(219): note: 'GiNaC::numeric::numeric': ambiguous call to overloaded function
../src/sage/symbolic/ginac/archive.cpp(584): error C2039: 'mem_fun_ref': is not a member of 'std'
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.41.34120\include\sstream(19): note: see declaration of 'std'
../src/sage/symbolic/ginac/archive.cpp(584): error C3861: 'mem_fun_ref': identifier not found
../src/sage/symbolic/ginac/archive.cpp(584): error C2672: 'for_each': no matching overloaded function found
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.41.34120\include\xkeycheck.h(341): warning C4005: 'register': macro redefinition
../src/sage/symbolic/ginac/constant.cpp(23): note: see previous definition of 'register'
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.41.34120\include\xkeycheck.h(343): fatal error C1189: #error:  The C++ Standard Library forbids macroizing the keyword "register". Enable warning C4005 to find the forbidden define.
ginac_lst.cpp.obj : error LNK2005: "protected: static void const * __cdecl GiNaC::container<class std::list>::get_tinfo(void)" (?get_tinfo@?$container@Vlist@std@@@ginac@@KAPEBXXZ) already defined in meson-generated_src_sage_symbolic_expression.pyx.cpp.obj
Some of them should perhaps be reverted
`os.uname` is not available on Windows
@tobiasdiez tobiasdiez marked this pull request as ready for review December 5, 2024 02:33
@tobiasdiez
Copy link
Contributor Author

tobiasdiez commented Dec 5, 2024

@saraedum Thanks for the feedback. Cysignals is now using meson and builds nicely on Windows. NTL is still not available on conda (as far as I know), but we can use the flexibility of meson to just not build the parts of sage that make use of it (a similar strategy is employed for various other dependencies which don't provide windows build / or are not installable from conda yet).

This PR is now in a working stage, at least to the extend that it should compile nicely on Windows. Instructions on how to test are under the Windows tab at https://doc-pr-38872--sagemath.netlify.app/html/en/installation/meson. If you find the time to test it on your system, this would be awesome. After the next beta (that includes #37447) I'll cleanup the code a bit more and make the PR ready for a proper review.

Turns out `mtx.lib` exists on Windows as "Microsoft Transaction Server". Thus, we also check for the existence of the header `meataxe.h`.
@isuruf
Copy link
Member

isuruf commented Dec 9, 2024

cysignals and gmpy2 issues should be fixed now

@tobiasdiez
Copy link
Contributor Author

cysignals and gmpy2 issues should be fixed now

They are indeed, thanks a lot!

@soehms
Copy link
Member

soehms commented Jan 8, 2025

This PR is now in a working stage, at least to the extend that it should compile nicely on Windows. Instructions on how to test are under the Windows tab at https://doc-pr-38872--sagemath.netlify.app/html/en/installation/meson. If you find the time to test it on your system, this would be awesome. After the next beta (that includes #37447) I'll cleanup the code a bit more and make the PR ready for a proper review.

Testreport on Windows 11 pro

I tried to follow your instructions on the documentation page. Since I'm not really familiar with the build system on Windows, it wasn't easy. First of all, it looks like the "Windows" tab is almost a clone of the other tabs with very few Windows-specific changes. Even your example of the "VS x64 Native Tools Command Prompt" doesn't look like what it looked like in my test:

**********************************************************************
** Visual Studio 2022 Developer Command Prompt v17.12.3
** Copyright (c) 2022 Microsoft Corporation
**********************************************************************
[vcvarsall.bat] Environment initialized for: 'x64'

C:\Program Files\Microsoft Visual Studio\2022\Community>

I ran the test on Windows 11 Pro, freshly installed a few months ago. None of the required prerequisites were present on that system. Here I give a summary of what I had to do to get the test working (hoping it helps someone else starting at a similar point as me):

  • I downloaded and ran VisualStudioSetup. I checked all the boxes relevant to C/C++ and Python development (and a few more that may not be required but I wasn't sure about).

  • I downloaded and installed Git-Bash, selecting all the default options except for the question about the terminal I want Git to be available on (here I selected the option for all terminal types).

  • I downloaded miniforge and installed it under my home path using Powershell as explained in this tutorial.

After that, I started the VS x64 Native Tools prompt (I suspect that's essentially a regular cmd terminal with the environment set by "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Auxiliary\Build\vcvarsall.bat"). I changed the directory to my home path, cloned the Sage repository into a subfolder, and checked out your branch. Then I activated the mamba environment by running .\miniforge3\Scripts\activate.

Finally, I was able to follow your instructions:

(sage-dev) C:\Users\sebastian\sage>pip install gmpy2 cysignals
Requirement already satisfied: gmpy2 in c:\users\sebastian\miniforge3\envs\sage-dev\lib\site-packages (2.1.5)
Requirement already satisfied: cysignals in c:\users\sebastian\miniforge3\envs\sage-dev\lib\site-packages (1.12.0)

(sage-dev) C:\Users\sebastian\sage>set LIB=%CONDA_PREFIX%\Library\lib;%LIB%

(sage-dev) C:\Users\sebastian\sage>pip install --no-build-isolation --editable .
Obtaining file:///C:/Users/sebastian/sage
  Checking if build backend supports build_editable ... done
  Preparing editable metadata (pyproject.toml) ... done
Requirement already satisfied: six>=1.15.0 in c:\users\sebastian\miniforge3\envs\sage-dev\lib\site-packages (from sagemath==10.6b2) (1.17.0)
Requirement already satisfied: conway-polynomials>=0.8 in c:\users\sebastian\miniforge3\envs\sage-dev\lib\site-packages(from sagemath==10.6b2) (0.10)
Requirement already satisfied: cython!=3.0.3,>=3.0 in c:\users\sebastian\miniforge3\envs\sage-dev\lib\site-packages (from sagemath==10.6b2) (3.0.11)
Requirement already satisfied: gmpy2~=2.1.b999 in c:\users\sebastian\miniforge3\envs\sage-dev\lib\site-packages (from sagemath==10.6b2) (2.1.5)
...
Requirement already satisfied: pure_eval in c:\users\sebastian\miniforge3\envs\sage-dev\lib\site-packages (from stack_data->ipython>=7.13.0->sagemath==10.6b2) (0.2.3)
Building wheels for collected packages: sagemath
  Building editable for sagemath (pyproject.toml) ... done
  Created wheel for sagemath: filename=sagemath-10.6b2-cp311-cp311-win_amd64.whl size=16759 sha256=53b80ef9857cb142c2919a88ff11f1f1384b09e6f91fa52263842d981871d19c
  Stored in directory: C:\Users\sebastian\AppData\Local\Temp\pip-ephem-wheel-cache-bxq6ke4c\wheels\6c\82\8f\5ff77f17cf38bb97b46a696d2aefe5aa0fff1e75fe9cde8b7d
Successfully built sagemath
Installing collected packages: sagemath
Successfully installed sagemath-10.6b2

Now I'm not quite sure how to use Sage? There was nothing in the terminal environment to start Sage by name. Then I tried to use Sage in an IPython session by importing its global names...

sage-dev) C:\Users\sebastian\sage>IPython
Python 3.11.11 | packaged by conda-forge | (main, Dec  5 2024, 14:06:23) [MSC v.1942 64 bit (AMD64)]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.30.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: from sage.rings.all import *
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
Cell In[1], line 1
----> 1 from sage.rings.all import *

File ~\sage\src\sage\rings\all.py:57
     54 from sage.rings.finite_rings.all import *
     56 # Number field
---> 57 from sage.rings.number_field.all import *
     59 # Function field
     60 from sage.rings.function_field.all import *

File ~\sage\src\sage\rings\number_field\all.py:2
----> 2 from sage.rings.number_field.number_field import (NumberField, NumberFieldTower, CyclotomicField, QuadraticField,
      3                                                   is_fundamental_discriminant, is_real_place)
      4 from sage.rings.number_field.number_field_element import NumberFieldElement
      6 from sage.rings.number_field.order import EquationOrder, GaussianIntegers, EisensteinIntegers
    198 from sage.modules.module import Module

File ~\sage\src\sage\rings\number_field\number_field.py:118
    116 from sage.categories.homset import Hom
    117 from sage.categories.sets_cat import Sets
--> 118 from sage.modules.free_module import VectorSpace
    119 from sage.modules.free_module_element import vector
    120 from sage.rings.real_mpfr import RR

File ~\sage\src\sage\modules\free_module.py:197
    195 from sage.misc.lazy_import import LazyImport
    196 from sage.misc.randstate import current_randstate
--> 197 from sage.modules import free_module_element
    198 from sage.modules.module import Module
    199 from sage.rings.finite_rings.finite_field_base import FiniteField

ImportError: cannot import name 'free_module_element' from 'sage.modules' (C:\Users\sebastian\sage\src\sage\modules\__init__.py)

In [2]:

In [2]: from sage.rings.integer_ring import ZZ

In [3]: ZZ
Out[3]: Integer Ring

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants