Skip to content

Commit 9024d28

Browse files
committed
better CPU frequency detection (Linux), automated build/release Action
Signed-off-by: kernaltrap <[email protected]>
1 parent 06b333e commit 9024d28

File tree

5 files changed

+109
-5
lines changed

5 files changed

+109
-5
lines changed

.github/workflows/release.yml

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: Build and Release
2+
3+
on:
4+
push:
5+
tags:
6+
- '*'
7+
branches:
8+
- main
9+
10+
permissions:
11+
contents: write
12+
13+
jobs:
14+
build:
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- name: Checkout code
19+
uses: actions/checkout@v3
20+
21+
- name: Set up Meson and Ninja
22+
run: |
23+
sudo apt-get update
24+
sudo apt-get install -y meson ninja-build
25+
26+
- name: Extract version from source code
27+
id: get_version
28+
run: |
29+
VERSION=$(grep '#define VERSION ' src/tinyfetch.h | awk '{print $3}' | tr -d '"')
30+
echo "VERSION=$VERSION" >> $GITHUB_ENV
31+
32+
- name: Configure Git
33+
run: |
34+
git config --global user.name "github-actions"
35+
git config --global user.email "[email protected]"
36+
37+
- name: Create a new tag
38+
run: |
39+
git tag "v${{ env.VERSION }}"
40+
git push origin "v${{ env.VERSION }}"
41+
42+
- name: Configure Meson build
43+
run: |
44+
meson setup builddir
45+
46+
- name: Build with Meson
47+
run: |
48+
meson compile -C builddir
49+
50+
- name: Create release asset
51+
run: |
52+
tar -czvf "builddir/tinyfetch-${{ env.VERSION }}.tar.gz" builddir/tinyfetch
53+
54+
- name: Create a new release
55+
id: create_release
56+
uses: actions/create-release@v1
57+
with:
58+
tag_name: "v${{ env.VERSION }}"
59+
release_name: "Release ${{ env.VERSION }}"
60+
draft: false
61+
prerelease: false
62+
env:
63+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
64+
65+
- name: Upload release asset
66+
uses: actions/upload-release-asset@v1
67+
with:
68+
upload_url: ${{ steps.create_release.outputs.upload_url }}
69+
asset_path: "builddir/tinyfetch-${{ env.VERSION }}.tar.gz"
70+
asset_name: "tinyfetch-${{ env.VERSION }}.tar.gz"
71+
asset_content_type: application/gzip
72+
env:
73+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

src/tinyfetch.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -749,9 +749,10 @@ void tinycpu(void) {
749749
#ifdef __linux__
750750
char *cpu = file_parser_char("/proc/cpuinfo", "model name : %[^\n]");
751751
char *cpu_fallback = file_parser_char("/proc/cpuinfo", "cpu : %[^\n]");
752-
double cpu_freq =
753-
file_parser_double("/proc/cpuinfo", "cpu MHz : %lf");
754-
double formatted_freq = cpu_freq / 1000;
752+
double cpu_freq = file_parser_double(
753+
"/sys/devices/system/cpu/cpufreq/policy0/scaling_available_frequencies",
754+
"%lf");
755+
double formatted_freq = cpu_freq / 1000000;
755756
int cpu_count = get_cpu_count();
756757
if (cpu != NULL) {
757758
printf("%s (%d) @ %.2fGHz\n", cpu, cpu_count, formatted_freq);

src/tinyfetch.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
/*
77
tinyfetch.h
88
*/
9-
10-
#define VERSION "6.0a"
9+
#define VERSION "6.1"
1110
#define decoration "[·]"
1211
#define CMDLINE_PATH "/proc/%d/cmdline"
1312
#define help_banner \

tinyfetch-6.0a-meson-build-pci.patch

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--- meson.build 2024-06-26 20:58:26.753005180 -0500
2+
+++ _meson.build 2024-07-19 20:14:50.876736109 -0500
3+
@@ -8,17 +8,8 @@
4+
5+
uname_output = run_command('uname', check: true).stdout().strip()
6+
if uname_output == 'Linux'
7+
- config_h = configuration_data()
8+
- pci_dep = dependency('libpci', required: false)
9+
- if pci_dep.found()
10+
- link_args += ['-lpci']
11+
- config_h.set('PCI_DETECTION', 1)
12+
- else
13+
- config_h.set('PCI_DETECTION', 0)
14+
- endif
15+
- configure_file(output: 'config.h', configuration: config_h)
16+
c_args += ['-Os', '-s', '-fomit-frame-pointer', '-fno-unwind-tables', '-fno-asynchronous-unwind-tables', '-g0']
17+
- executable('tinyfetch', 'src/tinyfetch.c', install : true, c_args: c_args, link_args: link_args)
18+
+ executable('tinyfetch', 'src/tinyfetch.c', install : true, c_args: c_args)
19+
elif uname_output == 'FreeBSD'
20+
config_h = configuration_data()
21+
pci_dep = dependency('libpci', required: false)

tinyfetch-6.0a-remove-config.patch

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
--- tinyfetch.c 2024-07-16 13:58:19.256177802 -0500
2+
+++ _tinyfetch.c 2024-07-19 20:15:50.162202099 -0500
3+
@@ -24,7 +24,6 @@
4+
#include <sys/sysctl.h>
5+
#include <sys/types.h>
6+
#endif
7+
-#include "config.h"
8+
#include "tinyascii.h"
9+
#include "tinyfetch.h"
10+

0 commit comments

Comments
 (0)