Skip to content

Commit da6c97d

Browse files
nicknick
authored andcommitted
changes to CMake and bindings
1 parent a2c33d5 commit da6c97d

13 files changed

Lines changed: 109 additions & 22 deletions

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@
33
################################################################################
44

55
/.vs
6+
/.venv
7+
BUILDING.md

CMakeLists.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,10 @@ target_include_directories(docx_comment_parser
3434
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
3535
$<INSTALL_INTERFACE:include>
3636
PRIVATE
37-
3837
)
3938

4039
target_link_libraries(docx_comment_parser
4140
PRIVATE
42-
4341
ZLIB::ZLIB
4442
)
4543

@@ -116,7 +114,6 @@ install(TARGETS docx_comment_parser
116114
install(FILES
117115
include/docx_comment_parser.h
118116
include/zip_reader.h
119-
include/xml_utils.h
120117
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/docx_comment_parser
121118
)
122119

File renamed without changes.
File renamed without changes.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* -I$(python3 -c "import pybind11; print(pybind11.get_include())") \
88
* python_bindings.cpp ../src/docx_parser.cpp ../src/batch_parser.cpp \
99
* ../src/zip_reader.cpp \
10-
* -lxml2 -lz \
10+
* -lz \
1111
* -o docx_comment_parser$(python3-config --extension-suffix)
1212
*
1313
* Usage from Python:

setup.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
"""
1111

1212
from setuptools import setup, Extension
13-
from setuptools.command.build_ext import build_ext
14-
import subprocess
1513
import sys
1614
import os
1715

@@ -22,24 +20,26 @@
2220
except ImportError:
2321
raise RuntimeError("pybind11 not found. Install with: pip install pybind11")
2422

25-
# ─── Locate libxml2 ───────────────────────────────────────────────────────────
26-
def pkg_config(*args):
27-
try:
28-
return subprocess.check_output(
29-
["pkg-config"] + list(args), stderr=subprocess.DEVNULL
30-
).decode().split()
31-
except (subprocess.CalledProcessError, FileNotFoundError):
32-
return []
33-
34-
35-
extra_compile_args = ["-std=c++17", "-O3", "-DNDEBUG",
23+
# ─── Platform-specific flags ─────────────────────────────────────────────────
24+
if sys.platform == "win32":
25+
extra_compile_args = ["/std:c++17", "/O2", "/DNDEBUG", "/EHsc"]
26+
extra_link_args = []
27+
else:
28+
extra_compile_args = [
29+
"-std=c++17",
30+
"-O3",
31+
"-DNDEBUG",
32+
"-fvisibility=hidden",
33+
]
34+
extra_link_args = ["-lz"]
3635

3736
# ─── Source files ─────────────────────────────────────────────────────────────
3837
sources = [
3938
"python/python_bindings.cpp",
4039
"src/docx_parser.cpp",
4140
"src/batch_parser.cpp",
4241
"src/zip_reader.cpp",
42+
"src/xml_parser.cpp",
4343
]
4444

4545
ext = Extension(
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
#include <thread>
44
#include <mutex>
5-
#include <atomic>
65
#include <queue>
76
#include <functional>
87
#include <condition_variable>

docx_parser.cpp renamed to src/docx_parser.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#include "xml_parser.h"
44

55
#include <algorithm>
6-
#include <cassert>
76
#include <set>
87
#include <unordered_map>
98
#include <functional>

xml_parser.cpp renamed to src/xml_parser.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ static void decode_entities(const char* s, std::size_t len, std::string& out) {
2626
const char* end = s + len;
2727
while (s < end) {
2828
if (*s != '&') { out += *s++; continue; }
29-
const char* amp = s++;
29+
++s; // skip '&'
3030
const char* semi = static_cast<const char*>(std::memchr(s, ';', static_cast<std::size_t>(end - s)));
3131
if (!semi) { out += '&'; continue; }
3232
std::string_view ref(s, static_cast<std::size_t>(semi - s));
@@ -65,7 +65,6 @@ static void decode_entities(const char* s, std::size_t len, std::string& out) {
6565
out += ';';
6666
}
6767
s = semi + 1;
68-
(void)amp;
6968
}
7069
}
7170

@@ -110,7 +109,7 @@ bool sax_parse(const char* data, std::size_t len, SaxHandler& h) {
110109
const char* end = data + len;
111110

112111
// Reusable buffers to reduce allocations
113-
std::string prefix, local, val, text_buf;
112+
std::string prefix, local, text_buf;
114113

115114
while (p < end) {
116115
if (*p != '<') {

0 commit comments

Comments
 (0)