Skip to content

Commit

Permalink
Fixes ios package issue with auto-generated C++ header files (#4255)
Browse files Browse the repository at this point in the history
  • Loading branch information
gupnik authored Feb 6, 2025
1 parent e36ee95 commit 9bab767
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 20 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,13 @@ swift/wallet-core/
codegen-v2/bindings/

src/Generated/*.cpp
include/Generated/TrustWalletCore/*.h
include/TrustWalletCore/TWHRP.h
include/TrustWalletCore/TW*Proto.h
include/TrustWalletCore/TWEthereumChainID.h

# Generated
include/TrustWalletCore/TWTONAddressConverter.h

# Wasm
emsdk/
wasm-build/
Expand Down
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ endif ()
target_include_directories(TrustWalletCore
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/Generated>
$<INSTALL_INTERFACE:include>
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src
Expand Down
8 changes: 4 additions & 4 deletions codegen-v2/src/codegen/cpp/code_gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::Error::BadFormat;
use crate::Result;

static IN_DIR: &str = "../rust/bindings/";
static HEADER_OUT_DIR: &str = "../include/Generated/TrustWalletCore/";
static HEADER_OUT_DIR: &str = "../include/TrustWalletCore/";
static SOURCE_OUT_DIR: &str = "../src/Generated/";

#[derive(Deserialize, Serialize, Debug)]
Expand Down Expand Up @@ -72,14 +72,14 @@ fn generate_header_guard(file: &mut std::fs::File) -> Result<()> {
}

fn generate_header_includes(file: &mut std::fs::File, info: &TWConfig) -> Result<()> {
writeln!(file, "#include <TrustWalletCore/TWBase.h>")?;
writeln!(file, "#include \"TWBase.h\"")?;

// Include headers based on argument types
let mut included_headers = std::collections::HashSet::new();
for func in &info.static_functions {
for arg in &func.args {
if arg.ty.contains("TWString") && included_headers.insert("TWString.h") {
writeln!(file, "#include <TrustWalletCore/TWString.h>")?;
writeln!(file, "#include \"TWString.h\"")?;
}
// Additional type checks can be added here in the future
}
Expand Down Expand Up @@ -160,7 +160,7 @@ pub fn generate_header(info: &TWConfig) -> Result<()> {
fn generate_source_includes(file: &mut std::fs::File, info: &TWConfig) -> Result<()> {
writeln!(
file,
"#include <Generated/TrustWalletCore/{}.h>",
"#include <TrustWalletCore/{}.h>",
info.class
)?;
writeln!(file, "#include \"rust/Wrapper.h\"")?;
Expand Down
17 changes: 7 additions & 10 deletions codegen/bin/codegen
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ Encoding.default_internal = Encoding::UTF_8
options = OpenStruct.new
# default input / output path
options.input = "#{CurrentDir}/../../include/TrustWalletCore"
options.input_generated = "#{CurrentDir}/../../include/Generated/TrustWalletCore"
options.output = "#{CurrentDir}/../../"
options.swift = true
options.java = true
Expand Down Expand Up @@ -63,17 +62,15 @@ end.parse!

entities = []
files = []
[options.input, options.input_generated].each do |input_dir|
Dir.foreach(input_dir) do |item|
next if ['.', '..', '.DS_Store'].include?(item)
Dir.foreach(options.input) do |item|
next if ['.', '..', '.DS_Store'].include?(item)

file_path = File.expand_path(File.join(input_dir, item))
entity = Parser.new(path: file_path).parse
next if entity.nil?
file_path = File.expand_path(File.join(options.input, item))
entity = Parser.new(path: file_path).parse
next if entity.nil?

entities << entity
files << File.basename(item, '.h').sub(/^TW/, '')
end
entities << entity
files << File.basename(item, '.h').sub(/^TW/, '')
end

generator = CodeGenerator.new(entities: entities, files: files, output_folder: options.output)
Expand Down
4 changes: 1 addition & 3 deletions kotlin/wallet-core-kotlin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,8 @@ kotlin {
includeDirs(
rootDir.parentFile.resolve("include"),
rootDir.parentFile.resolve("include/TrustWalletCore"),
rootDir.parentFile.resolve("include/Generated/TrustWalletCore")
)
headers(rootDir.parentFile.resolve("include/Generated/TrustWalletCore").listFiles()!! +
rootDir.parentFile.resolve("include/TrustWalletCore").listFiles()!!)
headers(rootDir.parentFile.resolve("include/TrustWalletCore").listFiles()!!)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/chains/TheOpenNetwork/TWTONAddressConverterTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include "TestUtilities.h"

#include "TrustWalletCore/TWTONAddressConverter.h"
#include <TrustWalletCore/TWTONAddressConverter.h>

namespace TW::TheOpenNetwork::tests {

Expand Down

0 comments on commit 9bab767

Please sign in to comment.