Skip to content

Commit 9ab0495

Browse files
More tweaks to the mrbind instructions. (#5842)
1 parent 2f1960e commit 9ab0495

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

scripts/mrbind/README-generating.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -104,39 +104,37 @@ The resulting Python modules are created next to the MeshLib shared libraries, i
104104

105105
* **`--trace` — enable verbose logs.** Remove to get quieter logs.
106106

107-
* **`-B` — force a full rebuild of the bindings.** Incremental builds are not very useful, because they're not perfect and can miss changes. Use incremental builds only e.g. when you're fixing linker errors.
107+
* **`-B` — force a full rebuild of the bindings.** Don't remove this flag. Doing so causes Make to attempt an incremental build instead of a full rebuild, but we don't have those configured correctly, so the binding generation might be skipped even when the input headers were changed. There's one valid usecase for removing this flag: making changes to fix linker errors, such as correcting `MESHLIB_SHLIB_DIR` or `VS_MODE`; in those cases removing `-B` will redo linking instead of rebuilding the entire bindings.
108108

109109
* **`MODE=...` — optimization** setting for the Python module:
110110

111-
* `release` (default) — Enable optimization, disable debug symbols. Same as what goes into the production.
111+
* `release` (default) — Enable optimization, disable debug symbols. This is what goes into the production.
112112

113113
* `debug` — disable optimizations, enable debug symbols. Use this to debug the bindings.
114114

115115
* `none` — neither enable optimizations nor enable the debug symbols. This gives the fastest build times, useful for testing bindings locally.
116116

117-
You can also et entirely custom C++ compiler flags, by setting `EXTRA_CFLAGS` and `EXTRA_LDFLAGS`.
118-
119-
The `EXTRA_...` flags are ignored for C#, and `MODE=none` is replaced with `MODE=debug` there.
117+
You can also use entirely custom C++ compiler flags, by setting `EXTRA_CFLAGS` and `EXTRA_LDFLAGS`.
120118

121119
* **`NUM_FRAGMENTS=?? -j??` — adjust RAM usage vs build speed tradeoff.**
122120

123121
If you're running out of RAM, reduce `-j...`.
124122

125-
`NUM_FRAGMENTS=??` is how many translation units the bindings are split into. `-j??` is the number of parallel build threads/processes. We have some heuristics to guess good values for this, they are printed when the script starts.
123+
`NUM_FRAGMENTS=??` is how many translation units the bindings are split into. `-j??` is the number of parallel build threads/processes. We have some heuristics to guess good values for this, those values are printed when the script starts.
126124

127125
Guessing the fastest combination isn't trivial. Usually you want to maximize threads (up to the number of cores), and then minimize the number of fragments as much as your RAM allows. The number of fragments should normally be a multiple of the number of threads.
128126

129127
* **`PYTHON_PKGCONF_NAME=python-3.??-embed` — select Python version.** We try to guess this one. You can set this to `python3-embed` to use whatever your OS considers to be the default version.
130128

131-
* **`ENABLE_CUDA=??` — enable or disable Cuda.** If you're building MeshLib without Cuda support, pass `ENABLE_CUDA=0` to skip the Cuda bindings too. It defaults to `1` everywhere except MacOS, where Cuda doesn't work.
129+
* **`ENABLE_CUDA=??` — enable or disable Cuda.** If you're building MeshLib without Cuda support, pass `ENABLE_CUDA=0` to skip the Cuda bindings. It defaults to `1` everywhere except MacOS, where Cuda doesn't work.
132130

133-
When this is disabled, a stub Cuda bindings are still generated, with a single function that reports that Cuda is not available.
131+
When this is disabled, stub Cuda bindings are still generated, with a single function that reports that Cuda is not available.
134132

135133
* **`BUILD_SHIMS=1` — support multiple Python versions.** This enables support for all Python versions found on the system, as opposed a single default one. See the relevant section in the [troubleshooting guide](#troubleshooting-python-bindings).
136134

137135
* **`shims` — add support for multiple Python versions.** Same effect as `BUILD_SHIMS=1`, but instead of regenerating the bindings, this just adds the missing version support to existing bindings. This is great if you forgot the flag during the initial compilation.
138136

139-
* **`FOR_WHEEL=1` — build for wheel packaging.** This is primarily for CI, not for local use. Indicates that you want to package the resulting module into a wheel (a Python module archive for distribution), instead of using it locally. Enabling this might prevent the module from working locally.
137+
* **`FOR_WHEEL=1` — build for wheel packaging.** This is primarily for CI, not for local use. Indicates that you want to package the resulting module into a wheel (a Python module archive for distribution), instead of using it locally. Enabling this might prevent the module from functioning until packaged into a wheel.
140138

141139
This automatically enables `BUILD_SHIMS=1`, among other things.
142140

@@ -148,19 +146,19 @@ The resulting Python modules are created next to the MeshLib shared libraries, i
148146

149147
* When built locally, Python bindings only support one speific Python version by default. If you try to import them from another version, you will get errors such as the one above.
150148

151-
* To check which version you built for, look for shared libraried named `pybind11nonlimitedapi_meshlib_3.??` next to the Python modules. On Windows, those should be in `source/x64/Release/meshlib` (or `.../Debug/...`). The number in the filename is the Python version.
149+
* To check what version you built for, look for shared libraried named `pybind11nonlimitedapi_meshlib_3.??` next to the Python modules. On Windows, those should be in `source/x64/Release/meshlib` (or `.../Debug/...`). The number in the filename is the Python version.
152150

153151
* The easiest fix to use that Python version.
154152

155-
* On Windows, run e.g. `py -3.12` to use that specific version (`3.12` is our default for the bindings at the time of writing). You might need to install it first from [here](https://www.python.org/downloads/windows/).
153+
* On Windows, run e.g. `py -3.12` to use that specific version (`3.12` is our default for the bindings at the time of writing). You might need to install that version first, from [here](https://www.python.org/downloads/windows/).
156154

157155
* On Linux, just running `python3` without specifying the minor version should use the correct version by default.
158156

159157
* Alternatively, you can add the missing shared libraries to support your preferred Python version.
160158

161-
* You can build them by rerunning the generation script with additional flag `shims`. This will build the libraries for all Python versions found on your system.
159+
* You can build them by rerunning the generation script with the additional flag `shims`. This will build the libraries for all Python versions found on your system.
162160

163-
This commands only builds the libraries and does nothing else. You can use `BUILD_SHIMS=1` instead of `shims` to regenerate the bindings and build those libraries at the same time.
161+
This command only builds the libraries and does nothing else. You can use `BUILD_SHIMS=1` instead of `shims` to both regenerate the bindings and build those libraries at the same time.
164162

165163
* You can also download the prebuilt libraries from [here](https://pypi.org/project/meshlib/#files). Download the archive for your OS and extract the `pybind11nonlimitedapi_meshlib_...` shared libraries next to yours.
166164

@@ -170,7 +168,7 @@ The resulting Python modules are created next to the MeshLib shared libraries, i
170168

171169
* **`machine type x86 conflicts with x64`**
172170

173-
* You opened `x86 ...` VS developer command prompt, but we need `x64 Native`. Rebuild the bindings in x64 prompt.
171+
* You opened `x86 ...` VS developer command prompt, but we need `x64 Native`. Rebuild the bindings in the x64 prompt.
174172

175173
* **`undefined symbol: void __cdecl std::_Literal_zero_is_expected(void)`**
176174

@@ -182,7 +180,7 @@ The resulting Python modules are created next to the MeshLib shared libraries, i
182180

183181
* You likely used a non-default compiler when compiling MeshLib. Pass this compiler to `CXX_FOR_ABI=...` when generating Python bindings to fix the issue (e.g. `CXX_FOR_ABI=clang++-22` or `g++-15`).
184182

185-
MeshLib is usually compiled using a different compiler than the Python bindings (for the bindings we use a specific version of Clang, the same that is used by the parser; using the same compiler for the bindings on all platforms makes writing them easier). Therefore, we must ensure that the two compilers use the same ABI. `CXX_FOR_ABI` should be set to the compiler the ABI of which we're trying to match. (Defaults to `CXX` environment variable, or `g++` if not set.) At the moment, if `CXX_FOR_ABI` is GCC 13 or older or Clang 17 or older (note that Apple Clang uses a [different version numbering scheme](https://en.wikipedia.org/wiki/Xcode#Xcode_15.0_-_(since_visionOS_support)_2)), we pass `-fclang-abi-compat=17` to our Clang 18 or newer (which is used to compile the bindings). This flag *disables* mangling of `requires` constraints into function names. If we guess incorrectly, you'll get undefined references to functions with `requires` constraints on them.
183+
MeshLib is usually compiled using a different compiler than the Python bindings (for the bindings we use a specific version of Clang, the same that is used by the parser; using the same compiler for the bindings on all platforms makes writing them easier). Therefore, we must ensure that the two compilers use the same ABI. `CXX_FOR_ABI` should be set to the compiler the ABI of which we're trying to match. (Defaults to the `CXX` environment variable, or `g++` if not set.) At the moment, if `CXX_FOR_ABI` is GCC 13 or older or Clang 17 or older (note that Apple Clang uses a [different version numbering scheme](https://en.wikipedia.org/wiki/Xcode#Xcode_15.0_-_(since_visionOS_support)_2)), we pass `-fclang-abi-compat=17` to our Clang 18 or newer (which is used to compile the bindings). This flag *disables* mangling of `requires` constraints into the function names. If we guess incorrectly, you'll get undefined references to functions with `requires` constraints on them.
186184

187185
* **Importing the wheel segfaults on MacOS**
188186

@@ -203,7 +201,7 @@ The resulting Python modules are created next to the MeshLib shared libraries, i
203201

204202
Running our script generates the code for the bindings, at `source/MeshLibC2` and `source/MeshLibC2Cuda`.
205203

206-
Then you must build MeshLib with a special CMake flag, which will build the generated bindings.
204+
Then you must build MeshLib with a special CMake flag, which will build the generated bindings in addition to the rest of the MeshLib.
207205

208206
### Windows
209207

@@ -271,8 +269,10 @@ The steps below both generate the C# code (at `MeshLib/source/MRDotNet2`) and co
271269

272270
### Less common flags for the generator script
273271

274-
* **Selecting MRBind installation:** if you installed MRBind to a non-default location (the default is `./MeshLib/mrbind`), you must pass this location to `MRBIND_SOURCE=path/to/mrbind`.
272+
* **Selecting MRBind installation:** if you installed MRBind to a non-default location (the default is `./thirdparty/mrbind`), you must pass this location to `MRBIND_SOURCE=path/to/mrbind`.
275273

276274
Additionally, if the MRBind binary is not at `$MRBIND_SOURCE/build/mrbind`, you must pass `MRBIND_EXE=...` (path to the executable itself, not its directory).
277275

276+
For C and C# (but not Python), if you set `MRBIND_EXE`, then you can skip `MRBIND_SOURCE`.
277+
278278
You can find more undocumented flags/variables in `generate.mk`.

0 commit comments

Comments
 (0)