Skip to content

Commit

Permalink
re #464: smaller test case; cross-compile, qemu; command:
Browse files Browse the repository at this point in the history
set -xe ; cd ~/proj/rapidyaml/samples/add_subdirectory/ ; sys=powerpc64le ; cxxflags="-O2 -flto=auto -ffat-lto-objects  -fexceptions -g -grecord-gcc-switches -pipe -Wall -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -std=c++11 -DNDEBUG" ; bdir=build/$sys ; mkdir -p $bdir ; cmake -S . -B $bdir -D CMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS_RELEASE:STRING="$cxxflags" --toolchain ../../.github/toolchains/linux-gnu-$sys.cmake ; cmake --build $bdir --target run -j --verbose

to run the tests:

( set -xe ; \
cxxflags="-O2 -flto=auto -ffat-lto-objects  -fexceptions -g -grecord-gcc-switches -pipe -Wall -Wp,-U_FORTIFY_SOURCE,-D_FORTIFY_SOURCE=3 -Wp,-D_GLIBCXX_ASSERTIONS -std=c++11 -DNDEBUG" ; \
cd /rapidyaml/ ; \
sys=powerpc64le ; \
bdir=build/$sys ; \
mkdir -p $bdir ; \
cmake -S . -B $bdir \
  -D CMAKE_BUILD_TYPE=Release \
  -DRYML_BUILD_TESTS=ON \
  -DGIT=/usr/bin/git    \\
  -DCMAKE_CXX_FLAGS_RELEASE:STRING="$cxxflags"      \
   --toolchain .github/toolchains/linux-gnu-$sys.cmake  ;  \
for t in quickstart parse_engine_6_qmrk parse_engine_7_seqimap tree emit json merge seq map scalar_null anchor number ; do \
cmake --build $bdir -j --verbose --target ryml-test-$t \
  && qemu-ppc64le-static $bdir/test/ryml-test-$t \
  || echo "\n\n\nFAILED\n\n" ; \
done )
  • Loading branch information
biojppm committed Aug 20, 2024
1 parent 5e91f35 commit beeabe4
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 44 deletions.
26 changes: 26 additions & 0 deletions .github/toolchains/linux-gnu-powerpc64le.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
set(CMAKE_SYSTEM_NAME Linux)
set(CROSS_COMPILER_PREFIX /usr)
set(CROSS_COMPILER_TARGET powerpc64le-linux-gnu)
set(CMAKE_SYSTEM_PROCESSOR powerpc64le)
set(CMAKE_CROSSCOMPILING_EMULATOR qemu-ppc64le-static)
set(CMAKE_C_COMPILER ${CROSS_COMPILER_PREFIX}/bin/${CROSS_COMPILER_TARGET}-gcc)
set(CMAKE_CXX_COMPILER ${CROSS_COMPILER_PREFIX}/bin/${CROSS_COMPILER_TARGET}-g++)
set(CMAKE_AR ${CROSS_COMPILER_PREFIX}/bin/${CROSS_COMPILER_TARGET}-ar CACHE FILEPATH "Archiver")
set(CMAKE_MAKE_PROGRAM ${CROSS_COMPILER_PREFIX}/bin/make CACHE FILEPATH "make")

# use -static to avoid having to install the dynamic loader
# see https://mfo.dev.br/2018/03/17/ppc64le-on-x86_64-cross-compilers.html
set(CMAKE_CXX_FLAGS -static)
set(CMAKE_C_FLAGS -static)

set(CMAKE_FIND_ROOT_PATH ${CROSS_COMPILER_PREFIX}/${CROSS_COMPILER_TARGET})
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

# needed ubuntu packages:
#
# sudo apt-get install -y \
# gcc-powerpc64le-linux-gnu \
# g++-powerpc64le-linux-gnu \
# qemu-user-system
90 changes: 50 additions & 40 deletions .github/workflows/rarearchs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -115,55 +115,65 @@ jobs:
fi
time apt-get install -y cmake cmake-data
cmake --version
echo "install took $((SECONDS - start_time))"
echo "install took $((SECONDS - start_time))s"
run: |
set -xe
start_time=$SECONDS
uname -a
pwd
ls -lFhp .
#
# https://stackoverflow.com/questions/5470257/how-to-see-which-flags-march-native-will-activate
echo | c++ -O0 -Q -E -v - </dev/null 2>&1
echo | c++ -O0 -Q -c --help=optimizers --help=target
echo | c++ -O0 -dM -E - | sort
echo -----
echo | c++ -O1 -Q -E -v - </dev/null 2>&1
echo | c++ -O1 -Q -c --help=optimizers --help=target
echo | c++ -O1 -dM -E - | sort
echo -----
echo | c++ -O2 -Q -E -v - </dev/null 2>&1
echo | c++ -O2 -Q -c --help=optimizers --help=target
echo | c++ -O2 -dM -E - | sort
echo -----
echo | c++ -O3 -Q -E -v - </dev/null 2>&1
echo | c++ -O3 -Q -c --help=optimizers --help=target
echo | c++ -O3 -dM -E - | sort
echo =====
#
##
## https://stackoverflow.com/questions/5470257/how-to-see-which-flags-march-native-will-activate
#echo | c++ -O0 -Q -E -v - </dev/null 2>&1
#echo | c++ -O0 -Q -c --help=optimizers --help=target
#echo | c++ -O0 -dM -E - | sort
#echo -----
#echo | c++ -O1 -Q -E -v - </dev/null 2>&1
#echo | c++ -O1 -Q -c --help=optimizers --help=target
#echo | c++ -O1 -dM -E - | sort
#echo -----
#echo | c++ -O2 -Q -E -v - </dev/null 2>&1
#echo | c++ -O2 -Q -c --help=optimizers --help=target
#echo | c++ -O2 -dM -E - | sort
#echo -----
#echo | c++ -O3 -Q -E -v - </dev/null 2>&1
#echo | c++ -O3 -Q -c --help=optimizers --help=target
#echo | c++ -O3 -dM -E - | sort
#echo =====
##
bdir=build_${{matrix.arch}}_${{matrix.bt}}_${{matrix.std}}
idir=install_${{matrix.arch}}_${{matrix.bt}}_${{matrix.std}}
mkdir -p $bdir
#
cmd="cmake -S . -B $bdir \
-DCMAKE_INSTALL_PREFIX=$idir \
-DCMAKE_BUILD_TYPE=${{matrix.bt}} \
-DC4_CXX_STANDARD=${{matrix.std}} \
-DCXX_STANDARD=${{matrix.std}} \
-DRYML_DEV=ON \
-DRYML_TEST_SUITE=ON \
-DRYML_BUILD_BENCHMARKS=OFF \
-DRYML_SANITIZE=OFF \
-DRYML_LINT=OFF \
-DRYML_VALGRIND=OFF"
echo $cmd
cd samples/add_subdirectory
mkdir -p $bdir
if [ -z "${{matrix.cxxflags}}" ] ; then
time $cmd
time cmake -S . -B $bdir -DCMAKE_BUILD_TYPE=${{matrix.bt}}
else
time $cmd -DCMAKE_CXX_FLAGS_RELEASE:STRING="${{matrix.cxxflags}}"
time cmake -S . -B $bdir -DCMAKE_BUILD_TYPE=${{matrix.bt}} \
-DCMAKE_CXX_FLAGS_RELEASE:STRING="${{matrix.cxxflags}}"
fi
#
time cmake --build $bdir --verbose -j 4 --target ryml-test-build
#
time cmake --build $bdir --target ryml-test-run
echo "run took $((SECONDS - start_time))"
cmake --build $bdir --config ${{matrix.bt}} -j 3 --target run
##
#mkdir -p $bdir
#cmd="cmake -S . -B $bdir \
# -DCMAKE_INSTALL_PREFIX=$idir \
# -DCMAKE_BUILD_TYPE=${{matrix.bt}} \
# -DC4_CXX_STANDARD=${{matrix.std}} \
# -DCXX_STANDARD=${{matrix.std}} \
# -DRYML_DEV=ON \
# -DRYML_TEST_SUITE=ON \
# -DRYML_BUILD_BENCHMARKS=OFF \
# -DRYML_SANITIZE=OFF \
# -DRYML_LINT=OFF \
# -DRYML_VALGRIND=OFF"
#echo $cmd
#if [ -z "${{matrix.cxxflags}}" ] ; then
# time $cmd
#else
# time $cmd -DCMAKE_CXX_FLAGS_RELEASE:STRING="${{matrix.cxxflags}}"
#fi
##
#time cmake --build $bdir --verbose -j 4 --target ryml-test-build
##
#time cmake --build $bdir --target ryml-test-run
echo "run took $((SECONDS - start_time))s"
13 changes: 9 additions & 4 deletions samples/quickstart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ int report_checks();

int main()
{
sample::sample_json();
#ifdef WTF
sample::sample_lightning_overview();
sample::sample_quick_overview();
sample::sample_substr();
Expand Down Expand Up @@ -113,6 +115,7 @@ int main()
sample::sample_per_tree_allocator();
sample::sample_static_trees();
sample::sample_location_tracking();
#endif // WTF
return sample::report_checks();
}

Expand Down Expand Up @@ -229,7 +232,6 @@ struct CheckPredicate
#define CHECK(predicate) assert(predicate)
#endif


// helper functions for sample_parse_file()
template<class CharContainer> CharContainer file_get_contents(const char *filename);
template<class CharContainer> size_t file_get_contents(const char *filename, CharContainer *v);
Expand Down Expand Up @@ -264,6 +266,7 @@ struct ScopedErrorHandlerExample : public ErrorHandlerExample
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------

#ifdef WTF
/** a lightning tour over most features
* see @ref sample_quick_overview */
void sample_lightning_overview()
Expand Down Expand Up @@ -4268,7 +4271,7 @@ void sample_emit_style()

//-----------------------------------------------------------------------------


#endif // WTF
/** shows how to parse and emit JSON. */
void sample_json()
{
Expand All @@ -4286,11 +4289,13 @@ void sample_json()
// has a smaller grammar:
ryml::Tree json_tree = ryml::parse_json_in_arena(json);
// to emit JSON, use the proper overload:
std::cout << "WTF1:\n" << ryml::emitrs_json<std::string>(tree) << "\n";
CHECK(ryml::emitrs_json<std::string>(tree) == R"({"doe": "a deer, a female deer","ray": "a drop of golden sun","me": "a name, I call myself","far": "a long long way to go"})");
CHECK(ryml::emitrs_json<std::string>(json_tree) == R"({"doe": "a deer, a female deer","ray": "a drop of golden sun","me": "a name, I call myself","far": "a long long way to go"})");
// to emit JSON to a stream:
std::stringstream ss;
ss << ryml::as_json(tree); // <- mark it like this
std::cout << "WTF2:\n" << ss.str() << "\n";
CHECK(ss.str() == R"({"doe": "a deer, a female deer","ray": "a drop of golden sun","me": "a name, I call myself","far": "a long long way to go"})");
// Note the following limitations:
//
Expand All @@ -4304,7 +4309,7 @@ void sample_json()
// - anchors and references cannot be emitted as json and
// are not allowed.
}

#ifdef WTF

//-----------------------------------------------------------------------------

Expand Down Expand Up @@ -5185,7 +5190,7 @@ seq with key:
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------


#endif // WTF
/** @addtogroup doc_sample_helpers
* @{ */

Expand Down

0 comments on commit beeabe4

Please sign in to comment.