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

flac: build with cmake, fixes cross compilation #193886

Merged
merged 2 commits into from
Oct 4, 2022
Merged

Conversation

NickCao
Copy link
Member

@NickCao NickCao commented Oct 1, 2022

Description of changes
Things done
  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandbox = true set in nix.conf? (See Nix manual)
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 22.11 Release Notes (or backporting 22.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
    • (Release notes changes) Ran nixos/doc/manual/md-to-db.sh to update generated release notes
  • Fits CONTRIBUTING.md.

@NickCao
Copy link
Member Author

NickCao commented Oct 1, 2022

Built flac and gst_all_1.gst-plugins-good on x86_64-linux and riscv64-linux (cross), not feasible to run nixpkgs-review though.

@NickCao NickCao marked this pull request as ready for review October 1, 2022 11:15
Copy link
Contributor

@ck3d ck3d left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@ruuda ruuda left a comment

Choose a reason for hiding this comment

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

The new binary performs noticeably worse. I suspect it ends up passing different optimization flags to the compiler in the end? Could you look into this?

Benchmark 1: result-bin-before/bin/flac -t album/*.flac
  Time (mean ± σ):      5.037 s ±  0.113 s    [User: 4.834 s, System: 0.120 s]
  Range (min … max):    4.955 s …  5.282 s    10 runs
 
Benchmark 2: result-bin-cmake/bin/flac -t album/*.flac
  Time (mean ± σ):      5.307 s ±  0.040 s    [User: 5.072 s, System: 0.136 s]
  Range (min … max):    5.257 s …  5.381 s    10 runs
 
Summary
  'result-bin-before/bin/flac -t album/*.flac' ran
    1.05 ± 0.03 times faster than 'result-bin-cmake/bin/flac -t album/*.flac'

@ck3d
Copy link
Contributor

ck3d commented Oct 2, 2022

Good catch!

According to the project documentation, autotools and cmake should be equivalent:
https://github.com/xiph/flac/blob/master/README.md?plain=1#L87

The autotools used following configuration:

  Configuration summary :

    FLAC version : ............................ 1.4.1

    Host CPU : ................................ x86_64
    Host Vendor : ............................. pc
    Host OS : ................................. linux-gnu


    Compiler is GCC : ......................... yes
    GCC version : ............................. 11.3.0
    Compiler is Clang : ....................... no
    SSE optimizations : ....................... yes
    Neon optimizations : ...................... no
    Asm optimizations : ....................... yes
    Ogg/FLAC support : ........................ yes
    Stack protector  : ........................ yes
    Fuzzing support (Clang only) : ............ no

When building with cmake, no configuration summary is available.
It could be that some optimizations are not activated.

I think this is an upstream issue.

@NickCao
Copy link
Member Author

NickCao commented Oct 3, 2022

https://github.com/xiph/flac/blob/2440e19a733f045e50cd7f3dbd706b9ed98fc5ef/configure.ac#L508 sets -O3, while it's missing from the cmake build system. AVX is on by default in cmake, ruling out that possibility.

@ofborg ofborg bot requested a review from ruuda October 3, 2022 02:58
@ruuda
Copy link
Contributor

ruuda commented Oct 4, 2022

Hmm, even with b8a03ce, there is a significant difference ... the binary is about 3% larger, and when I measure a perf stat of flac --test, it executes about 8% more instructions. (Using instructions now instead of wall time because it is more stable, in wall time, the old version is 1.05 ± 0.02 times faster on my machine.)

Is there an easy way to trace the compiler invocations, so we can see which flags get passed?

@ruuda
Copy link
Contributor

ruuda commented Oct 4, 2022

I am a fool, I was comparing the current PR to master, which still has flac 1.3.4..., the regression is an upstream one, unrelated to this PR. I now no longer find a difference between the two:

Benchmark 1: result-bin-cmake/bin/flac -t album/*.flac
  Time (mean ± σ):      4.854 s ±  0.140 s    [User: 4.753 s, System: 0.096 s]
  Range (min … max):    4.702 s …  5.111 s    10 runs
 
Benchmark 2: result-bin-before/bin/flac -t album/*.flac
  Time (mean ± σ):      4.912 s ±  0.078 s    [User: 4.815 s, System: 0.091 s]
  Range (min … max):    4.783 s …  4.991 s    10 runs
 
Summary
  'result-bin-cmake/bin/flac -t album/*.flac' ran
    1.01 ± 0.03 times faster than 'result-bin-before/bin/flac -t album/*.flac'

@ck3d ck3d merged commit 72c02dc into NixOS:staging Oct 4, 2022
@ck3d
Copy link
Contributor

ck3d commented Oct 4, 2022

No problem :)

@NickCao NickCao deleted the flac branch October 5, 2022 00:41
@Mindavi
Copy link
Contributor

Mindavi commented Oct 19, 2022

I was just preparing a PR and got a merge conflict, thanks for already fixing this! My solution was worse (using configure script patches that already landed upstream).

@Mindavi Mindavi added the 6.topic: cross-compilation Building packages on a different sort platform than than they will be run on label Oct 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants