Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ISSUE #85 : Base64-Encoder Executable #93

Merged
merged 17 commits into from
Feb 18, 2025
Merged

Conversation

nav-mohan
Copy link

@nav-mohan nav-mohan commented Jan 21, 2025

Fixes issue #85
Currently, we use xxd and a native cmake implementation to encode parameter files for linking into a shared-library.
base64-encode is an executable meant to replace both.
It will be installed in the CMAKE_INSTALL_RELOC_BINDIR.

ipcamit and others added 6 commits January 12, 2025 14:17
A utility for base64 encoding and decoding of model and model-driver parameter files.
This biary executable will be used for compiling shared-libraries of model and model-driver.
This utility will be installed in the CMAKE_INSTALL_RELOC_BINDIR.
Specify build and installation instructions for kim_base64_encode.
kim_base64_encode is a critical dependant for building model/model-driver shared-libraries.
kim_base64_encode must be built before kim-api.
kim_base64_encode will be installed in the CMAKE_INSTALL_RELOC_BINDIR for system-wide access during compile-time of model/model-driver shared-libraries.
…ible now.

Stylistic changes:
   base64.hpp moved to KIM_Base64.hpp
   KIM_Base64.hpp edited to have 2 space indent
   Function names/variable names to follow PascalCase or camelCase (like other KIM-API files)
   Doxygen style docstrings
TODO:
   Licensing issue discussion with Ryan
This is a work in progress and the code is not expected to compile at this stage.
A number of small changes have been made to port the code from c++11 to c++98.
A pending change is to replace the string-literals with escaped characters.
Create the command-line-interface for kim-base64-encode following the docopt.org format keeping inline with other utils/kim-api-* binary executables
@ipcamit
Copy link

ipcamit commented Jan 21, 2025

@nav-mohan I think the Open suse error stems from the fact that it is using newer OpenSUSE with newer libasan, so now libasan6 should be updated to libasan8. Not sure if that will solve it but probably worth a shot.

See here: https://opensuse.pkgs.org/tumbleweed/opensuse-oss-x86_64/libasan8-14.2.1+git10750-1.2.x86_64.rpm.html

Copy link

codecov bot commented Jan 22, 2025

Codecov Report

Attention: Patch coverage is 93.50649% with 10 lines in your changes missing coverage. Please review.

Project coverage is 46.13%. Comparing base (4d125ff) to head (ab54495).
Report is 2 commits behind head on devel.

Files with missing lines Patch % Lines
cpp/src/third-party/libb64/src/cdecode.c 80.43% 7 Missing and 2 partials ⚠️
cpp/src/third-party/libb64/src/cencode.c 98.41% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##            devel      #93      +/-   ##
==========================================
+ Coverage   45.29%   46.13%   +0.83%     
==========================================
  Files         140      145       +5     
  Lines       13059    13359     +300     
  Branches     1338     1354      +16     
==========================================
+ Hits         5915     6163     +248     
- Misses       6476     6518      +42     
- Partials      668      678      +10     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Comment on lines 4 to 8
`base64-encode` is a simple xxd replacement to convert files
into embeddable C++ source code. Instead of using binary array
it used base64 strings, which makes it much more performant
for large files. Currently only -i option is supported for
compatibility. More options to be released in future. C++ 98 compliant.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
`base64-encode` is a simple xxd replacement to convert files
into embeddable C++ source code. Instead of using binary array
it used base64 strings, which makes it much more performant
for large files. Currently only -i option is supported for
compatibility. More options to be released in future. C++ 98 compliant.
`base64-encode` is a straightforward replacement for xxd,
designed to convert files into embeddable C++ source code.
Unlike binary arrays, it utilizes base64 strings, significantly
enhancing performance for large files. Currently, only the -i
option is supported for compatibility, with more options
planned for future releases. It is compliant with C++98 standards.

@nav-mohan nav-mohan force-pushed the devel branch 3 times, most recently from ef8c6f5 to 1ddb0ed Compare February 2, 2025 18:54
@ipcamit
Copy link

ipcamit commented Feb 3, 2025

@nav-mohan Regardinhe Fedora debug is failing while complaining about position independent code. I think we can fix it by including

set_target_properties(b64 PROPERTIES POSITION_INDEPENDENT_CODE ON)

in the cpp/libb64/CMakeLists.txt file.

The window test seems to be failing from CRLF file endings, that is bit strange but needs closer looking into. Perhaps I can try manually looking into the generated C++ files on windows when I get time. Perhaps a windows os based macro to write "\r\n" is needed.

@nav-mohan
Copy link
Author

@nav-mohan Regardinhe Fedora debug is failing while complaining about position independent code. I think we can fix it by including

set_target_properties(b64 PROPERTIES POSITION_INDEPENDENT_CODE ON)

in the cpp/libb64/CMakeLists.txt file.

The window test seems to be failing from CRLF file endings, that is bit strange but needs closer looking into. Perhaps I can try manually looking into the generated C++ files on windows when I get time. Perhaps a windows os based macro to write "\r\n" is needed.

@ipcamit thanks for looking into it. if you cant' acquire a Windows machine, you could execute these Github Actions workflows on your own fork of the repo.

@nav-mohan
Copy link
Author

nav-mohan commented Feb 5, 2025

@nav-mohan Regardinhe Fedora debug is failing while complaining about position independent code. I think we can fix it by including

set_target_properties(b64 PROPERTIES POSITION_INDEPENDENT_CODE ON)

in the cpp/libb64/CMakeLists.txt file.

The window test seems to be failing from CRLF file endings, that is bit strange but needs closer looking into. Perhaps I can try manually looking into the generated C++ files on windows when I get time. Perhaps a windows os based macro to write "\r\n" is needed.

@ipcamit Some updates:
I was able to reproduce the MINGW bug by installing MINGW on my Ubuntu machine (sudo apt install mingw-w64) and using the MINGW compiler in my CMAKE

set(CMAKE_C_COMPILER x86_64-w64-mingw32-gcc)
set(CMAKE_CXX_COMPILER x86_64-w64-mingw32-g++)
set(CMAKE_EXE_LINKER_FLAGS "-static -static-libgcc -static-libstdc++")

A quick screenshot to show the output from mingw and gcc when used to encode examples/model-drivers/ex_model_driver_P_LJ/item-compiled-with-version.txt
image
The closing-quote and the semi-colon are at the start of the line as opposed to end of the line.
You were right in that the root cause of this problem is in the difference between newline characters in mingw (\r\n) and gcc(\n).
The particular bug we're seeing is due to the step of rewinding by 1 character which resets the write-head back to start of the line.
I've found two possible solutions to this

  1. open the output filestream in binary-mode -- this prevents any ambiguity between \r\n and \n. 1 byte in either case is \n
  2. comment out this line in the libb64 library source-code.

As for the Fedora workflow, enabling the PIC flag worked and that build runs successfully now.

@ipcamit
Copy link

ipcamit commented Feb 5, 2025

Thank you @nav-mohan for investigating this. I think 2 is a better solution. Then we can remove the seekp line as well. Please log the changes in the .origin file as well.

@ilia-nikiforov-umn
Copy link

@ellio167 do you know how to handle the billing issue with the MacOS runners? I looked at the openkim organization billing page and didn't see anything obvious, but as @ipcamit pointed out offline, it might be up to the PR author to pay (since otherwise a malicious actor could bill someone's account just by submitting PRs)

@ellio167
Copy link
Member

ellio167 commented Feb 6, 2025

We've never setup billing for github, I don't think. So, I think the settings for the openkim org as such that nothing non-free can run.

I would guess that we could change this and add a payment method (a pcard from one of the AEM staff, I suppose). However, don't know if that's something we want to do... Plus, I don't know anything about setting this up or maintaining/securing it...

@ilia-nikiforov-umn
Copy link

We've never setup billing for github, I don't think. So, I think the settings for the openkim org as such that nothing non-free can run.

I would guess that we could change this and add a payment method (a pcard from one of the AEM staff, I suppose). However, don't know if that's something we want to do... Plus, I don't know anything about setting this up or maintaining/securing it...

Got it, I'll see if I can figure out what to do here.

@nav-mohan
Copy link
Author

nav-mohan commented Feb 6, 2025

@ilia-nikiforov-umn @ellio167 We can control specific triggers for running the build workflow.
We could disable the pull_request trigger. I'll see if there's a way to disable it specifically for the MacOS builds.
image

@ipcamit
Copy link

ipcamit commented Feb 11, 2025

So what is the the status for this PR? Just want to know if anything is to be done at my end?

@ilia-nikiforov-umn
Copy link

@ilia-nikiforov-umn @ellio167 We can control specific triggers for running the build workflow. We could disable the pull_request trigger. I'll see if there's a way to disable it specifically for the MacOS builds. image

@nav-mohan can you try removing the -large from the MacOS runners and see if that will work?

https://github.com/orgs/community/discussions/102846#discussioncomment-9344474

macos-14 is free, macos-14-large using more CPUs is not.

@nav-mohan nav-mohan force-pushed the devel branch 2 times, most recently from 602948d to afd1afe Compare February 11, 2025 23:03
@nav-mohan
Copy link
Author

@ilia-nikiforov-umn thanks for pointing that out. That was one of the issues.
Some further changes were needed for the compilers.
@ipcamit @ellio167 all the builds are working now.

@ellio167
Copy link
Member

@nav-mohan Can you please revert most of the changes in the PR so as to minimize the differences between the master devel branch and this PR? In particular, you've merged in changes from an official release which has made changes to essentially all the files by putting a specific version number in the file headers. Changes like this

-# Release: This file is part of the kim-api.git repository.
+# Release: This file is part of the kim-api-2.3.0 package.

should be eliminated. Thank you.

ipcamit and others added 10 commits February 12, 2025 17:00
libasan6 is deprecated and has been updated to libasan8
MacOS 10//11 is not supported by Github Actions and has been updated to Mac 13/14
Fortran compiler is not included in mingw-toolchain and must be explicitly installed
Fedora requires POSITION_INDEPENDENT_CODE ON when linking a static library (libb64) with a dynamic library (kim-api)
Workflows can now be manually triggered through web UI.
Going forward we'll try to store all external libraries in this folder
A small modification to libb64 is required to ensure the output of kim-api-base64-encode returns a valid C++ source-file.
	use MacOS-13, MacOS-14 instead of MacOS-13-large, MacOS-14-large
	use clang++ compiler
	use gfortran-14 compiler
@nav-mohan
Copy link
Author

@ellio167 commits have been squashes/dropped and the branch has been cleaned up.

@ellio167
Copy link
Member

I think this is ready; @nav-mohan @ipcamit take a final look to see if any of my refactors are objectionable.

@ipcamit
Copy link

ipcamit commented Feb 18, 2025

Looks good to me!

@nav-mohan
Copy link
Author

Looks good to me as well!

@ellio167 ellio167 merged commit 6fe9881 into openkim:devel Feb 18, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants