gnu-sort 1.0.5

High-performance Rust implementation of GNU sort with zero-copy operations, SIMD optimization, and parallel processing
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
name: CI

# Builds binaries for 7 major platforms:
# Linux: x86_64, aarch64, i686
# Windows: x86_64, aarch64
# macOS: x86_64, aarch64

on:
  push:
    branches: [ main, master ]
    tags:
      - 'v/*'
  pull_request:
    branches: [ main, master ]
  schedule:
    # Run tests weekly to catch regressions
    - cron: '0 0 * * 0'

env:
  CARGO_TERM_COLOR: always
  RUSTFLAGS: "-Dwarnings"

jobs:
  test:
    name: Test Suite
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [ubuntu-latest, windows-latest, macos-latest]
        rust: [stable, beta, 1.70.0]  # MSRV
        exclude:
          # Don't test beta/MSRV on all platforms to save CI time
          - os: windows-latest
            rust: beta
          - os: windows-latest  
            rust: 1.70.0
          - os: macos-latest
            rust: beta
          - os: macos-latest
            rust: 1.70.0

    steps:
    - name: Checkout repository
      uses: actions/checkout@v4

    - name: Install Rust toolchain
      uses: dtolnay/rust-toolchain@master
      with:
        toolchain: ${{ matrix.rust }}
        components: rustfmt, clippy

    - name: Setup Rust cache
      uses: Swatinem/rust-cache@v2
      with:
        key: ${{ matrix.os }}-${{ matrix.rust }}

    - name: Install system dependencies (Ubuntu)
      if: matrix.os == 'ubuntu-latest'
      run: |
        sudo apt-get update
        sudo apt-get install -y bc time

    - name: Install system dependencies (macOS)
      if: matrix.os == 'macos-latest'
      run: |
        # macOS already has bc and time
        echo "No additional dependencies needed"

    - name: Check formatting
      run: cargo fmt --all -- --check
      if: matrix.rust == 'stable'

    - name: Run Clippy
      run: cargo clippy --all-targets --all-features -- -D warnings
      if: matrix.rust == 'stable'

    - name: Build
      run: cargo build --verbose

    - name: Run tests
      run: cargo test --verbose

    - name: Build release
      run: cargo build --release --verbose

    - name: Test release binary exists
      shell: bash
      run: |
        if [[ "${{ matrix.os }}" == "windows-latest" ]]; then
          test -f target/release/sort.exe
        else
          test -f target/release/sort
        fi

    - name: Basic functionality test
      shell: bash
      run: |
        # Create test data
        printf "3\n1\n2\n" > test.txt
        
        # Test basic sorting
        if [[ "${{ matrix.os }}" == "windows-latest" ]]; then
          ./target/release/sort.exe test.txt > output.txt
        else
          ./target/release/sort test.txt > output.txt
        fi
        
        # Check output - simplified cross-platform test
        # Extract just the numbers and check they're in order
        sorted_output=$(cat output.txt | tr -d '\r' | tr '\n' ' ')
        expected="1 2 3 "
        
        if [[ "$sorted_output" != "$expected" ]]; then
          echo "Basic sort test failed"
          echo "Expected: $expected"
          echo "Got: $sorted_output"
          echo "Raw output:"
          cat output.txt | od -c
          exit 1
        fi
        
        echo "✅ Basic functionality test passed"

  benchmark:
    name: Performance Benchmarks
    runs-on: ubuntu-latest
    needs: test
    if: github.event_name == 'pull_request'

    steps:
    - name: Checkout repository
      uses: actions/checkout@v4

    - name: Install Rust toolchain
      uses: dtolnay/rust-toolchain@stable

    - name: Setup Rust cache
      uses: Swatinem/rust-cache@v2

    - name: Install system dependencies
      run: |
        sudo apt-get update
        sudo apt-get install -y bc time coreutils

    - name: Build release
      run: cargo build --release

    - name: Run benchmarks
      run: |
        chmod +x benchmark.sh
        ./benchmark.sh 2>&1 | tee benchmark_results.txt

    - name: Check performance regression
      run: |
        # Extract performance data and check for major regressions
        # This is a placeholder - would implement actual regression detection
        echo "Benchmark completed successfully"
        grep -E "(✓|✗)" benchmark_results.txt || true

    - name: Upload benchmark results
      uses: actions/upload-artifact@v4
      with:
        name: benchmark-results
        path: benchmark_results.txt

  security:
    name: Security Audit
    runs-on: ubuntu-latest
    steps:
    - name: Checkout repository
      uses: actions/checkout@v4

    - name: Install Rust toolchain
      uses: dtolnay/rust-toolchain@stable

    - name: Install cargo-audit
      run: cargo install cargo-audit

    - name: Run security audit
      run: cargo audit

  coverage:
    name: Code Coverage
    runs-on: ubuntu-latest
    steps:
    - name: Checkout repository
      uses: actions/checkout@v4

    - name: Install Rust toolchain
      uses: dtolnay/rust-toolchain@stable
      with:
        components: llvm-tools-preview

    - name: Install cargo-llvm-cov
      uses: taiki-e/install-action@cargo-llvm-cov

    - name: Setup Rust cache
      uses: Swatinem/rust-cache@v2

    - name: Generate code coverage
      run: cargo llvm-cov --all-features --workspace --lcov --output-path lcov.info

    - name: Upload coverage to Codecov
      uses: codecov/codecov-action@v4
      with:
        file: lcov.info
        fail_ci_if_error: false
        verbose: true
      continue-on-error: true

  docs:
    name: Documentation
    runs-on: ubuntu-latest
    steps:
    - name: Checkout repository
      uses: actions/checkout@v4

    - name: Install Rust toolchain
      uses: dtolnay/rust-toolchain@stable

    - name: Setup Rust cache
      uses: Swatinem/rust-cache@v2

    - name: Build documentation
      run: cargo doc --no-deps --all-features

    # Documentation deployment disabled until gh-pages branch is configured
    # - name: Deploy documentation (main branch only)
    #   if: github.ref == 'refs/heads/main' && github.event_name == 'push'
    #   uses: peaceiris/actions-gh-pages@v3
    #   with:
    #     github_token: ${{ secrets.GITHUB_TOKEN }}
    #     publish_dir: ./target/doc

  release:
    name: Build and Release
    runs-on: ${{ matrix.os }}
    needs: test
    if: startsWith(github.ref, 'refs/tags/v/')
    permissions:
      contents: write
    strategy:
      fail-fast: false
      matrix:
        include:
          # Linux
          - os: ubuntu-latest
            target: x86_64-unknown-linux-gnu
            name: linux-x86_64
          - os: ubuntu-latest
            target: aarch64-unknown-linux-gnu
            name: linux-aarch64
            use_cross: true
          - os: ubuntu-latest
            target: i686-unknown-linux-gnu
            name: linux-i686
            use_cross: true
          # Windows
          - os: windows-latest
            target: x86_64-pc-windows-msvc
            name: windows-x86_64
            ext: .exe
          - os: windows-latest
            target: aarch64-pc-windows-msvc
            name: windows-aarch64
            ext: .exe
          # macOS
          - os: macos-latest
            target: x86_64-apple-darwin
            name: macos-x86_64
          - os: macos-latest
            target: aarch64-apple-darwin
            name: macos-aarch64

    steps:
    - name: Checkout repository
      uses: actions/checkout@v4

    - name: Install Rust toolchain
      uses: dtolnay/rust-toolchain@stable
      with:
        targets: ${{ matrix.target }}

    - name: Setup Rust cache
      uses: Swatinem/rust-cache@v2
      with:
        key: ${{ matrix.target }}

    - name: Install cross compilation tool
      if: matrix.use_cross == true
      uses: taiki-e/install-action@v2
      with:
        tool: cross

    - name: Build release binary (cross)
      if: matrix.use_cross == true
      run: cross build --release --target ${{ matrix.target }}

    - name: Build release binary (cargo)
      if: matrix.use_cross != true
      run: cargo build --release --target ${{ matrix.target }}

    - name: Create release archive
      shell: bash
      run: |
        mkdir -p release
        if [[ -n "${{ matrix.ext }}" ]]; then
          binary_name="sort${{ matrix.ext }}"
        else
          binary_name="sort"
        fi
        archive_name="rust-sort-${{ matrix.name }}.tar.gz"
        
        echo "🔍 Debug info:"
        echo "  Platform: ${{ matrix.name }}"
        echo "  Target: ${{ matrix.target }}"
        echo "  Binary: $binary_name"
        echo "  Archive: $archive_name"
        echo "  Working dir: $(pwd)"
        
        echo "📂 Target directory contents:"
        ls -la target/${{ matrix.target }}/release/ || echo "❌ Target dir not found"
        
        cd target/${{ matrix.target }}/release
        if [[ -f "$binary_name" ]]; then
          tar -czf "../../../release/$archive_name" "$binary_name"
          echo "✅ Created: release/$archive_name"
          ls -la "../../../release/$archive_name"
        else
          echo "❌ Binary not found: $binary_name"
          echo "Available files:"
          ls -la .
          exit 1
        fi
        cd -
        
        echo "📦 Final release directory:"
        ls -la release/

    - name: Debug files before release
      shell: bash
      run: |
        echo "🔍 Files to upload:"
        ls -la release/ || echo "❌ No release directory"
        echo "📊 File count: $(ls release/*.tar.gz 2>/dev/null | wc -l)"
        if ls release/*.tar.gz >/dev/null 2>&1; then
          echo "📋 Files:"
          for file in release/*.tar.gz; do
            echo "  - $(basename $file) ($(du -h $file | cut -f1))"
          done
        fi

    - name: Release
      uses: softprops/action-gh-release@v2
      with:
        tag_name: ${{ github.ref_name }}
        name: "🦀 Rust Sort ${{ github.ref_name }}"
        body: |
          ## What's Changed in ${{ github.ref_name }}
          
          🚀 **High-performance Rust implementation of GNU sort**
          
          ### Features
          * Zero-copy operations for maximum performance
          * SIMD-optimized comparisons  
          * Multi-threaded parallel sorting
          * Field-based sorting (-k option)
          * Locale-aware string comparison
          * Cross-platform compatibility
          
          ### Supported Platforms
          * Linux: x86_64, aarch64, i686
          * Windows: x86_64, aarch64
          * macOS: x86_64, aarch64
          
          **Platform: ${{ matrix.name }} (${{ matrix.target }})**
        files: |
          ./release/*.tar.gz
        draft: false
        prerelease: false
        token: ${{ secrets.GITHUB_TOKEN }}

  build-matrix:
    name: Build Release Binaries  
    runs-on: ${{ matrix.os }}
    needs: test
    # Builds binaries on every commit to main/master (for testing)
    if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master'
    strategy:
      fail-fast: false
      matrix:
        include:
          # Linux
          - os: ubuntu-latest
            target: x86_64-unknown-linux-gnu
          - os: ubuntu-latest
            target: aarch64-unknown-linux-gnu
            use_cross: true
          # Windows  
          - os: windows-latest  
            target: x86_64-pc-windows-msvc
          - os: windows-latest
            target: aarch64-pc-windows-msvc
          # macOS
          - os: macos-latest
            target: x86_64-apple-darwin
          - os: macos-latest
            target: aarch64-apple-darwin

    steps:
    - name: Checkout repository
      uses: actions/checkout@v4

    - name: Install Rust toolchain
      uses: dtolnay/rust-toolchain@stable
      with:
        targets: ${{ matrix.target }}

    - name: Setup Rust cache
      uses: Swatinem/rust-cache@v2
      with:
        key: ${{ matrix.target }}

    - name: Install cross compilation tool
      if: matrix.use_cross == true
      uses: taiki-e/install-action@v2
      with:
        tool: cross

    - name: Build release binary (cross)
      if: matrix.use_cross == true
      run: cross build --release --target ${{ matrix.target }}

    - name: Build release binary (cargo)
      if: matrix.use_cross != true
      run: cargo build --release --target ${{ matrix.target }}

  publish:
    name: Publish to crates.io
    runs-on: ubuntu-latest
    needs: [test]
    if: startsWith(github.ref, 'refs/tags/v/')
    permissions:
      contents: read

    steps:
    - name: Checkout repository
      uses: actions/checkout@v4

    - name: Install Rust toolchain
      uses: dtolnay/rust-toolchain@stable

    - name: Setup Rust cache
      uses: Swatinem/rust-cache@v2

    - name: Publish to crates.io
      run: cargo publish --allow-dirty --token ${{ secrets.CARGO_REGISTRY_TOKEN }}
      env:
        CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}