Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions cpp/CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ make -j$(nproc)
# Via Maven from repo root
./mvnw clean verify -P with-cpp

# Maven and build.sh compile in parallel. ./mvnw and build.sh use one job per
# CPU core; a plain `mvn` falls back to 4. Override with
# -Dcmake.build.parallel.level=N, CMAKE_BUILD_PARALLEL_LEVEL, or build.sh -j=N
./mvnw -P with-cpp verify -Dcmake.build.parallel.level=8

# Run all tests (fast iteration only: runs the built binary and skips the
# Maven compile/link/package steps that CI performs)
./build/Release/lib/TsFile_Test
Expand Down
14 changes: 3 additions & 11 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -166,17 +166,9 @@ if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build." FORCE)
endif ()

if (NOT DEFINED CMAKE_BUILD_PARALLEL_LEVEL)
include(ProcessorCount)
ProcessorCount(N)
if (N EQUAL 0)
set(N 1)
endif ()
set(CMAKE_BUILD_PARALLEL_LEVEL ${N} CACHE STRING "Number of parallel build jobs")
message("CMAKE BUILD PARALLEL LEVEL: ${CMAKE_BUILD_PARALLEL_LEVEL} (auto-detected)")
else ()
message("CMAKE BUILD PARALLEL LEVEL: ${CMAKE_BUILD_PARALLEL_LEVEL} (from environment)")
endif ()
# Build parallelism is set by the driver, not here: `cmake --build` honors only the
# CMAKE_BUILD_PARALLEL_LEVEL environment variable (never a cache variable of that
# name), so the Maven build passes --parallel and build.sh passes -j instead.

message("CMAKE BUILD TYPE " ${CMAKE_BUILD_TYPE})
# Tune Release builds for the build-host CPU (-march=native). OFF by default:
Expand Down
2 changes: 2 additions & 0 deletions cpp/README-zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ mvn clean verify -P with-cpp

`build.sh` 默认使用 Release,构建完成后可在 `./build/Release` 目录下找到生成的共享库文件。

`build.sh` 和 `./mvnw` 默认按 CPU 核数并行编译(`mvnw` 会导出 `CMAKE_BUILD_PARALLEL_LEVEL`);直接使用 `mvn` 时默认 4 个并行任务。可用 `-j=N`(`build.sh`)、`-Dcmake.build.parallel.level=N`(Maven)或环境变量 `CMAKE_BUILD_PARALLEL_LEVEL` 调整并行度。

在向 GitHub 提交代码之前,请确保 `mvn` 编译通过。

---
Expand Down
5 changes: 5 additions & 0 deletions cpp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ To build tsfile, use Maven which automatically detects and uses the appropriate
mvn clean verify -P with-cpp
```

Compilation runs one job per CPU core under `./mvnw` (the wrapper exports
`CMAKE_BUILD_PARALLEL_LEVEL`); a plain `mvn` invocation falls back to 4 jobs.
Set `-Dcmake.build.parallel.level=N` or `CMAKE_BUILD_PARALLEL_LEVEL` to choose
the job count, and `bash build.sh -j=N` for the direct CMake build.

**Toolchain Selection:**

Maven will automatically select the compiler based on your platform:
Expand Down
31 changes: 30 additions & 1 deletion cpp/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ enable_lz4=ON
enable_lzokay=ON
enable_zlib=ON
enable_zstd=ON
build_jobs=""
# Keep the default build compatible with CMake 3.11-era industrial toolchains.
# Bundled XZ Utils requires CMake 3.20+, so LZMA2 must be enabled explicitly.
enable_lzma2=OFF
Expand All @@ -47,6 +48,17 @@ get_key_value() {
echo "${1#*=}"
}

detect_build_jobs()
{
if command -v nproc >/dev/null 2>&1; then
nproc
elif command -v sysctl >/dev/null 2>&1 && sysctl -n hw.ncpu >/dev/null 2>&1; then
sysctl -n hw.ncpu
else
echo 1
fi
}

usage()
{
cat <<EOF
Expand All @@ -62,6 +74,9 @@ Options:
Checks passed to -fsanitize= when ASan is enabled
(default: address,undefined).
-c=<ON|OFF> Enable or disable code coverage.
-j=<n>, -j<n>, --jobs=<n>
Number of parallel compile jobs (default: detected
processor count).
--build-shared=<ON|OFF>
Build libtsfile as a shared library (default: ON).
--build-static Build libtsfile as a static library.
Expand Down Expand Up @@ -102,6 +117,7 @@ function print_config()
echo "enable_zlib=$enable_zlib"
echo "enable_zstd=$enable_zstd"
echo "enable_lzma2=$enable_lzma2"
echo "build_jobs=$build_jobs"
}

function run_test_for_cov()
Expand Down Expand Up @@ -138,6 +154,13 @@ parse_options()
-c)
shift
enable_cov=$(get_key_value "$1");;
-j=* | --jobs=*)
build_jobs=$(get_key_value "$1");;
-j[0-9]*)
build_jobs=${1#-j};;
-j | --jobs)
shift
build_jobs=$(get_key_value "$1");;
--build-shared=*)
build_shared=$(get_key_value "$1");;
--build-static)
Expand Down Expand Up @@ -183,6 +206,12 @@ parse_options()
}

parse_options "$@"

if [ -z "${build_jobs}" ]
then
build_jobs=$(detect_build_jobs)
fi

print_config

if [[ ${run_cov_only} -eq 1 ]]
Expand Down Expand Up @@ -243,7 +272,7 @@ cmake ../../ \
-DENABLE_ZSTD=$enable_zstd \
-DENABLE_LZMA2=$enable_lzma2

VERBOSE=1 make
VERBOSE=1 make -j"${build_jobs}"
if [ ${do_install} -eq 1 ]
then
VERBOSE=1 make install
Expand Down
34 changes: 34 additions & 0 deletions cpp/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@
-->
<tsfile.sanitizer.checks>address,undefined</tsfile.sanitizer.checks>
<build.test>ON</build.test>
<!--
Parallelism for the CMake build. ./mvnw exports
CMAKE_BUILD_PARALLEL_LEVEL with the host core count, which the
profile below forwards here; this value is the fallback for a plain
`mvn` invocation. Override either way with
-Dcmake.build.parallel.level=N.
-->
<cmake.build.parallel.level>4</cmake.build.parallel.level>
<tsfile.build.shared>ON</tsfile.build.shared>
<tsfile.dependency.source>BUNDLED</tsfile.dependency.source>
<tsfile.dependency.offline>OFF</tsfile.dependency.offline>
Expand Down Expand Up @@ -163,6 +171,15 @@
generators such as the Makefile generators.
-->
<config>${build.type}</config>
<!--
CMake's build command runs the native tool serially
unless a jobs count is given; see
cmake.build.parallel.level.
-->
<options>
<option>--parallel</option>
<option>${cmake.build.parallel.level}</option>
</options>
</configuration>
</execution>
<!-- Execute the tests -->
Expand Down Expand Up @@ -231,6 +248,23 @@
</plugins>
</build>
<profiles>
<!--
./mvnw exports CMAKE_BUILD_PARALLEL_LEVEL with the host core count.
Maven resolves plugin configuration before the build starts, so a
plugin execution cannot publish the value; it has to come from the
model. Without the variable, cmake.build.parallel.level applies.
-->
<profile>
<id>build-parallelism-from-env</id>
<activation>
<property>
<name>env.CMAKE_BUILD_PARALLEL_LEVEL</name>
</property>
</activation>
<properties>
<cmake.build.parallel.level>${env.CMAKE_BUILD_PARALLEL_LEVEL}</cmake.build.parallel.level>
</properties>
</profile>
<profile>
<id>jenkins-build</id>
<!-- This is needed by the groovy hack script -->
Expand Down
23 changes: 23 additions & 0 deletions mvnw

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions mvnw.cmd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions skills/tsfile/references/cpp-build-write.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ cmake --build cpp/build/static --target tsfile
cd cpp && bash build.sh --build-static
```

Maven builds and `build.sh` compile in parallel: `./mvnw` and `build.sh` use one
job per CPU core, while a plain `mvn` falls back to 4. Control the count with
`-Dcmake.build.parallel.level=N`, the `CMAKE_BUILD_PARALLEL_LEVEL` environment
variable, or `bash build.sh -j=N`.

Use a separate build directory when switching library kind. A direct MSVC
consumer of the static archive must define `TSFILE_STATIC`; consumers of the
exported CMake target inherit the required definition. Verify the artifact in
Expand Down
Loading