Skip to content

Implement CPack for Debian/RPM#2590

Merged
kabeor merged 1 commit intocapstone-engine:nextfrom
AndrewQuijano:cpack
Jan 20, 2025
Merged

Implement CPack for Debian/RPM#2590
kabeor merged 1 commit intocapstone-engine:nextfrom
AndrewQuijano:cpack

Conversation

@AndrewQuijano
Copy link
Copy Markdown
Contributor

@AndrewQuijano AndrewQuijano commented Dec 22, 2024

Your checklist for this pull request

  • I've documented or updated the documentation of every API function and struct this PR changes.
  • I've added tests that prove my fix is effective or that my feature works (if possible)

Detailed description
I created a CPackConfig.txt that can create both Debian and RPM packages. The Debian package matches what we have now. I can look further about making a proper RPM package.

Debian Screenshots
image
image
This is identical to #2579
image

RPM
image
image

Here is the generated spec file
libcapstone-dev.spec.txt

I do want to get help with macOS package creation and testing using CPack

I updated how to do this in the Building.md file

...

Test plan
We can probably use something like check_capstone.sh? Although for now, we can merge it as another way to create the Debian Package? My hope is, from here, work can be done to get a Mac OSX package built. I can help with RPM, the work is done, but any last necessary touches I can take care of it.

...

Closing issues

...

@AndrewQuijano AndrewQuijano changed the title Implement CPack for Debian/RPM Implement CPack for Debian/RPM and delete Travis Dec 22, 2024
@AndrewQuijano
Copy link
Copy Markdown
Contributor Author

AndrewQuijano commented Dec 27, 2024

@Rot127 While I will need help with the Mac stuff, I can try to poke around how capstone made RPM packages before, but your feedback would be helpful to have! I did poke around and find this, it seems the RPM packaging standard is a lot more of a mess than I thought as it seems anyone can package as they see fit.

https://rpmfind.net/linux/rpm2html/search.php?query=libcapstone-devel
https://rpmfind.net/linux/rpm2html/search.php?query=capstone
https://rpmfind.net/linux/rpm2html/search.php?query=capstone-devel

I do want to ask, if the goal is to automate placing Debian packages in APT, this would require creating both a libcapstone package with the shared objects only and another debian with the static library/headers. I could use cmake twice and leverage CPack to make two packages. To avoid the headers being made twice, would I need to delete these lines of code?

https://github.com/capstone-engine/capstone/blob/next/CMakeLists.txt#L799-L801

@Rot127
Copy link
Copy Markdown
Collaborator

Rot127 commented Dec 29, 2024

Sorry for the late answer. I will review this one after new year. But to answer your questions meanwhile:

I do want to ask, if the goal is to #2537, this would require creating both a libcapstone package with the shared objects only and another debian with the static library/headers.

Yes, this would be nice to have. Though, I can't put any priority on it. And before v6 Beta, it is not necessary. I think for v6 Gold it is though.

try to poke around how capstone made RPM packages before, but your feedback would be helpful to have!

I have no idea. They were made before my time here. You have to contact the package maintainers and/or follow the docs.

@AndrewQuijano AndrewQuijano force-pushed the cpack branch 4 times, most recently from 419750b to 12879d4 Compare December 31, 2024 00:08
@AndrewQuijano
Copy link
Copy Markdown
Contributor Author

AndrewQuijano commented Dec 31, 2024

I poked around a bit more about making the RPM the best I can, so a few things I'll likely need help on,
I will ask based on this
https://github.com/capstone-engine/capstone/blob/next/packages/rpm/capstone.spec

  1. It would be nice to have something to check if the package works, is this legit?
ln -s libcapstone.so libcapstone.so.5
make check LD_LIBRARY_PATH="`pwd`"
  1. It would be nice to have an install too, would this look accurate to add?
DESTDIR=%{buildroot} LIBDIRARCH=%{_lib} \
INCDIR="%{_includedir}" make install
find %{buildroot} -name '*.la' -exec rm -f {} ';'
find %{buildroot} -name '*.a' -exec rm -f {} ';'

# install python bindings
pushd bindings/python
%{__python2} setup.py install --skip-build --root %{buildroot}
%if 0%{?with_python3}
%{__python3} setup.py install --skip-build --root %{buildroot}
%endif # with_python3
popd

# install java bindings
install -D -p -m 0644 bindings/java/%{name}.jar  %{buildroot}/%{_javadir}/%{name}.jar
  1. I'm not sure if a build would be need for the package?
DESTDIR="%{buildroot}" 	V=1 CFLAGS="%{optflags}" \
LIBDIRARCH="%{_lib}" INCDIR="%{_includedir}" make %{?_smp_mflags}

# Fix pkgconfig file
sed -i 's;%{buildroot};;' capstone.pc
grep -v archive capstone.pc > capstone.pc.tmp
mv capstone.pc.tmp capstone.pc

# build python bindings
pushd bindings/python
CFLAGS="%{optflags}" %{__python2} setup.py build
%if 0%{?with_python3}
CFLAGS="%{optflags}" %{__python3} setup.py build
%endif # with_python3
popd

# build java bindings
pushd bindings/java
make CFLAGS="%{optflags}" # %{?_smp_mflags} parallel seems broken
popd
  1. Please feel free to check my current generated spec file and poke around what else should be needed to make this as high quality as possible. I'm also realizing there is no contacts to who packages for Fedora and CentOS, etc.

  2. No worries, we can wait until next year, but will also need your help on updating CPack to also generate the Mac packages too :)

Copy link
Copy Markdown
Collaborator

@Rot127 Rot127 left a comment

Choose a reason for hiding this comment

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

Nice! Thanks a lot for getting started with it.

Some general notes:

  • Let's exclude OSX for now, please. It gets too much otherwise and they can be part of another PR.
  • The packages/rpm/capstone.spec file shouldn't be necessary. I think it can be removed. CPack should generate it.
  • Once we have tested the package build locally, we can add the process to the release workflow.

Regarding #2590 (comment)

This looks a little hacky. Let's not worry about the bindings for now. Because they need some refactoring before (see: #2291).
And maybe there are way better ways to create such packages. In the case of the Python bindings, they are already uploaded to pypi.

Comment thread CPackConfig.txt Outdated
Comment thread CPackConfig.txt Outdated
Comment thread CPackConfig.txt Outdated
Comment thread packages/rpm/uninstall.sh Outdated
Comment thread packages/rpm/remove_blank_lines.sh Outdated
Comment thread CPackConfig.txt Outdated
@AndrewQuijano
Copy link
Copy Markdown
Contributor Author

AndrewQuijano commented Jan 5, 2025

@Rot127 Just updated the CPack file per your suggestions (Note both Debian and RPM package content looks identical now), three questions remain:

  1. Is there a way to test the package after the installation to confirm it works?
  2. Have you had a minute to check if the RPM package works as intended?
  3. Once this is tested, should I delete all the docker stuff from the deb folder too? Should I also replicate this on v5 branch as I do still really hope to get a v5.0.4 package ready for faster PANDA installation relatively soon

https://github.com/AndrewQuijano/capstone/releases/tag/6.0.2-Alpha3

@AndrewQuijano AndrewQuijano force-pushed the cpack branch 6 times, most recently from d2bb8b5 to c77d6ff Compare January 6, 2025 00:27
@Rot127
Copy link
Copy Markdown
Collaborator

Rot127 commented Jan 6, 2025

Is there a way to test the package after the installation to confirm it works?

I just ran a cstool command the last time to check. Because cstool uses the dynamic library.
For headers we can just check, if we can include them as system header in a C source file.

Have you had a minute to check if the RPM package works as intended?

Not yet. I waited for you to add the workflow job, so I don't have to set up to much. Will do review this one again tomorrow.

Once this is tested, should I delete all the docker stuff from the deb folder too?

Yeah, sure. Less duplicates are always better.

Should I also replicate this on v5 branch as I do still really hope to get a v5.0.4 package ready for faster PANDA installation relatively soon

This would be awesome!

@kabeor Do you know if we could get the release before lunar new year?
If you have enough time, @AndrewQuijano can open the PR now and we can prioritize it. So it is merged quickly.

@AndrewQuijano
Copy link
Copy Markdown
Contributor Author

@Rot127 Just updated the PR, and just curious would you look into how to update labeler to v5? Also, figure I should ask, you don't mind I use your ISSUE_TEMPLATE folder and labeler stuff for any other open-source work right?

Copy link
Copy Markdown
Collaborator

@Rot127 Rot127 left a comment

Choose a reason for hiding this comment

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

Looks good!

But the build fails for me: https://github.com/Rot127/capstone/actions/runs/12734529842/job/35492198289

...
 Enabling CAPSTONE_WASM_SUPPORT
Enabling CAPSTONE_BPF_SUPPORT
Enabling CAPSTONE_RISCV_SUPPORT
Enabling CAPSTONE_SH_SUPPORT
Enabling CAPSTONE_TRICORE_SUPPORT
Enabling CAPSTONE_ALPHA_SUPPORT
Enabling CAPSTONE_HPPA_SUPPORT
Enabling CAPSTONE_LOONGARCH_SUPPORT
Enabling CAPSTONE_XTENSA_SUPPORT
CMake Error at /usr/local/share/cmake-3.31/Modules/WriteBasicConfigVersionFile.cmake:43 (message):
  No VERSION specified for WRITE_BASIC_CONFIG_VERSION_FILE()
Call Stack (most recent call first):
  /usr/local/share/cmake-3.31/Modules/CMakePackageConfigHelpers.cmake:402 (write_basic_config_version_file)
  CMakeLists.txt:897 (write_basic_package_version_file)


-- Configuring incomplete, errors occurred!

Comment thread .github/workflows/build_release.yml
Comment thread CPackConfig.cmake
@Rot127
Copy link
Copy Markdown
Collaborator

Rot127 commented Jan 12, 2025

Just updated the PR, and just curious would you look into how to update labeler to v5?

It isn't a priority currently for me. Too much other stuff to do unfortunately. If you want to work on it feel free to do so! If you are faster then @kabeor reviewing, we can replace my downgrading PR with yours.

Also, figure I should ask, you don't mind I use your ISSUE_TEMPLATE folder and labeler stuff for any other open-source work right?

Not at all. It is open-source in the end :D

@AndrewQuijano AndrewQuijano force-pushed the cpack branch 2 times, most recently from 39bcf36 to cc1aaa1 Compare January 13, 2025 00:02
@Rot127
Copy link
Copy Markdown
Collaborator

Rot127 commented Jan 13, 2025

Debian works fine.
But the rpm package fails to install:

nothing proivdes libc6 >= 2.2.5

The package name for libc is apparently glibc (tested on Fedora). Also see https://packages.fedoraproject.org/pkgs/capstone/capstone/fedora-rawhide.html.

@AndrewQuijano
Copy link
Copy Markdown
Contributor Author

@Rot127 just updated CPack, hopefully this should fix the issue

Copy link
Copy Markdown
Collaborator

@Rot127 Rot127 left a comment

Choose a reason for hiding this comment

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

Very nice! Thanks a lot!

@AndrewQuijano
Copy link
Copy Markdown
Contributor Author

@kabeor Please merge and create a 5.0.4 on the v5 Branch

@kabeor
Copy link
Copy Markdown
Member

kabeor commented Jan 16, 2025

@kabeor Please merge and create a 5.0.4 on the v5 Branch

Done.

@AndrewQuijano
Copy link
Copy Markdown
Contributor Author

@kabeor Thank you for the new release! I'm wondering, would it be possible to re-release 5.0.4? It seems the code to dynamically update the version got deleted here.

image

The released packages are missing the version in the file name (I aimed to follow standard RPM/Debian package practices), since the code to dynamically pick up the version from the tag got deleted.

https://github.com/capstone-engine/capstone/releases/tag/5.0.4

Also, could you please merge #2590? I should note, this PR also has the same technique to dynamically update the version of Capstone based on input from tag name. This should save time from having to manually bump the version number for every release, which seemed to be ok with @Rot127

I see based on the v5 release, I think a better solution is to use a version.h.in file, with some modifications from CMake, we can dynamically get this version data, automating this work on every release. Should this just be another PR?

#ifndef VERSION_H
#define VERSION_H

#define PROJECT_VERSION_MAJOR @PROJECT_VERSION_MAJOR@
#define PROJECT_VERSION_MINOR @PROJECT_VERSION_MINOR@
#define PROJECT_VERSION_PATCH @PROJECT_VERSION_PATCH@

#endif // VERSION_H

@AndrewQuijano
Copy link
Copy Markdown
Contributor Author

AndrewQuijano commented Jan 16, 2025

Two things

1- I did a bit more digging around for pkgconfig.mk, it is used by Makefile and Python, I propose having CMake be able to dynamically overwrite pkgconfig.mk with the version data if it is provided. I'm not sure where I'd write the updated version of pkgconfig for use? I'd also be curious what the values in bindings/python/capstone/__init__.py are used for?

image

2- I can add a version.h file to be created and updated dynamically in include/capstone folder. Let me know what to do next @Rot127 @kabeor and if it should be included in this PR (and perhaps in v5 as well too?)

@Rot127
Copy link
Copy Markdown
Collaborator

Rot127 commented Jan 16, 2025

It seems the code to dynamically update the version got deleted here.

Just pinged him. Was an accident while resolving conflicts. Thanks for pointing it out!
@kabeor will do a 5.0.5.

I see based on the v5 release, I think a better solution is to use a version.h.in file, with some modifications from CMake, we can dynamically get this version data, automating this work on every release. Should this just be another PR?

Good idea. At least on the next branch we should have it.
Would you mind opening an issue about it.

Regarding the whole pkgconfig changes:
Let's do them in the next release. Not now, in the v5.0.5 one. Otherwise you have to wait even longer for it :D And we might break it while rushing.
But we can discuss details in the issue. TO have them contained at one place.

@Rot127
Copy link
Copy Markdown
Collaborator

Rot127 commented Jan 16, 2025

@AndrewQuijano Please review #2606

@Rot127
Copy link
Copy Markdown
Collaborator

Rot127 commented Jan 16, 2025

Ah, also. Please rebase this one on the latest next. The labeler is fixed again.

@AndrewQuijano
Copy link
Copy Markdown
Contributor Author

AndrewQuijano commented Jan 19, 2025

@Rot127 Rebased complete!

@kabeor Thanks for v5.0.5 release! Will be updating PANDA to be using the new Debian package shortly panda-re/panda#1562

Copy link
Copy Markdown
Member

@kabeor kabeor left a comment

Choose a reason for hiding this comment

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

Thank you, merged.

@kabeor kabeor merged commit 5f290ca into capstone-engine:next Jan 20, 2025
imphil added a commit to imphil/capstone that referenced this pull request Feb 19, 2025
capstone can be built as sub-project through cmake's fetch_content
mechanism. In this case, `CMAKE_SOURCE_DIR` refers to the parent project
(that has nothing to do with capstone), while `PROJECT_SOURCE_DIR` refers
to the root of the capstone source tree.

Recently introduced changes to enable CPack (capstone-engine#2590) are using the wrong
variable and are hence breaking builds that use capstone through
fetch_content. Use the correct variable to fix this issue.
kabeor pushed a commit that referenced this pull request Mar 3, 2025
* cmake: Use PROJECT_SOURCE_DIR instead of CMAKE_SOURCE_DIR

capstone can be built as sub-project through cmake's fetch_content
mechanism. In this case, `CMAKE_SOURCE_DIR` refers to the parent project
(that has nothing to do with capstone), while `PROJECT_SOURCE_DIR` refers
to the root of the capstone source tree.

Recently introduced changes to enable CPack (#2590) are using the wrong
variable and are hence breaking builds that use capstone through
fetch_content. Use the correct variable to fix this issue.

* cmake: Only include cpack in top-level builds

Do not include cpack in builds where capstone is used through
fetch_content.
kabeor pushed a commit that referenced this pull request Apr 2, 2025
* Fix wrong version requirement of tricore instructions: (#2620)

crc32.b
crc32b.w
crc32l.w
crcn
popcnt.w
shuffle

Remove invalid instruction:
BISR_rc_v161

Learn up misconfigure of nor and not

* Switch to ubuntu-24.04-arm runner image (#2625)

* Build Tarball before DEB/RPM package. (#2627)

Because it was run after the RPM/DEB package build it contained the 'build' directory
with all its files. Which made it way too big.

* Add aliases mapping for MIPS & test for id, alias_id (#2635)

* Add checks for MIPS details on cstest_py (#2640)

* Give the user some guidance where to add missing enumeration values. (#2639)

* - Added missing files for sdist archive (#2624)

* cmake: Fix building capstone as sub-project (#2629)

* cmake: Use PROJECT_SOURCE_DIR instead of CMAKE_SOURCE_DIR

capstone can be built as sub-project through cmake's fetch_content
mechanism. In this case, `CMAKE_SOURCE_DIR` refers to the parent project
(that has nothing to do with capstone), while `PROJECT_SOURCE_DIR` refers
to the root of the capstone source tree.

Recently introduced changes to enable CPack (#2590) are using the wrong
variable and are hence breaking builds that use capstone through
fetch_content. Use the correct variable to fix this issue.

* cmake: Only include cpack in top-level builds

Do not include cpack in builds where capstone is used through
fetch_content.

* Update operand type enums of all arch modules to the one in `capstone.h` (#2633)

* Set all operand types to the main CS_OP_ types from capstone.h.

* Add test cases from issue.

* Enhance shift value and types of shift instructions. (#2638)

* Enhance shift value and types of shift instructions.

Shifts via registers now save the register id in cs_arch64_op.shift.value
and set the shift type accordingly.

* Sort table

* Fix build for compilers requiring explicit static for inline functions.. (#2645)

* Tms32c64x Little Endian (#2648)

* Add little endian support for TMS320c64x.
This requires now to initialize TMS320c64x with the
CS_MODE_BIG_ENDIAN flag.

* Fix typo

* Add Call group to svc, smc and hvc. (#2651)

* Decode BH field in print_insn_detail_ppc (#2662)

---------

Co-authored-by: Changqing  Jing <changqing.jing@bmw.com>
Co-authored-by: @Antelox <anteloxrce@gmail.com>
Co-authored-by: Giovanni <561184+wargio@users.noreply.github.com>
Co-authored-by: Philipp Wagner <mail@philipp-wagner.com>
Co-authored-by: Tim Haines <thaines.astro@gmail.com>
kabeor pushed a commit that referenced this pull request Apr 9, 2025
* cmake: Use PROJECT_SOURCE_DIR instead of CMAKE_SOURCE_DIR

capstone can be built as sub-project through cmake's fetch_content
mechanism. In this case, `CMAKE_SOURCE_DIR` refers to the parent project
(that has nothing to do with capstone), while `PROJECT_SOURCE_DIR` refers
to the root of the capstone source tree.

Recently introduced changes to enable CPack (#2590) are using the wrong
variable and are hence breaking builds that use capstone through
fetch_content. Use the correct variable to fix this issue.

* cmake: Only include cpack in top-level builds

Do not include cpack in builds where capstone is used through
fetch_content.
Rot127 pushed a commit that referenced this pull request Apr 11, 2025
* cmake: Use PROJECT_SOURCE_DIR instead of CMAKE_SOURCE_DIR

capstone can be built as sub-project through cmake's fetch_content
mechanism. In this case, `CMAKE_SOURCE_DIR` refers to the parent project
(that has nothing to do with capstone), while `PROJECT_SOURCE_DIR` refers
to the root of the capstone source tree.

Recently introduced changes to enable CPack (#2590) are using the wrong
variable and are hence breaking builds that use capstone through
fetch_content. Use the correct variable to fix this issue.

* cmake: Only include cpack in top-level builds

Do not include cpack in builds where capstone is used through
fetch_content.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Documentation Github-files Github related files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants