Hey devs,
I'm trying to integrate a third party botan pre-built library in chromium. Below I've mentioned all the changes I did..
Not exactly sure what I'm doing wrong. Tried setting is_component_build and use_lld to false. That did not work.
BUILD.gn
```
import("//build/config/c++/c++.gni")
import("//build/config/sanitizers/sanitizers.gni")
import("//build/toolchain/toolchain.gni")
import("//build/config/arm.gni")
import("//build/config/compiler/compiler.gni")
# Define botan configuration options
config("botan_build") {
ldflags = [
"-I/usr/local/include/botan-3",
"-lbotan-3",
"-L/usr/local/lib/",
"-nostdlib++",
"-Wl",
"-fuse-ld=lld",
]
cflags_cc = ["-I/usr/local/include/botan-3", "-std=c++20"]
cflags = ["-I/usr/local/include/botan-3"]
#include_dirs = [ "//brave/third_party/botan/botan-3" ]
#libs = [ "botan-3" ]
#lib_dirs = [ "//brave/third_party/botan/libs" ]
print("Botan config options applied with ldflags: $ldflags and cflags_cc: $cflags_cc")
}
# Define the botan source set
source_set("botan") {
target_name = "botan"
check_includes = false
# Remove unwanted configurations
configs -= [
"//build/config/compiler:chromium_code",
"//build/config/compiler:no_exceptions",
"//build/config/compiler:no_rtti",
"//build/config/coverage:default_coverage",
]
# Add required configurations
configs += [
"//build/config/compiler:no_chromium_code",
"//build/config/compiler:exceptions",
"//build/config/compiler:rtti",
":botan_build", # Ensure botan config options are added here
]
# public_configs = [":botan-build"]
sources = [
"src/pkcs.h",
"src/pkcs.cc",
]
configs -= ["//build/config/sanitizers:default_sanitizer_flags"]
}
```
pkcs.h
```
#ifndef MYCLASS_H
#define MYCLASS_H
namespace botanmylib {
class myclass {
public:
static int calculate();
};
} // namespace extensions
#endif // MYCLASS_H
```
pkcs.cc
```
#include <fstream>
#include <vector>
#include <iostream>
#include <cstddef>
#include <string>
#include "brave/third_party/botan/src/pkcs.h"
#include <botan/auto_rng.h>
#include <botan/p11.h>
#include <botan/p11_rsa.h>
#include <botan/p11_object.h>
#include <botan/p11_types.h>
#include <botan/pubkey.h>
#include <botan/rsa.h>
#include <botan/secmem.h>
extern int botanmylib::myclass::calculate()
{
std::cout<<"botan starting";
Botan::PKCS11::Module module("/usr/local/lib/libcastle_v2.1.0.0.dylib");
// open write session to first slot with connected token
std::cout<<"Hello world botan here";
return 0;
}
```
and I've added the corresponding deps: "//brave/third_party/botan:botan"
but while calling the method botanmylib::myclass::calculate(), the build fails at stage SOLINK libchrome_dll.dylib libchrome_dll.dylib.TOC with the following error:
```
ld64.lld: error: undefined symbol: Botan::PKCS11::Module::Module(std::__Cr::basic_string_view<char, std::__Cr::char_traits<char>>, CK_C_INITIALIZE_ARGS)
>>> referenced by pkcs.cc:21 (../../brave/third_party/botan/src/pkcs.cc:21)
>>> obj/brave/third_party/botan/botan/pkcs.o:(symbol botanmylib::myclass::calculate12()+0x5c)
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
Traceback (most recent call last):
File "/Users/Shubham.Kumar/projects/chromium/src/out/Component_arm64/../../build/toolchain/apple/linker_driver.py", line 367, in <module>
LinkerDriver(sys.argv).run()
File "/Users/Shubham.Kumar/projects/chromium/src/out/Component_arm64/../../build/toolchain/apple/linker_driver.py", line 151, in run
subprocess.check_call(compiler_driver_args, env=env)
File "/Users/Shubham.Kumar/projects/chromium/src/brave/vendor/depot_tools/boots...@3.11.8.chromium.35_bin/python3/lib/python3.11/subprocess.py", line 413, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['../../third_party/llvm-build/Release+Asserts/bin/clang++', '-shared', '-Wl,-install_name,@rpath/libchrome_dll.dylib', '-Wl,-order_file', '-Wl,../../chrome/app/framework.order', '-ObjC', '-I/usr/local/include/botan-3', '-lbotan-3', '-L/usr/local/lib/', '-nostdlib++', '-Wl', '-fuse-ld=lld', '-Werror', '-fuse-ld=lld', '-Wl,-fatal_warnings', '-Wl,--icf=all', '-Wl,--color-diagnostics', '-Wl,--strict-auto-link', '-Wl,--no-call-graph-profile-sort', '-arch', 'arm64', '-fno-global-isel', '-Wl,-mllvm,-enable-machine-outliner=never', '-no-canonical-prefixes', '-Wl,-dead_strip', '-nostdlib++', '-isysroot', '../../../../../../../Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.4.sdk', '-mmacos-version-min=10.13', '-Wl,-ObjC', '-Wl,-rpath,@loader_path/.', '-Wl,-rpath,@loader_path/../../..', '-rpath', '@executable_path/', '-L/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.4.sdk/usr/lib', '-o', './libchrome_dll.dylib', '@./libchrome_dll.dylib.rsp']' returned non-zero exit status 1.
ninja: build stopped: subcommand failed.
```