Skip to content

Commit 3dd0926

Browse files
krish2718rlubos
authored andcommitted
net: lib: wifi_prov_core: Fix windows build
Move proto generation to cmake for cross-platform support, the python script checks for the files and doesn't try to generate them. Signed-off-by: Chaitanya Tata <[email protected]>
1 parent 12d0c1a commit 3dd0926

File tree

4 files changed

+53
-50
lines changed

4 files changed

+53
-50
lines changed

samples/wifi/provisioning/internal/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ if(CONFIG_WIFI_PROV_CONFIG)
3737
OUTPUT ${WIFI_CONFIG_BIN}
3838
COMMAND ${WIFI_CONFIG_CMD}
3939
DEPENDS ${WIFI_CONFIG_SCRIPT}
40-
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
40+
DEPENDS wifi_prov_core
41+
WORKING_DIRECTORY ${PROTO_DIR}
4142
COMMENT "Generating sample WiFi configuration"
4243
)
4344

subsys/net/lib/wifi_prov_core/CMakeLists.txt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ set(nanopb_BUILD_RUNTIME OFF)
1111
set(CMAKE_MODULE_PATH ${ZEPHYR_NANOPB_MODULE_DIR}/extra)
1212
find_package(Nanopb REQUIRED)
1313
set(NANOPB_GENERATE_CPP_STANDALONE FALSE)
14+
15+
# Generate nanopb C files for embedded code
1416
nanopb_generate_cpp(proto_sources proto_headers
1517
proto/common.proto
1618
proto/version.proto
@@ -19,6 +21,30 @@ nanopb_generate_cpp(proto_sources proto_headers
1921
proto/response.proto
2022
)
2123

24+
# Generate Python protobuf files for the configuration script
25+
if(PROTOBUF_PROTOC_EXECUTABLE)
26+
set(PYTHON_PROTO_FILES
27+
${CMAKE_CURRENT_SOURCE_DIR}/proto/common.proto
28+
${CMAKE_CURRENT_SOURCE_DIR}/proto/version.proto
29+
${CMAKE_CURRENT_SOURCE_DIR}/proto/result.proto
30+
${CMAKE_CURRENT_SOURCE_DIR}/proto/request.proto
31+
${CMAKE_CURRENT_SOURCE_DIR}/proto/response.proto
32+
)
33+
34+
add_custom_target(generate_python_proto ALL
35+
COMMAND ${PROTOBUF_PROTOC_EXECUTABLE}
36+
--python_out=${CMAKE_CURRENT_SOURCE_DIR}/proto
37+
--proto_path=${CMAKE_CURRENT_SOURCE_DIR}/proto
38+
${PYTHON_PROTO_FILES}
39+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/proto
40+
COMMENT "Generating Python protobuf files"
41+
VERBATIM
42+
)
43+
44+
# Make sure Python proto files are generated before the library
45+
add_dependencies(wifi_prov_core generate_python_proto)
46+
endif()
47+
2248
# Add include path to generated .pb.h header files
2349
zephyr_library_include_directories(${CMAKE_CURRENT_BINARY_DIR})
2450

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# CMakeLists.txt for generating nanopb C definitions
1+
# CMakeLists.txt for generating protobuf definitions
22
# Copyright (c) 2025 Nordic Semiconductor ASA
33
#
44
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
@@ -12,35 +12,35 @@ set(PROTO_FILES
1212
version.proto
1313
)
1414

15-
# Create custom target for nanopb generation (for embedded code)
16-
add_custom_target(generate_nanopb ALL
17-
COMMAND ${CMAKE_COMMAND} -E echo "Generating nanopb C definitions..."
18-
COMMAND protoc --nanopb_out=. ${PROTO_FILES}
19-
COMMAND ${CMAKE_COMMAND} -E echo "Generated nanopb files:"
20-
COMMAND ${CMAKE_COMMAND} -E ls -la *.pb.c *.pb.h
21-
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
22-
COMMENT "Generating nanopb C definitions"
23-
VERBATIM
24-
)
15+
# Generate Python protobuf files for the configuration script
16+
if(PROTOBUF_PROTOC_EXECUTABLE)
17+
add_custom_target(generate_python_proto_files ALL
18+
COMMAND ${PROTOBUF_PROTOC_EXECUTABLE}
19+
--python_out=${CMAKE_CURRENT_SOURCE_DIR}
20+
--proto_path=${CMAKE_CURRENT_SOURCE_DIR}
21+
${PROTO_FILES}
22+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
23+
COMMENT "Generating Python protobuf files"
24+
VERBATIM
25+
)
26+
else()
27+
message(WARNING "protoc not found - Python protobuf files will not be generated")
28+
endif()
2529

2630
# Create custom target for cleaning
27-
add_custom_target(clean_nanopb
31+
add_custom_target(clean_proto_files
2832
COMMAND ${CMAKE_COMMAND} -E echo "Cleaning generated files..."
29-
COMMAND ${CMAKE_COMMAND} -E remove *.pb.c *.pb.h
33+
COMMAND ${CMAKE_COMMAND} -E remove *.pb.c *.pb.h *_pb2.py
3034
COMMAND ${CMAKE_COMMAND} -E echo "Cleaned!"
3135
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
32-
COMMENT "Cleaning generated nanopb files"
36+
COMMENT "Cleaning generated protobuf files"
3337
)
3438

3539
# Create custom target for testing
36-
add_custom_target(test_nanopb
40+
add_custom_target(test_proto_files
3741
COMMAND ${CMAKE_COMMAND} -E echo "Running auth mode validation tests..."
3842
COMMAND python3 test_auth_modes.py
3943
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
40-
COMMENT "Running nanopb validation tests"
44+
COMMENT "Running protobuf validation tests"
45+
DEPENDS generate_python_proto_files
4146
)
42-
43-
# Add dependencies to the main project if it exists
44-
if(TARGET ${PROJECT_NAME})
45-
add_dependencies(${PROJECT_NAME} generate_nanopb)
46-
endif()

subsys/net/lib/wifi_prov_core/proto/generate_wifi_prov_config.py

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -23,34 +23,10 @@
2323
from request_pb2 import Request, WifiConfig, EnterpriseCertConfig
2424
from common_pb2 import WifiInfo, AuthMode, Band, OpCode
2525
except ImportError:
26-
# Auto-generate Python protobuf files if they don't exist
27-
print("Python protobuf definitions not found. Auto-generating...")
28-
import subprocess
29-
30-
# Check if protoc is available
31-
try:
32-
subprocess.run(['protoc', '--version'], capture_output=True, check=True)
33-
except (subprocess.CalledProcessError, FileNotFoundError):
34-
print("Error: 'protoc' not found. Please install protobuf compiler.")
35-
sys.exit(1)
36-
37-
# Generate Python protobuf files
38-
proto_files = ['request.proto', 'common.proto', 'response.proto', 'result.proto', 'version.proto']
39-
try:
40-
# Get the directory where this script is located
41-
script_dir = os.path.dirname(os.path.abspath(__file__))
42-
43-
# Run protoc from the script directory where .proto files are located
44-
subprocess.run(['protoc', '--python_out=' + script_dir] + proto_files,
45-
cwd=script_dir, check=True)
46-
print("✅ Generated Python protobuf definitions")
47-
48-
# Import the generated modules
49-
from request_pb2 import Request, WifiConfig, EnterpriseCertConfig
50-
from common_pb2 import WifiInfo, AuthMode, Band, OpCode
51-
except subprocess.CalledProcessError as e:
52-
print(f"Error generating protobuf definitions: {e}")
53-
sys.exit(1)
26+
print("Error: Python protobuf defigdnitions not found.")
27+
print("Please ensure the CMake build has generated the protobuf files.")
28+
print("The files should be generated automatically during the build process.")
29+
sys.exit(1)
5430

5531
def read_cert_file(file_path):
5632
"""Read certificate file and return as bytes.

0 commit comments

Comments
 (0)