Skip to content

Commit

Permalink
linux-arm64 build somewhat working?
Browse files Browse the repository at this point in the history
  • Loading branch information
duvallj committed Feb 26, 2024
1 parent 3ecf646 commit d4aceff
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 63 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
.vs
.DS_Store
build
build-*
gcc-arm-*
compile_commands.json
example
node_modules
Expand Down
57 changes: 16 additions & 41 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ project(${MODULE})
include(ExternalProject)
find_package(Git REQUIRED)
find_package(Threads REQUIRED)
find_program(iwyu_path OPTIONAL NAMES include-what-you-use iwyu)
find_program(clang_tidy_path OPTIONAL NAMES clang-tidy)

# depot_tools
# -----------------------------------------------------------------------------
Expand Down Expand Up @@ -151,7 +149,19 @@ list(APPEND GN_GEN_ARGS
use_lld=false
)

if (APPLE)
macro(assign_bool var)
if (${ARGN})
set(${var} ON)
else()
set(${var} OFF)
endif()
endmacro()

assign_bool(use_custom_libcxx APPLE)
assign_bool(is_arm32 "$ENV{TARGET_ARCH}" STREQUAL "arm")
assign_bool(is_arm64 "$ENV{TARGET_ARCH}" STREQUAL "arm64")

if (${use_custom_libcxx})
list(APPEND GN_GEN_ARGS
use_custom_libcxx=true
)
Expand All @@ -161,12 +171,12 @@ else()
)
endif()

if ("$ENV{TARGET_ARCH}" STREQUAL "arm")
if (${is_arm32})
list(APPEND GN_GEN_ARGS
target_cpu="arm"
rtc_build_tools=true
)
elseif ("$ENV{TARGET_ARCH}" STREQUAL "arm64")
elseif (${is_arm64})
list(APPEND GN_GEN_ARGS
target_cpu="arm64"
rtc_build_tools=true
Expand Down Expand Up @@ -304,14 +314,6 @@ set_target_properties(${MODULE} PROPERTIES PREFIX "" SUFFIX ".node")

set_property(TARGET ${MODULE} PROPERTY CXX_STANDARD 14)

if(NOT iwyu_path STREQUAL "iwyu_path-NOTFOUND")
set_property(TARGET ${MODULE} PROPERTY CXX_INCLUDE_WHAT_YOU_USE ${iwyu_path} -Xiwyu --mapping_file=${CMAKE_SOURCE_DIR}/.iwyu.imp)
endif()

if(NOT clang_tidy_path STREQUAL "clang_tidy_path-NOTFOUND")
set_property(TARGET ${MODULE} PROPERTY CXX_CLANG_TIDY ${clang_tidy_path})
endif()

# NOTE(mroberts): Workaround for
#
# https://gitlab.kitware.com/cmake/cmake/issues/15052
Expand Down Expand Up @@ -395,7 +397,7 @@ else()
"$<$<CONFIG:Debug>:-DDEBUG>"
)

if (APPLE OR "$ENV{TARGET_ARCH}" STREQUAL "arm" OR "$ENV{TARGET_ARCH}" STREQUAL "arm64")
if (${use_custom_libcxx})
# NOTE(mroberts): Workaround for
#
# https://gitlab.kitware.com/cmake/cmake/issues/15052
Expand Down Expand Up @@ -459,33 +461,6 @@ else()
target_compile_options(${MODULE} PRIVATE
-fpermissive
)

if ("$ENV{TARGET_ARCH}" STREQUAL "arm" OR "$ENV{TARGET_ARCH}" STREQUAL "arm64")
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR "$ENV{TARGET_ARCH}")
set(tools $ENV{ARM_TOOLS_PATH})

set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)

if ("$ENV{TARGET_ARCH}" STREQUAL "arm")
set(CMAKE_SYSROOT ${libwebrtc_source_dir}/src/build/linux/debian_sid_arm-sysroot)
target_compile_options(${MODULE} PRIVATE
-march=armv7-a
-mfloat-abi=hard
-mtune=generic-armv7-a
-mfpu=neon
)
set(CMAKE_C_COMPILER ${tools}/bin/arm-linux-gnueabihf-gcc)
set(CMAKE_CXX_COMPILER ${tools}/bin/arm-linux-gnueabihf-g++)
else()
set(CMAKE_SYSROOT ${libwebrtc_source_dir}/src/build/linux/debian_sid_arm64-sysroot)
set(CMAKE_C_COMPILER ${tools}/bin/aarch64-linux-gnu-gcc)
set(CMAKE_CXX_COMPILER ${tools}/bin/aarch64-linux-gnu-g++)
endif()
endif()
endif()
endif()

Expand Down
9 changes: 5 additions & 4 deletions lib/binding.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
'use strict';

const os = require('os');
const triple = `${os.platform()}-${os.arch()}`;
const paths_to_try = [
'../build/wrtc.node',
'../build/Debug/wrtc.node',
'../build/Release/wrtc.node',
`@roamhq/wrtc-${os.platform()}-${os.arch()}`,
`../build-${triple}/wrtc.node`,
`../build-${triple}/Debug/wrtc.node`,
`../build-${triple}/Release/wrtc.node`,
`@roamhq/wrtc-${triple}`,
];

let succeeded = false;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@
"lint": "eslint lib/*.js lib/**/*.js test/*.js test/**/*.js scripts/*.js",
"test": "node --expose-gc test/all.js"
}
}
}
2 changes: 1 addition & 1 deletion prebuilds/linux-x64/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
"cpu": [
"x64"
]
}
}
9 changes: 6 additions & 3 deletions scripts/build-from-source.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
'use strict';

const { spawnSync } = require('child_process');
const os = require('os');
const platform = os.platform();
const arch = process.env.TARGET_ARCH ?? os.arch();

const args = ['configure'];
const args = ['-O', `build-${platform}-${arch}`, '-a', arch];

if (process.env.DEBUG) {
args.push(...[
Expand All @@ -26,7 +29,7 @@ if (process.env.TARGET_ARCH) {

function main() {
console.log('Running cmake-js ' + args.join(' '));
let { status } = spawnSync('cmake-js', args, {
let { status } = spawnSync('cmake-js', ['configure', ...args], {
shell: true,
stdio: 'inherit'
});
Expand All @@ -35,7 +38,7 @@ function main() {
}

console.log('Running cmake-js build');
status = spawnSync('cmake-js', ['build'], {
status = spawnSync('cmake-js', ['build', ...args], {
shell: true,
stdio: 'inherit'
}).status;
Expand Down
6 changes: 1 addition & 5 deletions scripts/build-webrtc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,4 @@ case "$(uname -s)" in
export TARGETS="$TARGETS libc++ libc++abi"
esac

if [ -z "$PARALLELISM" ]; then
ninja $TARGETS
else
ninja $TARGETS -j $PARALLELISM
fi
ninja $TARGETS
8 changes: 0 additions & 8 deletions scripts/configure-webrtc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,6 @@ export PATH=$DEPOT_TOOLS:$PATH

cd ${SOURCE_DIR}

if [ "$TARGET_ARCH" == "arm" ]; then
python build/linux/sysroot_scripts/install-sysroot.py --arch=arm
elif [ "$TARGET_ARCH" == "arm64" ]; then
python build/linux/sysroot_scripts/install-sysroot.py --arch=arm64
else
python build/linux/sysroot_scripts/install-sysroot.py --arch=amd64
fi

# NOTE(mroberts): Running hooks generates this file, but running hooks also
# takes too long in CI; so do this manually.
(cd build/util && python lastchange.py -o LASTCHANGE)
Expand Down
13 changes: 13 additions & 0 deletions toolchains/linux-arm64.toolchain
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR arm64)

set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)

set(arm_bindir /home/user/node-webrtc/gcc-arm-10.3-2021.07-x86_64-aarch64-none-linux-gnu/bin) # Change this if necessary
# These compilers should come with a sysroot built in.
# If not, set CMAKE_SYSROOT accordingly
set(CMAKE_C_COMPILER ${arm_bindir}/aarch64-none-linux-gnu-gcc)
set(CMAKE_CXX_COMPILER ${arm_bindir}/aarch64-none-linux-gnu-g++)

0 comments on commit d4aceff

Please sign in to comment.